Tuesday, July 19, 2016

[google-cloud-sql-discuss] Re: Cannot connect to cloud SQL 2nd generation using hibernate+jpa on GAE

this is a exception i throw when the user from the database is null. the problem is the same username and password work under tomcat in compute engine. but when try to connect uder app engine
the user still null . Here is the code to connect  below

protected AuthenticationInfo doGetAuthenticationInfo(
            AuthenticationToken arg0) {
        UsernamePasswordToken up = (UsernamePasswordToken)arg0;
        String text = (String) up.getPrincipal();
        String username = text.substring(0, text.lastIndexOf(";"));
        String operateur = text.substring(text.lastIndexOf(";")+1, text.length());
        System.out.println("Username : "+username);
        System.out.println("Operateur : "+operateur);
        System.out.println("Username : "+username);
        if(operateur == null || operateur.trim().isEmpty()){
            operateur = "-1";
            //throw new UnknownAccountException("operateur is empty");
        }
        HashedCredentialsMatcher hash = new HashedCredentialsMatcher(Sha256Hash.ALGORITHM_NAME);
        hash.setStoredCredentialsHexEncoded(false);
        hash.setHashIterations(HASH_ITERATION);
        this.setCredentialsMatcher(hash);
        Utilisateur user = UtilisateurManager.findUtilisateurByLogin(entityManager, username, BigInteger.valueOf(Long.parseLong(operateur)));
        if(user == null){
            throw new UnknownAccountException("Incorrect Account");
        }
        String password = user.getPassword();
        String salt = user.getSalt();
        SimpleAuthenticationInfo  info = new SimpleAuthenticationInfo(username, password.toCharArray(),ByteSource.Util.bytes(salt.getBytes()), getName());
        //Authenticated with success
        System.out.println("With Succes....");
        user.setDerniereConnexion(new Date());
        UtilisateurService.setCurrentUser(user);
        return info;
    }


On Thursday, July 14, 2016 at 10:02:31 AM UTC-4, Carl Andin Michel Sanon wrote:
Hi everyone,
                   i read everything in https://cloud.google.com/sql/docs/app-engine-connect also in https://developers.google.com/eclipse/docs/cloudsql-jpatools but i cannot connect to cloud SQL 2nd generation using hibernate+jpa on GAE. Please i want some additional explanation and some example to do it right.

                  i already have a web application running in GAE and connect to cloud sql 1rst generation, look at my persistence file using for the first generation below .
                  Now, what change to do in this persistence file to make it work with cloud sql 2nd generation please?

Best Regards.

<properties>    
            <property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://myapps-web:apps/db" />               
            <property name="javax.persistence.validation.mode" value="NONE"/>          
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.connection.pool_size" value="0" />
            <property name="hibernate.connection.useUnicode" value="true"/>
            <property name="hibernate.connection.charSet" value="UTF-8"/>
            <property name="hibernate.bytecode.provider" value="javassist"/>
<!--       <property name="hibernate.bytecode.use_reflection_optimizer" value="true"/> -->
            <property name="hibernate.jdbc.use_streams_for_binary" value="true"/>
            <property name="hibernate.cache.use_query_cache" value="false"/>
            <property name="hibernate.cache.use_second_level_cache" value="false"/>
            <!-- PROD -->
            <property name="hibernate.show_sql" value="false"/>
<!--             <property name="hibernate.format_sql" value="false"/> -->
<!--             <property name="hibernate.generate_statistics" value="false"/> -->
<!--             <property name="hibernate.use_sql_comments" value="false"/> -->
</properties>

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/46c6692a-0996-4ccc-9488-1ab9c7a7d8d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment