glassfish
  1. glassfish
  2. GLASSFISH-16802

@DataSourceDefinition java.sql.SQLException: No PasswordCredential found for connections with empty password

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1.1_b08
    • Component/s: jca
    • Labels:
      None
    • Environment:

      Confirmed both in OSX Snow Leopard and Windows 7 64 Bits, in two separate machines (probably the bug is OS and Hardware agnostic).

      Description

      When creating a datasource like this:

      @DataSourceDefinition(name = "java:app/jdbc/myDatasource", 
       className = "org.h2.jdbcx.JdbcDataSource", 
       url = "jdbc:h2:/path/to/db;AUTO_SERVER=TRUE;MVCC=TRUE", 
       user = "sa",
       password=""
      ) 
      

      or

      web.xml
      <data-source>
          <description>DataSource for H2</description>
          <name>java:app/jdbc/cdiDS</name>
          <class-name>org.h2.jdbcx.JdbcDataSource</class-name>
          <url>jdbc:h2:/path/to/db;AUTO_SERVER=TRUE;MVCC=TRUE</url>
          <user>sa</user>
          <password></password>
      </data-source>
      

      Throws a nasty Exception:

       
      Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: No PasswordCredential found
      Error Code: 0
      	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:309)
      	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:138)
      	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
      	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
      	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:592)
      	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
      	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:394)
      	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
      	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
      	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
      	at org.glassfish.persistence.jpa.PersistenceUnitLoader.doJava2DB(PersistenceUnitLoader.java:373)
      	at org.glassfish.persistence.jpa.JPADeployer$2.visitPUD(JPADeployer.java:434)
      	at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:486)
      	at org.glassfish.persistence.jpa.JPADeployer.iterateInitializedPUsAtApplicationPrepare(JPADeployer.java:464)
      	at org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:388)
      	at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
      	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:452)
      	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
      	at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
      	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
      	at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:118)
      	at com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:97)
      	at com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:88)
      	at org.glassfish.maven.PluginUtil.doDeploy(PluginUtil.java:106)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.glassfish.maven.AbstractDeployMojo.doDeploy(AbstractDeployMojo.java:171)
      	at org.glassfish.maven.RunMojo.execute(RunMojo.java:62)
      	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
      	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
      	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
      	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
      	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
      Caused by: java.sql.SQLException: Error in allocating a connection. Cause: No PasswordCredential found
      	at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:117)
      	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
      	... 54 more
      Caused by: javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: No PasswordCredential found
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:310)
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
      	at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:110)
      	... 55 more
      Caused by: com.sun.appserv.connectors.internal.api.PoolingException: No PasswordCredential found
      	at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:103)
      	at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
      	at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1497)
      	at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:940)
      	at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230)
      	at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511)
      	at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
      	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:242)
      	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:167)
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:335)
      	at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:304)
      	... 59 more
      Caused by: com.sun.appserv.connectors.internal.api.PoolingException: No PasswordCredential found
      	at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:920)
      	at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1181)
      	at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
      	... 69 more
      Caused by: com.sun.appserv.connectors.internal.api.PoolingException: No PasswordCredential found
      	at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:168)
      	at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:903)
      	... 71 more
      Caused by: javax.resource.spi.SecurityException: No PasswordCredential found
      	at com.sun.gjc.util.SecurityUtils.getPasswordCredential(SecurityUtils.java:111)
      	at com.sun.gjc.spi.XAManagedConnectionFactory.createManagedConnection(XAManagedConnectionFactory.java:100)
      	at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:147)
      	... 72 more
      05/06/2011 00:57:59 org.glassfish.persistence.jpa.PersistenceUnitLoader doJava2DB
      

      The same thing happens if I don't specify a password.
      The funny thing is, this works as expected:

      glassfish-resources.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
      <resources>
        <jdbc-resource enabled="true" jndi-name="jdbc/myDatasource"pool-name="connectionPool">
          <description/>
        </jdbc-resource>
        <jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource"  name="connectionPool" res-type="javax.sql.DataSource">
          <property name="URL" value="jdbc:h2:jdbc:h2:/path/to/db;AUTO_SERVER=TRUE;MVCC=TRUE"/>
          <property name="User" value="sa"/>
          <property name="Password" value=""/>
        </jdbc-connection-pool>
      </resources>
      

      I haven't tested with other databases, but a quick search on Google lead me to believe that this bug is also database agnostic.
      Can you guys confirm it?

        Activity

        Hide
        Mitesh Meswani added a comment -

        Assigning to JCA for initial investigation

        Show
        Mitesh Meswani added a comment - Assigning to JCA for initial investigation
        Hide
        Jagadish added a comment -

        I am able to reproduce the issue.
        We need to evaluate further as "" is the default value of password attribute in annotation.
        Current implementation will not set the password for datasource if it is "".

        Show
        Jagadish added a comment - I am able to reproduce the issue. We need to evaluate further as "" is the default value of password attribute in annotation. Current implementation will not set the password for datasource if it is "".
        Hide
        Jagadish added a comment -

        Fix is to avoid ignoring "password" attribute when specified with the value of "".

        Show
        Jagadish added a comment - Fix is to avoid ignoring "password" attribute when specified with the value of "".
        Hide
        Jagadish added a comment -

        Fixed in trunk :

        svn log -v -r 47399
        ---------------
        trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/handlers/DataSourceDefinitionHandler.java

        Show
        Jagadish added a comment - Fixed in trunk : svn log -v -r 47399 --------------- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/handlers/DataSourceDefinitionHandler.java
        Hide
        scatari added a comment -

        Approved for 3.1.1.

        Show
        scatari added a comment - Approved for 3.1.1.
        Hide
        Jagadish added a comment -

        Fixed in 3.1.1
        svn log -v -r 47430
        branches/3.1.1/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/handlers/DataSourceDefinitionHandler.java

        Show
        Jagadish added a comment - Fixed in 3.1.1 svn log -v -r 47430 branches/3.1.1/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/handlers/DataSourceDefinitionHandler.java

          People

          • Assignee:
            Jagadish
            Reporter:
            a.accioly
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: