Search in sources :

Example 51 with ServiceSchemaManager

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

the class UpgradeUtils method getAttributeValueString.

/**
     * 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.
     * @return the value of the attribute
     * @throws UpgradeException if there is an error.
     */
public static String getAttributeValueString(String serviceName, String attributeName, String schemaType) throws UpgradeException {
    String value = null;
    try {
        ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
        ServiceSchema ss = sm.getSchema(schemaType);
        Map attributeDefaults = ss.getAttributeDefaults();
        if (attributeDefaults.containsKey(attributeName)) {
            HashSet hashSet = (HashSet) attributeDefaults.get(attributeName);
            value = (String) (hashSet.iterator().next());
        }
    } catch (SMSException sme) {
        throw new UpgradeException("Error getting attr value : " + sme.getMessage());
    }
    return value;
}
Also used : 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) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 52 with ServiceSchemaManager

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

the class UpgradeUtils method getServiceSchemaManager.

/**
     * Returns the <code>ServiceSchemaManager</code> for a service.
     *
     * @param serviceName the service name
     * @param ssoToken the admin SSOToken.
     * @return the <code>ServiceSchemaManager</code> of the service.
     */
protected static ServiceSchemaManager getServiceSchemaManager(String serviceName, SSOToken ssoToken) {
    String classMethod = "UpgradeUtils:getServiceSchemaManager : ";
    ServiceSchemaManager mgr = null;
    if (serviceName != null) {
        try {
            if (serviceName.equals(IDFF_PROVIDER_SERVICE)) {
                mgr = new ServiceSchemaManager(ssoToken, serviceName, IDFF_SERVICE_VERSION);
            } else {
                mgr = new ServiceSchemaManager(serviceName, ssoToken);
            }
        } catch (SSOException e) {
            debug.error(classMethod + "SchemaCommand.getServiceSchemaManager", e);
        } catch (SMSException e) {
            debug.error(classMethod + "SchemaCommand.getServiceSchemaManager", e);
        } catch (Exception e) {
            debug.error(classMethod + "Error : ", e);
        }
    }
    return mgr;
}
Also used : SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) 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 53 with ServiceSchemaManager

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

the class UpgradeUtils method getServiceRevision.

/**
     * Returns the current service revision number .
     *
     * @param serviceName name of the service.
     * @return revisionNumber the service revision number.
     */
public static int getServiceRevision(String serviceName) {
    int revisionNumber = -1;
    ServiceSchemaManager ssm = getServiceSchemaManager(serviceName);
    if (ssm != null) {
        revisionNumber = ssm.getRevisionNumber();
    }
    return revisionNumber;
}
Also used : ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 54 with ServiceSchemaManager

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

the class UpgradeUtils method deletePolicyRule.

private static void deletePolicyRule(String serviceName, SSOToken adminToken) throws SMSException, SSOException, AMException {
    String classMethod = "UpgradeUtils:deletePolicyRule : ";
    ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
    if (ssm == null) {
        if (debug.messageEnabled()) {
            debug.message(classMethod + "delete-service-no-policy-rules");
        }
    } else {
        if (ssm.getPolicySchema() == null) {
            if (debug.messageEnabled()) {
                debug.message(classMethod + "delete-service-no-policy-schema");
            }
        } else {
            processCleanPolicies(serviceName, adminToken);
            if (debug.messageEnabled()) {
                debug.message(classMethod + "policy schemas cleaned");
            }
        }
    }
}
Also used : ByteString(org.forgerock.opendj.ldap.ByteString) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 55 with ServiceSchemaManager

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

the class UpgradeUtils method attributeExists.

/**
     * Checks the service scheam for existance of an attribute.
     *
     * @param serviceName name of the service.
     * @param attributeName the attribute name
     * @param schemaType the schema type
     * @return true if attrbute exist else false.
     * @throws UpgradeException if there is an error
     */
public static boolean attributeExists(String serviceName, String attributeName, String schemaType) throws UpgradeException {
    boolean isExists = false;
    try {
        ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
        ServiceSchema ss = sm.getSchema(schemaType);
        Map attributeDefaults = ss.getAttributeDefaults();
        if (attributeDefaults.containsKey(attributeName)) {
            HashSet hashSet = (HashSet) attributeDefaults.get(attributeName);
            String value = (String) (hashSet.iterator().next());
            isExists = true;
        }
    } catch (SMSException sme) {
        throw new UpgradeException("Error getting attribute value");
    }
    return isExists;
}
Also used : 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) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

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