Search in sources :

Example 11 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.

the class CLIUtil method getPasswordFields.

/**
     * Returns a set of attributes (of password syntax) of a given service.
     *
     * @param serviceName Name of service.
     * @return a set of attributes (of password syntax) of a given service.
     * @throws SMSException if error occurs when reading the service schema 
     *         layer
     * @throws SSOException if Single sign-on token is invalid.
     */
public static Set getPasswordFields(String serviceName) throws SMSException, SSOException {
    Set setPasswords = new HashSet();
    SSOToken ssoToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, ssoToken);
    if (ssm != null) {
        ServiceSchema schema = ssm.getOrganizationSchema();
        if (schema != null) {
            Set attributeSchemas = schema.getAttributeSchemas();
            for (Iterator i = attributeSchemas.iterator(); i.hasNext(); ) {
                AttributeSchema as = (AttributeSchema) i.next();
                if (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD)) {
                    setPasswords.add(as.getName());
                }
            }
        }
    }
    return setPasswords;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 12 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.

the class CLIUtil method getPasswordFields.

/**
     * Returns a set of attributes (of password syntax) of a given service.
     *
     * @param serviceName Name of service.
     * @param schemaType Type of Schema.
     * @param subSchema Name of SubSchema
     * @return a set of attributes (of password syntax) of a given service.
     * @throws SMSException if error occurs when reading the service schema 
     *         layer
     * @throws SSOException if Single sign-on token is invalid.
     */
public static Set getPasswordFields(String serviceName, SchemaType schemaType, String subSchema) throws SMSException, SSOException {
    Set setPasswords = new HashSet();
    SSOToken ssoToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, ssoToken);
    if (ssm != null) {
        ServiceSchema schema = ssm.getSchema(schemaType);
        if (schema != null) {
            ServiceSchema ss = schema.getSubSchema(subSchema);
            Set attributeSchemas = ss.getAttributeSchemas();
            for (Iterator i = attributeSchemas.iterator(); i.hasNext(); ) {
                AttributeSchema as = (AttributeSchema) i.next();
                if (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD)) {
                    setPasswords.add(as.getName());
                }
            }
        }
    }
    return setPasswords;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 13 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.

the class ComplianceServicesImpl method getDeletedObjectFilter.

/**
     * Protected method to get the search filter to be used for searching for
     * deleted objects.
     * 
     */
public String getDeletedObjectFilter(int objectType) throws AMException, SSOException {
    Set values = new HashSet();
    try {
        if (gsc == null) {
            ServiceSchemaManager scm = new ServiceSchemaManager(ADMINISTRATION_SERVICE, internalToken);
            gsc = scm.getGlobalSchema();
        }
        Map attrMap = gsc.getAttributeDefaults();
        if (attrMap != null)
            values = (Set) attrMap.get(COMPLIANCE_SPECIAL_FILTER_ATTR);
        if (debug.messageEnabled()) {
            debug.message("Compliance.getDeletedObjectSearchFilter = " + values.toString());
        }
    } catch (SMSException ex) {
        debug.error(AMSDKBundle.getString("359"), ex);
        throw new AMException(AMSDKBundle.getString("359"), "359");
    } catch (SSOException ex) {
        debug.error(AMSDKBundle.getString("359"), ex);
        throw new AMException(AMSDKBundle.getString("359"), "359");
    }
    String org_filter = null;
    String group_filter = null;
    String user_filter = null;
    String def_filter = null;
    String res_filter = null;
    Iterator iter = values.iterator();
    while (iter.hasNext()) {
        String thisFilter = (String) iter.next();
        if (thisFilter.startsWith("Organization=")) {
            org_filter = thisFilter.substring(13);
        } else if (thisFilter.startsWith("Group=")) {
            group_filter = thisFilter.substring(6);
        } else if (thisFilter.startsWith("User=")) {
            user_filter = thisFilter.substring(5);
        } else if (thisFilter.startsWith("Misc=")) {
            def_filter = thisFilter.substring(5);
        } else if (thisFilter.startsWith("Resource=")) {
            res_filter = thisFilter.substring(9);
        }
    }
    org_filter = (org_filter == null) ? DEFAULT_DELETED_ORG_FILTER : org_filter;
    group_filter = (group_filter == null) ? DEFAULT_DELETED_GROUP_FILTER : group_filter;
    user_filter = (user_filter == null) ? DEFAULT_DELETED_USER_FILTER : user_filter;
    def_filter = (def_filter == null) ? DEFAULT_DELETED_OBJECT_FILTER : def_filter;
    res_filter = (res_filter == null) ? DEFAULT_DELETED_RESOURCE_FILTER : res_filter;
    switch(objectType) {
        case AMObject.ORGANIZATION:
            return (org_filter);
        case AMObject.USER:
            return (user_filter);
        case AMObject.ASSIGNABLE_DYNAMIC_GROUP:
        case AMObject.DYNAMIC_GROUP:
        case AMObject.STATIC_GROUP:
        case AMObject.GROUP:
            return (group_filter);
        case AMObject.RESOURCE:
            return (res_filter);
        default:
            return ("(|" + org_filter + group_filter + user_filter + def_filter + res_filter + ")");
    }
}
Also used : HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 14 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.

the class DirectoryServicesImpl method getServiceAttributesWithQualifier.

/**
     * Method to get the attribute names of a service with CosQualifier. For
     * example: Return set could be ["iplanet-am-web-agent-allow-list
     * merge-schemes", "iplanet-am-web-agent-deny-list merge-schemes"] This only
     * returns Dynamic attributes
     */
private Set getServiceAttributesWithQualifier(SSOToken token, String serviceName) throws SMSException, SSOException {
    ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
    ServiceSchema ss = null;
    try {
        ss = ssm.getSchema(SchemaType.DYNAMIC);
    } catch (SMSException sme) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.getServiceNames(): No " + "schema defined for SchemaType.DYNAMIC type");
        }
    }
    if (ss == null) {
        return Collections.EMPTY_SET;
    }
    Set attrNames = new HashSet();
    Set attrSchemaNames = ss.getAttributeSchemaNames();
    Iterator itr = attrSchemaNames.iterator();
    while (itr.hasNext()) {
        String attrSchemaName = (String) itr.next();
        AttributeSchema attrSchema = ss.getAttributeSchema(attrSchemaName);
        String name = attrSchemaName + " " + attrSchema.getCosQualifier();
        attrNames.add(name);
    }
    return attrNames;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 15 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.

the class AMAuthenticationManager method createAuthenticationInstance.

/**
     * Creates an <code>AMAuthenticationInstance</code> instance with the
     * specified parameters.
     *
     * @param name Name of the authentication module instance.
     * @param type Type of the authentication module instance.
     * @param attributes A Map of parameters for this module instance.
     * @return <code>AMAuthenticationInstance</code> object is newly created.
     * @throws AMConfigurationException if error occurred during the 
     *         authentication creation.
     */
public AMAuthenticationInstance createAuthenticationInstance(String name, String type, Map attributes) throws AMConfigurationException {
    if (name.indexOf(' ') != -1) {
        throw new AMConfigurationException(BUNDLE_NAME, "invalidAuthenticationInstanceName", null);
    }
    Set moduleTypes = getAuthenticationTypes();
    if (!moduleTypes.contains(type)) {
        throw new AMConfigurationException(BUNDLE_NAME, "wrongType", new Object[] { type });
    }
    AMAuthenticationInstance instance = getAuthenticationInstance(name);
    if (instance != null) {
        if (instance.getServiceConfig() != null) {
            throw new AMConfigurationException(BUNDLE_NAME, "authInstanceExist", new Object[] { name });
        } else {
            throw new AMConfigurationException(BUNDLE_NAME, "authInstanceIsGlobal", new Object[] { name });
        }
    }
    String serviceName = getServiceName(type);
    ServiceSchema schema = null;
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        schema = ssm.getSchema(SchemaType.GLOBAL);
    } catch (SSOException e) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("Token doesn't have access to service: " + token + " -> " + serviceName);
        }
    } catch (SMSException e) {
    // normal exception for service without global configuration.
    // no need to log anything.
    }
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(token, realm);
        // Check if service is assigned
        if (!ocm.getAssignedServices().contains(serviceName)) {
            ocm.assignService(serviceName, null);
        }
        ServiceConfig orgConfig = ocm.getServiceConfig(serviceName);
        if (orgConfig == null) {
            orgConfig = ocm.addServiceConfig(serviceName, null);
        }
        ServiceConfig subConfig = orgConfig;
        if (!name.equals(type)) {
            orgConfig.addSubConfig(name, ISAuthConstants.SERVER_SUBSCHEMA, 0, attributes);
            subConfig = orgConfig.getSubConfig(name);
        } else {
            // if the module instance name equals to its type, set the
            // the attributes in its organization config, not sub config.
            subConfig.setAttributes(attributes);
        }
        //AMAuthLevelManager listeners are in place, so let's reinitialize to be on the safe side.
        if (!SystemProperties.isServerMode()) {
            buildModuleInstanceForService(realm, serviceName);
        }
        return new AMAuthenticationInstance(name, type, subConfig, schema);
    } catch (Exception e) {
        throw new AMConfigurationException(e);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) ServiceConfig(com.sun.identity.sm.ServiceConfig) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Aggregations

ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)209 SMSException (com.sun.identity.sm.SMSException)146 ServiceSchema (com.sun.identity.sm.ServiceSchema)131 SSOException (com.iplanet.sso.SSOException)119 Set (java.util.Set)87 HashSet (java.util.HashSet)60 Map (java.util.Map)56 HashMap (java.util.HashMap)49 AttributeSchema (com.sun.identity.sm.AttributeSchema)46 SSOToken (com.iplanet.sso.SSOToken)43 Iterator (java.util.Iterator)40 CLIException (com.sun.identity.cli.CLIException)33 BeforeTest (org.testng.annotations.BeforeTest)27 AfterTest (org.testng.annotations.AfterTest)26 Test (org.testng.annotations.Test)26 CLIRequest (com.sun.identity.cli.CLIRequest)25 Parameters (org.testng.annotations.Parameters)18 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)15 TreeSet (java.util.TreeSet)12 ByteString (org.forgerock.opendj.ldap.ByteString)11