use of com.sun.gjc.spi.ConnectionRequestInfoImpl in project Payara by payara.
the class SecurityUtils method getPasswordCredential.
/**
* This method returns the <code>PasswordCredential</code> object, given
* the <code>ManagedConnectionFactory</code>, subject and the
* <code>ConnectionRequestInfo</code>. It first checks if the
* <code>ConnectionRequestInfo</code> is null or not. If it is not null,
* it constructs a <code>PasswordCredential</code> object with
* the user and password fields from the <code>ConnectionRequestInfo</code> and returns this
* <code>PasswordCredential</code> object. If the <code>ConnectionRequestInfo</code>
* is null, it retrieves the <code>PasswordCredential</code> objects from
* the <code>Subject</code> parameter and returns the first
* <code>PasswordCredential</code> object which contains a
* <code>ManagedConnectionFactory</code>, instance equivalent
* to the <code>ManagedConnectionFactory</code>, parameter.
*
* @param mcf <code>ManagedConnectionFactory</code>
* @param subject <code>Subject</code>
* @param info <code>ConnectionRequestInfo</code>
* @return <code>PasswordCredential</code>
* @throws <code>ResourceException</code> generic exception if operation fails
* @throws <code>SecurityException</code> if access to the <code>Subject</code> instance is denied
*/
public static PasswordCredential getPasswordCredential(final ManagedConnectionFactory mcf, final Subject subject, javax.resource.spi.ConnectionRequestInfo info) throws ResourceException {
if (info == null) {
if (subject == null) {
return null;
} else {
PasswordCredential pc = (PasswordCredential) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Set passwdCredentialSet = subject.getPrivateCredentials(PasswordCredential.class);
Iterator iter = passwdCredentialSet.iterator();
while (iter.hasNext()) {
PasswordCredential temp = (PasswordCredential) iter.next();
if (temp.getManagedConnectionFactory().equals(mcf)) {
return temp;
}
}
return null;
}
});
if (pc == null) {
String msg = sm.getString("su.no_passwd_cred");
throw new javax.resource.spi.SecurityException(msg);
} else {
return pc;
}
}
} else {
ConnectionRequestInfoImpl cxReqInfo = (ConnectionRequestInfoImpl) info;
PasswordCredential pc = new PasswordCredential(cxReqInfo.getUser(), cxReqInfo.getPassword());
pc.setManagedConnectionFactory(mcf);
return pc;
}
}
use of com.sun.gjc.spi.ConnectionRequestInfoImpl in project Payara by payara.
the class AbstractDataSource method getNonTxConnection.
/**
* Gets a connection that is not in the scope of any transaction. This
* can be used to save performance overhead incurred on enlisting/delisting
* each connection got, irrespective of whether its required or not.
* Note here that this meethod does not fit in the connector contract
* per se.
*
* @param user User name for authenticating the connection
* @param password Password for authenticating the connection
* @return <code>java.sql.Connection</code>
* @throws java.sql.SQLException if connection cannot be obtained
*/
@Override
public Connection getNonTxConnection(String user, String password) throws SQLException {
try {
ConnectionRequestInfoImpl cxReqInfo = new ConnectionRequestInfoImpl(user, password.toCharArray());
ConnectionHolder con = (ConnectionHolder) ((com.sun.appserv.connectors.internal.spi.ConnectionManager) cm).allocateNonTxConnection(mcf, cxReqInfo);
setConnectionType(con, true);
return con;
} catch (ResourceException re) {
logNonTransientException(re);
throw new SQLException(re.getMessage(), re);
}
}
use of com.sun.gjc.spi.ConnectionRequestInfoImpl in project Payara by payara.
the class AbstractDataSource method getConnection.
/**
* Retrieves the <code> Connection </code> object.
*
* @param user User name for the Connection.
* @param pwd Password for the Connection.
* @return <code> Connection </code> object.
* @throws SQLException In case of an error.
*/
@Override
public Connection getConnection(String user, String pwd) throws SQLException {
try {
ConnectionRequestInfoImpl info = new ConnectionRequestInfoImpl(user, pwd.toCharArray());
ConnectionHolder con = (ConnectionHolder) cm.allocateConnection(mcf, info);
setConnectionType(con);
return con;
} catch (ResourceException re) {
logNonTransientException(re);
throw new SQLException(re.getMessage(), re);
}
}
Aggregations