glassfish
  1. glassfish
  2. GLASSFISH-19609

Connector runtime transforms a SecurityException into a ResourceAllocationException

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0_b72_EE7MS4
    • Fix Version/s: 4.0_b79
    • Component/s: jca
    • Labels:
      None

      Description

      In our resource adapter (JMSRA) we want our implementation of ManagedConnectionFactory#createManagedConnection to handle a user/password error by throwing a javax.resource.spi.SecurityException, which is explicitly listed in the API as one of the exceptions which may be thrown.

      http://docs.oracle.com/javaee/6/api/javax/resource/spi/ManagedConnectionFactory.html#createManagedConnection%28javax.security.auth.Subject,%20javax.resource.spi.ConnectionRequestInfo%29

      However we have discovered that when this exception is passed through the connector runtime to ConnectionManager#allocateConnection this is turned into a javax.resource.spi.ResourceAllocationException. This is despite the API for this method also explicitly listing javax.resource.spi.SecurityException as one of the exceptions that can be thrown.

      http://docs.oracle.com/javaee/6/api/javax/resource/spi/ConnectionManager.html#allocateConnection%28javax.resource.spi.ManagedConnectionFactory,%20javax.resource.spi.ConnectionRequestInfo%29

      This means that the RA code which calls ConnectionManager#allocateConnection cannot handle this correctly. This is a problem cause the RA needs to know that the exception is security-related and throw a JMS-specific security exception. This is required to support JMS 1.1

      The relevant stack of connector code is below:

       at com.sun.messaging.jms.ra.ManagedConnectionFactory.createManagedConnection(ManagedConnectionFactory.java:226)
       at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:160)
       at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:907)
       at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1189)
       at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
       at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
       at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512)
       at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944)
       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:245)
       at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:170)
       at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:337)
       at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:306)
       at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:207)
       at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:170)
       at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
      

      It looks as if the code that transforms the exception is as follows:

      \workspace\trunk\main\appserver\connectors\connectors-runtime\src\main\java\com\sun\enterprise\resource\allocator\ConnectorAllocator.java (line 157-183)

      public ResourceHandle createResource()
      
                  throws PoolingException {
              try {
                  ManagedConnection mc =
                          mcf.createManagedConnection(subject, reqInfo);
                  ResourceHandle resource =
                          createResourceHandle(mc, spec, this, info);
                  ConnectionEventListener l =
                          new ConnectionListenerImpl(resource);
                  mc.addConnectionEventListener(l);
                  return resource;
              } catch (ResourceException ex) {
                  Object[] params = new Object[]{spec.getPoolInfo(), ex.toString()};
                  _logger.log(Level.WARNING,"poolmgr.create_resource_error",params);
                  if(_logger.isLoggable(Level.FINE)) {
                      _logger.log(Level.FINE,"Resource Exception while creating resource",ex);
                  }
                  
                  if (ex.getLinkedException() != null) {
                      _logger.log(Level.WARNING,
                              "poolmgr.create_resource_linked_error", ex
                                      .getLinkedException().toString());
                  }
                  throw new PoolingException(ex);
              }
          }
      

      workspace\trunk\main\appserver\connectors\connectors-runtime\src\main\java\com\sun\enterprise\connectors\ConnectionManagerImpl.java (line 308-315)

       } catch (PoolingException ex) {
                  Object[] params = new Object[]{poolInfo, ex};
                  getLogger().log(Level.WARNING, "poolmgr.get_connection_failure", params);
                  String i18nMsg = getLocalStrings().getString("con_mgr.error_creating_connection", ex.getMessage());
                  ResourceAllocationException rae = new ResourceAllocationException(i18nMsg);
                  rae.initCause(ex);
                  throw rae;
              }
      

        Activity

        Hide
        Nigel Deakin added a comment -

        Please note that this fix is needed to resolve a CTS failure.

        Show
        Nigel Deakin added a comment - Please note that this fix is needed to resolve a CTS failure.
        Hide
        Jagadish added a comment -

        Provided a fix such that SecurityException would be unwrapped.

        svn log -v -r 59912
        ------------------------------------------------------------------------
        r59912 | jr158900 | 2013-02-28 22:41:43 +0530 (Thu, 28 Feb 2013) | 4 lines
        Changed paths:
        M /trunk/main/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/ConnectionManagerImpl.java

        Show
        Jagadish added a comment - Provided a fix such that SecurityException would be unwrapped. svn log -v -r 59912 ------------------------------------------------------------------------ r59912 | jr158900 | 2013-02-28 22:41:43 +0530 (Thu, 28 Feb 2013) | 4 lines Changed paths: M /trunk/main/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/ConnectionManagerImpl.java

          People

          • Assignee:
            Jagadish
            Reporter:
            Nigel Deakin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: