Search in sources :

Example 1 with DecodeAction

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

the class CreateServiceConfig method createSubConfig.

static void createSubConfig(SSOToken token, String dn, Node node, ServiceSchemaImpl ss, String orgdn, AMEncryption decryptObj) throws SMSException, SSOException {
    // Get service id and priority
    String id = XMLUtils.getNodeAttributeValue(node, SMSUtils.SERVICE_ID);
    String priority = XMLUtils.getNodeAttributeValue(node, SMSUtils.PRIORITY);
    // Get the attributes
    Map attrs = getAttributeValuePairs(node);
    if ((decryptObj != null) && (attrs != null) && !attrs.isEmpty()) {
        for (Iterator i = attrs.keySet().iterator(); i.hasNext(); ) {
            String attrName = (String) i.next();
            AttributeSchemaImpl as = ss.getAttributeSchema(attrName);
            AttributeSchema.Syntax syntax = as.getSyntax();
            if (syntax.equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD) || syntax.equals(AttributeSchema.Syntax.PASSWORD)) {
                Set values = (Set) attrs.get(attrName);
                if ((values != null) && !values.isEmpty()) {
                    Set decoded = new HashSet(values.size() * 2);
                    for (Iterator j = values.iterator(); j.hasNext(); ) {
                        decoded.add(AccessController.doPrivileged(new DecodeAction((String) j.next(), decryptObj)));
                    }
                    attrs.put(attrName, decoded);
                }
            }
        }
    }
    // Create the LDAP entry
    createSubConfigEntry(token, dn, ss, id, priority, attrs, orgdn);
    // Check for further sub-configuration
    Iterator subConfigs = XMLUtils.getChildNodes(node, SMSUtils.SUB_CONFIG).iterator();
    while (subConfigs.hasNext()) {
        Node subConfigNode = (Node) subConfigs.next();
        String subConfigName = XMLUtils.getNodeAttributeValue(subConfigNode, SMSUtils.NAME);
        String subConfigID = XMLUtils.getNodeAttributeValue(subConfigNode, SMSUtils.SERVICE_ID);
        if (subConfigID == null) {
            subConfigID = subConfigName;
        }
        createSubConfig(token, ("ou=" + subConfigName + "," + dn), subConfigNode, ss.getSubSchema(subConfigID), orgdn, decryptObj);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) DecodeAction(com.sun.identity.security.DecodeAction) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with DecodeAction

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

the class AttributeValidator method inheritDefaults.

/**
     * This method checks if the attribute name (as given by the
     * AttributeSchema) is present, and if missings adds the defaults values.
     * 
     * @param attrs
     *            A map of the attributes and their values
     * @return A map which is a union of the attributes provided and default
     *         attribute values
     */
Map inheritDefaults(Map attrs) {
    Set values = (Set) attrs.get(as.getName());
    if (values == null) {
        // Inherit the default values
        attrs.put(as.getName(), as.getDefaultValues());
    } else if (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) || as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD)) {
        // Decrypt the password
        Set vals = new HashSet();
        for (Iterator items = values.iterator(); items.hasNext(); ) {
            String tString = (String) items.next();
            try {
                vals.add(AccessController.doPrivileged(new DecodeAction(tString)));
            } catch (Throwable e) {
                debug.error("AttributeValidator: Unable to decode", e);
                vals.add(tString);
            }
        }
        attrs.put(as.getName(), vals);
    }
    return (attrs);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) DecodeAction(com.sun.identity.security.DecodeAction) HashSet(java.util.HashSet)

Example 3 with DecodeAction

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

the class AttributeValidator method decodeEncodedAttrs.

/**
     * This method checks if attribute schema is of syntax password or
     * encoded_password, if so it decrypts the password when it is stored in the
     * cache.
     * 
     * @param attrs
     *            a Map of the attributes and their values
     * @return A map which is has replaced encrypted values with decrypted ones.
     */
Map decodeEncodedAttrs(Map attrs) {
    Set values = (Set) attrs.get(as.getName());
    if (values == null) {
        return attrs;
    }
    if (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) || as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD)) {
        // Decrypt the password
        Set vals = new HashSet();
        for (Iterator items = values.iterator(); items.hasNext(); ) {
            String tString = (String) items.next();
            try {
                vals.add(AccessController.doPrivileged(new DecodeAction(tString)));
            } catch (Throwable e) {
                debug.error("AttributeValidator: Unable to decode", e);
                vals.add(tString);
            }
        }
        attrs.put(as.getName(), vals);
    }
    return (attrs);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) DecodeAction(com.sun.identity.security.DecodeAction) HashSet(java.util.HashSet)

Example 4 with DecodeAction

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

the class MonitoringUtil method getMonAuthList.

protected static Map<String, String> getMonAuthList(String authFilePath) {
    String classMethod = "OpenSSOMonitoringUtil.getMonAuthList: ";
    if ((authFilePath == null) || ((authFilePath.trim().length() == 0))) {
        debug.error(classMethod + "No authentication file specified.");
        return null;
    }
    // prep for the "%BASE_DIR%/%SERVER_URI%/" style filepath
    if (authFilePath.contains("%BASE_DIR%") || (authFilePath.contains("%SERVER_URI%"))) {
        String ossoUri = SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
        ossoUri = ossoUri.replace('\\', '/');
        String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
        baseDir = baseDir.replace('\\', '/');
        if (ossoUri.startsWith("/")) {
            ossoUri = ossoUri.substring(1);
        }
        if (!ossoUri.endsWith("/")) {
            ossoUri += "/";
        }
        if (!baseDir.endsWith("/")) {
            baseDir += "/";
        }
        authFilePath = authFilePath.replaceAll("%BASE_DIR%", baseDir);
        authFilePath = authFilePath.replaceAll("%SERVER_URI%", ossoUri);
    }
    Map<String, String> hm = new HashMap<String, String>();
    try {
        BufferedReader frdr = new BufferedReader(new FileReader(authFilePath));
        String fbuff = null;
        while ((fbuff = frdr.readLine()) != null) {
            if (fbuff.trim().length() > 0) {
                StringTokenizer st = new StringTokenizer(fbuff);
                // assume first is userid, second is password, ignore rest
                if (st.countTokens() > 1) {
                    String userid = st.nextToken();
                    String passwd = st.nextToken();
                    String decpswd = AccessController.doPrivileged(new DecodeAction(passwd));
                    hm.put(userid, decpswd);
                }
            }
        }
        if (!hm.isEmpty()) {
            return hm;
        } else {
            return null;
        }
    } catch (IOException e) {
        debug.error(classMethod + "IOex on file " + authFilePath + ": " + e.getMessage());
    } catch (RuntimeException e) {
        debug.error(classMethod + "RuntimeEx on file " + authFilePath + ": ", e);
    } catch (Exception e) {
        debug.error(classMethod + "Exception on file " + authFilePath + ": ", e);
    }
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) BufferedReader(java.io.BufferedReader) DecodeAction(com.sun.identity.security.DecodeAction) FileReader(java.io.FileReader) IOException(java.io.IOException) IOException(java.io.IOException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 5 with DecodeAction

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

the class SAMLConfigValidator method readPwdFile.

private String readPwdFile(String pfile) {
    String pwdStr = null;
    if (pfile != null) {
        try {
            FileInputStream fis = new FileInputStream(pfile);
            InputStreamReader isr = new InputStreamReader(fis);
            BufferedReader br = new BufferedReader(isr);
            pwdStr = (String) AccessController.doPrivileged(new DecodeAction(br.readLine()));
            fis.close();
        } catch (Exception e) {
            Debug.getInstance(DEBUG_NAME).error("SAMLConfigValidator.readPwdFile: " + "Exception in reading password file information", e);
        }
    }
    return pwdStr;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) DecodeAction(com.sun.identity.security.DecodeAction) FileInputStream(java.io.FileInputStream)

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