SecurityUtilspublic class SecurityUtils extends Object SecurityUtils for Generic JDBC Connector. |
Fields Summary |
---|
private static com.sun.enterprise.util.i18n.StringManager | sm |
Methods Summary |
---|
public static javax.resource.spi.security.PasswordCredential | getPasswordCredential(ManagedConnectionFactory mcf, javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo info)This method returns the PasswordCredential object, given
the ManagedConnectionFactory , subject and the
ConnectionRequestInfo . It first checks if the
ConnectionRequestInfo is null or not. If it is not null,
it constructs a PasswordCredential object with
the user and password fields from the ConnectionRequestInfo and returns this
PasswordCredential object. If the ConnectionRequestInfo
is null, it retrieves the PasswordCredential objects from
the Subject parameter and returns the first
PasswordCredential object which contains a
ManagedConnectionFactory , instance equivalent
to the ManagedConnectionFactory , parameter.
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 {
com.sun.gjc.spi.ConnectionRequestInfo cxReqInfo = (com.sun.gjc.spi.ConnectionRequestInfo) info;
PasswordCredential pc = new PasswordCredential(cxReqInfo.getUser(), cxReqInfo.getPassword().toCharArray());
pc.setManagedConnectionFactory(mcf);
return pc;
}
| private static boolean | isEqual(java.lang.String str1, java.lang.String str2)Returns true if two strings are equal; false otherwise
if (str1 == null) {
return (str2 == null);
} else {
return str1.equals(str2);
}
| public static boolean | isPasswordCredentialEqual(javax.resource.spi.security.PasswordCredential pC1, javax.resource.spi.security.PasswordCredential pC2)Returns true if two PasswordCredential objects are equal; false otherwise
if (pC1 == pC2)
return true;
if (pC1 == null || pC2 == null)
return (pC1 == pC2);
if (!isEqual(pC1.getUserName(), pC2.getUserName())) {
return false;
}
String p1 = null;
String p2 = null;
if (pC1.getPassword() != null) {
p1 = new String(pC1.getPassword());
}
if (pC2.getPassword() != null) {
p2 = new String(pC2.getPassword());
}
return (isEqual(p1, p2));
|
|