Search in sources :

Example 56 with ServiceSchema

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

the class UpgradeUtils method getAttributeValue.

/**
     * Returns a set of values of an attribute.
     *
     * @param serviceName name of the service.
     * @param attributeName the attribute name.
     * @param schemaType the schema type.
     * @param isOrgAttrSchema boolean value indicating whether
     *        the attribute is to be retrieved from
     *        <OrganizationAttributeSchema>
     * @return a set of values for the attribute.
     * @throws UpgradeException if there is an error.
     */
public static Set getAttributeValue(String serviceName, String attributeName, String schemaType, boolean isOrgAttrSchema) throws UpgradeException {
    String classMethod = "UpgradeUtils:getAttributeValue : ";
    Set attrValues = Collections.EMPTY_SET;
    try {
        ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
        ServiceSchema ss = null;
        if (isOrgAttrSchema) {
            ss = sm.getOrganizationCreationSchema();
        } else {
            ss = sm.getSchema(schemaType);
        }
        Map attributeDefaults = ss.getAttributeDefaults();
        if (attributeDefaults.containsKey(attributeName)) {
            attrValues = (Set) attributeDefaults.get(attributeName);
        }
    } catch (SMSException sme) {
        debug.error(classMethod + "Error retreiving attribute values : ", sme);
        throw new UpgradeException("Unable to get attribute values : " + sme.getMessage());
    }
    return attrValues;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 57 with ServiceSchema

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

the class UpgradeUtils method addNewSubSchemas.

public static void addNewSubSchemas(String serviceName, Map<String, SubSchemaUpgradeWrapper> subSchemaChanges, SSOToken adminToken) throws UpgradeException {
    for (Map.Entry<String, SubSchemaUpgradeWrapper> subSchemaAdds : subSchemaChanges.entrySet()) {
        SubSchemaUpgradeWrapper ssAdd = subSchemaAdds.getValue();
        if (ssAdd != null) {
            if (ssAdd.getSubSchemasAdded() != null && ssAdd.getSubSchemasAdded().subSchemaChanged()) {
                ServiceSchema ss = getServiceSchema(serviceName, null, subSchemaAdds.getKey(), adminToken);
                addNewSubSchema(serviceName, ssAdd.getSubSchemasAdded(), ss, adminToken);
            }
        }
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 58 with ServiceSchema

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

the class UpgradeUtils method getSubSchemaAttributeValue.

/**
     * Returns a value of an attribute.
     * This method assumes that the attribute is single valued.
     *
     * @param serviceName name of the service.
     * @param attributeName name of the attribute.
     * @param schemaType the schema type.
     * @param subSchemaName the sub schema name.
     * @return the value of the attribute
     */
public static String getSubSchemaAttributeValue(String serviceName, String schemaType, String attributeName, String subSchemaName) {
    String classMethod = "UpgradeUtils:getSubSchemaAttributeValue :";
    ServiceSchema ss = null;
    String value = null;
    try {
        ss = getServiceSchema(serviceName, subSchemaName, schemaType);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeName);
        Set defaultVal = attrSchema.getDefaultValues();
        value = (String) (defaultVal.iterator().next());
    } catch (Exception e) {
        debug.error(classMethod + "cannot retrieve attribute value for " + attributeName);
    }
    return value;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) AttributeSchema(com.sun.identity.sm.AttributeSchema) ByteString(org.forgerock.opendj.ldap.ByteString) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Example 59 with ServiceSchema

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

the class UpgradeUtils method modifyAttributesInExistingSchema.

protected static void modifyAttributesInExistingSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
    for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
        modifyAttributeInExistingSchema(serviceName, null, schemaType, attrs.getName(), attrs.getAttributeSchemaNode(), adminToken);
    }
    if (schemaMods.hasSubSchema()) {
        for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
            for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
                ServiceSchema subSchema = null;
                try {
                    subSchema = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to modify attributes in schema", smse);
                    throw new UpgradeException(smse);
                }
                modifyAttributeInExistingSchema(subSchema, attrs.getName(), attrs.getAttributeSchemaNode());
            }
            if (schema.getValue().hasSubSchema()) {
                ServiceSchema ss = null;
                try {
                    ss = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to modify attributes in schema", smse);
                    throw new UpgradeException(smse);
                }
                modifyAttributesInExistingSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
            }
        }
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with ServiceSchema

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

the class UpgradeUtils method addAttributeToSubSchema.

/**
     * Adds new attribute schema to a sub schema in an existing service.
     *
     * @param serviceName the service name.
     * @param subSchemaName the sub schema name.
     * @param schemaType the schema type.
     * @param attributeSchemaFile
     *         XML file containing attribute schema definition.
     * @throws UpgradeException if there is an error adding the
     *         attribute schema.
     * @supported.api
     */
public static void addAttributeToSubSchema(String serviceName, String subSchemaName, String schemaType, String attributeSchemaFile) throws UpgradeException {
    String classMethod = "UpgradeUtils:addAttributeToSubSchema : ";
    if (debug.messageEnabled()) {
        debug.message(classMethod + "Adding attribute schema : " + attributeSchemaFile);
        debug.message(" to subSchema " + subSchemaName + " to service " + serviceName);
    }
    FileInputStream fis = null;
    ServiceSchema ss = getServiceSchema(serviceName, subSchemaName, schemaType);
    try {
        fis = new FileInputStream(attributeSchemaFile);
        ss.addAttributeSchema(fis);
    } catch (IOException ioe) {
        debug.error(classMethod + "File not found " + attributeSchemaFile);
        throw new UpgradeException(ioe.getMessage());
    } catch (SMSException sme) {
        debug.error(classMethod + "Cannot add attribute schema to : " + serviceName, sme);
        throw new UpgradeException(sme.getMessage());
    } catch (SSOException ssoe) {
        debug.error(classMethod + "Invalid SSOToken : ", ssoe);
        throw new UpgradeException(ssoe.getMessage());
    } catch (Exception e) {
        debug.error(classMethod + "Error setting attribute schema : ", e);
        throw new UpgradeException(e.getMessage());
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Aggregations

ServiceSchema (com.sun.identity.sm.ServiceSchema)216 SMSException (com.sun.identity.sm.SMSException)152 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)131 SSOException (com.iplanet.sso.SSOException)117 Set (java.util.Set)101 AttributeSchema (com.sun.identity.sm.AttributeSchema)76 HashSet (java.util.HashSet)71 Map (java.util.Map)70 HashMap (java.util.HashMap)57 Iterator (java.util.Iterator)56 CLIException (com.sun.identity.cli.CLIException)46 SSOToken (com.iplanet.sso.SSOToken)27 IOutput (com.sun.identity.cli.IOutput)26 BeforeTest (org.testng.annotations.BeforeTest)22 CLIRequest (com.sun.identity.cli.CLIRequest)21 ByteString (org.forgerock.opendj.ldap.ByteString)21 AfterTest (org.testng.annotations.AfterTest)21 Test (org.testng.annotations.Test)21 Parameters (org.testng.annotations.Parameters)18 TreeSet (java.util.TreeSet)15