FileDocCategorySizeDatePackage
SecurityUtils.javaAPI DocGlassfish v2 API7170Fri May 04 22:36:10 BST 2007com.sun.gjc.util

SecurityUtils

public class SecurityUtils extends Object
SecurityUtils for Generic JDBC Connector.
version
1.0, 02/07/22
author
Evani Sai Surya Kiran

Fields Summary
private static com.sun.enterprise.util.i18n.StringManager
sm
Constructors Summary
Methods Summary
public static javax.resource.spi.security.PasswordCredentialgetPasswordCredential(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.

param
mcf ManagedConnectionFactory
param
subject Subject
param
info ConnectionRequestInfo
return
PasswordCredential
throws
ResourceException generic exception if operation fails
throws
SecurityException if access to the Subject instance is denied


                                                                                                                      	         	            
         
                                                                  

        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 booleanisEqual(java.lang.String str1, java.lang.String str2)
Returns true if two strings are equal; false otherwise

param
str1 String
param
str2 String
return
true if the two strings are equal false otherwise

        if (str1 == null) {
            return (str2 == null);
        } else {
            return str1.equals(str2);
        }
    
public static booleanisPasswordCredentialEqual(javax.resource.spi.security.PasswordCredential pC1, javax.resource.spi.security.PasswordCredential pC2)
Returns true if two PasswordCredential objects are equal; false otherwise

param
pC1 PasswordCredential
param
pC2 PasswordCredential
return
true if the two PasswordCredentials 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));