Search in sources :

Example 6 with DecodeAction

use of com.sun.identity.security.DecodeAction in project OpenAM by OpenRock.

the class AMCrypt method decryptPasswords.

public static Map decryptPasswords(Map attributes, ServiceSchema serviceSchema) {
    if (serviceSchema == null || attributes == null) {
        return attributes;
    }
    Iterator iter = attributes.keySet().iterator();
    while (iter.hasNext()) {
        String attributeName = (String) (iter.next());
        AttributeSchema as = serviceSchema.getAttributeSchema(attributeName);
        if (as != null && (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) || as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD))) {
            Set valueSet = (Set) (attributes.get(attributeName));
            if (valueSet != null) {
                HashSet tmpValueSet = new HashSet(valueSet);
                valueSet.clear();
                Iterator valIter = tmpValueSet.iterator();
                while (valIter.hasNext()) {
                    String value = (String) valIter.next();
                    if (value != null) {
                        value = (String) AccessController.doPrivileged(new DecodeAction(value));
                    }
                    valueSet.add(value);
                }
            }
        }
    }
    return attributes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) DecodeAction(com.sun.identity.security.DecodeAction) HashSet(java.util.HashSet)

Example 7 with DecodeAction

use of com.sun.identity.security.DecodeAction in project OpenAM by OpenRock.

the class AMCrypt method decryptPasswords.

public static Set decryptPasswords(Set values, String attributeName, ServiceSchema serviceSchema) {
    if (values == null || values.isEmpty()) {
        return values;
    }
    AttributeSchema as = serviceSchema.getAttributeSchema(attributeName);
    if (as == null || (!as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) && !as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD))) {
        return values;
    }
    HashSet result = new HashSet();
    Iterator iter = values.iterator();
    while (iter.hasNext()) {
        String value = (String) iter.next();
        if (value != null) {
            value = (String) AccessController.doPrivileged(new DecodeAction(value));
        }
        result.add(value);
    }
    return result;
}
Also used : AttributeSchema(com.sun.identity.sm.AttributeSchema) Iterator(java.util.Iterator) DecodeAction(com.sun.identity.security.DecodeAction) HashSet(java.util.HashSet)

Example 8 with DecodeAction

use of com.sun.identity.security.DecodeAction in project OpenAM by OpenRock.

the class SessionService method decrypt.

/**
     * This method is used to decrypt the InternalSession object, after
     * obtaining from HttpSession.
     *
     * @param strEncrypted Object to be decrypted
     */
private InternalSession decrypt(String strEncrypted) {
    if (strEncrypted == null)
        return null;
    String strDecrypted;
    byte[] byteDecrypted = null;
    ByteArrayInputStream byteIn;
    ObjectInputStream objInStream;
    Object tempObject = null;
    try {
        // decrypt string
        strDecrypted = AccessController.doPrivileged(new DecodeAction(strEncrypted, Crypt.getHardcodedKeyEncryptor()));
        // convert string to byte
        byteDecrypted = Base64.decode(strDecrypted);
        // convert byte to object using streams
        byteIn = new ByteArrayInputStream(byteDecrypted);
        objInStream = new ObjectInputStream(byteIn);
        tempObject = objInStream.readObject();
    } catch (Exception e) {
        sessionDebug.message("Error in decrypting the Internal Session object" + e.getMessage());
        return null;
    }
    if (tempObject == null) {
        return null;
    }
    return (InternalSession) tempObject;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DecodeAction(com.sun.identity.security.DecodeAction) DelegationException(com.sun.identity.delegation.DelegationException) SSOException(com.iplanet.sso.SSOException) InterruptedIOException(java.io.InterruptedIOException) IdRepoException(com.sun.identity.idm.IdRepoException) ConnectException(java.net.ConnectException) SessionException(com.iplanet.dpro.session.SessionException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with DecodeAction

use of com.sun.identity.security.DecodeAction in project OpenAM by OpenRock.

the class AuthXMLUtils method getDeSerializedSubject.

/**
     * Deserializes Subject.
     *
     * @param subjectSerialized Serialized Subject.
     * @throws Exception
     */
public static Subject getDeSerializedSubject(String subjectSerialized) throws Exception {
    // decrypt and then decode
    String decStr = (String) AccessController.doPrivileged(new DecodeAction(subjectSerialized));
    byte[] sSerialized = Base64.decode(decStr);
    if (sSerialized == null)
        return null;
    byte[] byteDecrypted;
    ByteArrayInputStream byteIn;
    ObjectInputStream objInStream = null;
    Object tempObject = null;
    try {
        byteDecrypted = sSerialized;
        //convert byte to object using streams
        byteIn = new ByteArrayInputStream(byteDecrypted);
        objInStream = new ObjectInputStream(byteIn);
        tempObject = objInStream.readObject();
    } catch (Exception e) {
        debug.message("Exception Message in decrypt: ", e);
    }
    if (tempObject == null)
        return null;
    Subject subjectObj = (Subject) tempObject;
    if (debug.messageEnabled()) {
        debug.message("returning temp" + subjectObj);
    }
    return subjectObj;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DecodeAction(com.sun.identity.security.DecodeAction) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Subject(javax.security.auth.Subject) ObjectInputStream(java.io.ObjectInputStream)

Example 10 with DecodeAction

use of com.sun.identity.security.DecodeAction in project OpenAM by OpenRock.

the class FSSAMLTrustedPartnersViewBeanBase method setValues.

protected void setValues(Map map) {
    Map values = correctCaseOfAttributeNames(map);
    for (Iterator iter = values.keySet().iterator(); iter.hasNext(); ) {
        String attr = (String) iter.next();
        if (attr.equals(SAMLConstants.AUTH_PASSWORD)) {
            String pwd = (String) AccessController.doPrivileged(new DecodeAction((String) values.get(attr)));
            propertySheetModel.setValue(SAMLConstants.AUTH_PASSWORD, pwd);
            propertySheetModel.setValue(SAMLConstants.AUTH_PASSWORD + SAMLPropertyTemplate.CONFIRM_SUFFIX, pwd);
        } else {
            propertySheetModel.setValue(attr, values.get(attr));
        }
    }
}
Also used : Iterator(java.util.Iterator) DecodeAction(com.sun.identity.security.DecodeAction) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DecodeAction (com.sun.identity.security.DecodeAction)18 Iterator (java.util.Iterator)9 HashSet (java.util.HashSet)7 Set (java.util.Set)5 IOException (java.io.IOException)4 SSOException (com.iplanet.sso.SSOException)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 BufferedReader (java.io.BufferedReader)3 HashMap (java.util.HashMap)3 Node (org.w3c.dom.Node)3 SessionException (com.iplanet.dpro.session.SessionException)2 EncodeAction (com.sun.identity.security.EncodeAction)2 AttributeSchema (com.sun.identity.sm.AttributeSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 ObjectInputStream (java.io.ObjectInputStream)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 XMLException (com.iplanet.services.util.XMLException)1