Search in sources :

Example 6 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class RelativePathResolver method getRealPasswordFromAlias.

/**
 * Returns the actual password from the domain-wide safe password store,
 * if the given password is aliased. An aliased String is of the form
 * ${ALIAS=aliasname} where the actual password is stored in given alias name.
 * Following are the returned values:
 * <ul>
 * <li> Returns a null if given String is null. </li>
 * <li> Retuns the given String if it is not in the alias form. </li>
 * <li> Returns the real password from store if the given String is
 *      of the alias form and the alias has been created by the
 *      administrator. If the alias is not defined in the store,
 *      an IllegalArgumentException is thrown with appropriate
 *      message. </li>
 * </ul>
 * @param at is the aliased token of the form "${ALIAS=string}"
 * @return a String representing the actual password
 * @throws IllegalArgumentException if the alias is not defined
 * @throws KeyStoreException CertificateException IOException NoSuchAlgorithmException
 *         UnrecoverableKeyException if there is an error is opening or
 *         processing the password store
 */
public static String getRealPasswordFromAlias(final String at) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
    try {
        if (at == null || RelativePathResolver.getAlias(at) == null) {
            return (at);
        }
    } catch (final Exception e) {
        // underlying code is unsafe!
        return (at);
    }
    final String an = RelativePathResolver.getAlias(at);
    final boolean exists = getDomainPasswordAliasStore().containsKey(an);
    if (!exists) {
        final StringManager lsm = StringManager.getManager(RelativePathResolver.class);
        final String msg = lsm.getString("no_such_alias", an, at);
        throw new IllegalArgumentException(msg);
    }
    final String real = new String(getDomainPasswordAliasStore().get(an));
    return (real);
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 7 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class XAManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential passwordCredential = getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.XADataSource dataSource = getDataSource();
    javax.sql.XAConnection xaConn = null;
    try {
        /* For the case where the user/passwd of the connection pool is
            * equal to the PasswordCredential for the connection request
            * get a connection from this pool directly.
            * for all other conditions go create a new connection
            */
        String user = getUser();
        if (user == null || isEqual(passwordCredential, user, getPassword())) {
            xaConn = dataSource.getXAConnection();
        } else {
            xaConn = dataSource.getXAConnection(passwordCredential.getUserName(), new String(passwordCredential.getPassword()));
        }
    } catch (java.sql.SQLException sqle) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "jdbc.exc_create_xa_conn", sqle);
        }
        StringManager sm = StringManager.getManager(DataSourceObjectBuilder.class);
        String msg = sm.getString("jdbc.cannot_allocate_connection", sqle.getMessage());
        throw new ResourceAllocationException(msg, sqle);
    }
    ManagedConnectionImpl mc = null;
    try {
        mc = constructManagedConnection(xaConn, null, passwordCredential, this);
        mc.initializeConnectionType(ManagedConnectionImpl.ISXACONNECTION);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (xaConn != null) {
                try {
                    xaConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : createManagedConnection" + xaConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) SecurityUtils.getPasswordCredential(com.sun.gjc.util.SecurityUtils.getPasswordCredential) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Aggregations

StringManager (com.sun.enterprise.util.i18n.StringManager)7 DataSourceObjectBuilder (com.sun.gjc.common.DataSourceObjectBuilder)3 SQLException (java.sql.SQLException)3 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)3 PasswordCredential (javax.resource.spi.security.PasswordCredential)3 File (java.io.File)2 IOException (java.io.IOException)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 SecurityUtils.getPasswordCredential (com.sun.gjc.util.SecurityUtils.getPasswordCredential)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 CommandException (org.glassfish.api.admin.CommandException)1