Search in sources :

Example 56 with ServiceSchemaManager

use of com.sun.identity.sm.ServiceSchemaManager 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 ServiceSchemaManager

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

the class UpgradeUtils method setServiceRevision.

/**
     * Sets the service revision number.
     *
     * @param serviceName name of the service.
     * @param revisionNumber the revisionNumber of the service.
     * @throws <code>UpgradeException</code> if there is an error.
     */
public static void setServiceRevision(String serviceName, String revisionNumber) throws UpgradeException {
    String classMethod = "UpgradeUtils:setServiceRevision : ";
    try {
        System.out.println(bundle.getString("upg-service-name") + ":" + serviceName);
        System.out.println(bundle.getString("upg-revision-number") + ":" + revisionNumber);
        if (debug.messageEnabled()) {
            debug.message("Setting service revision for :" + serviceName + "to : " + revisionNumber);
        }
        ServiceSchemaManager ssm = getServiceSchemaManager(serviceName);
        ssm.setRevisionNumber(Integer.parseInt(revisionNumber));
        if (debug.messageEnabled()) {
            debug.message(classMethod + serviceName + ":Setting Service Revision Number" + revisionNumber);
        }
    } catch (SSOException ssoe) {
        throw new UpgradeException("Invalid SSOToken ");
    } catch (SMSException sme) {
        throw new UpgradeException("Error setting serviceRevision value");
    }
}
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)

Example 58 with ServiceSchemaManager

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

the class ClientResourceTest method setUp.

@BeforeTest
public void setUp() throws SMSException {
    mockManager = mock(ClientResourceManager.class);
    ServiceSchemaManager mockSchemaManager = mock(ServiceSchemaManager.class);
    ServiceSchema mockSchema = mock(ServiceSchema.class);
    mockSubSchema = mock(ServiceSchema.class);
    Mockito.doReturn(mockSchema).when(mockSchemaManager).getOrganizationSchema();
    Mockito.doReturn(mockSubSchema).when(mockSchema).getSubSchema(anyString());
    resource = new ClientResource(mockManager, mock(CTSPersistentStore.class), mockSchemaManager, mock(OAuth2AuditLogger.class), mock(Debug.class));
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 59 with ServiceSchemaManager

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

the class SpecialRepo method replaceDNAttributeIfPresent.

private void replaceDNAttributeIfPresent(Map attributes) {
    // to be added
    if (ssm == null) {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        try {
            ssm = new ServiceSchemaManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
        } catch (SMSException smse) {
            debug.error("SpecialRepo.replaceDN: Unable to get Schema" + "to determine revision number", smse);
            return;
        } catch (SSOException ssoe) {
            // should not happen
            return;
        }
    }
    if (ssm.getRevisionNumber() >= 30) {
        Set values;
        if ((attributes != null) && ((values = (Set) attributes.get(dnAttribute)) != null)) {
            for (Iterator items = values.iterator(); items.hasNext(); ) {
                String name = items.next().toString();
                // Hence check if it ends with SMS root suffix
                if (name.toLowerCase().endsWith(SMSEntry.getRootSuffix().toLowerCase())) {
                    // Replace only if the they are different
                    if (!SMSEntry.getRootSuffix().equals(SMSEntry.getAMSdkBaseDN())) {
                        name = name.substring(0, name.length() - SMSEntry.getRootSuffix().length());
                        name = name + SMSEntry.getAMSdkBaseDN();
                    }
                } else {
                    name = name + SMSEntry.getAMSdkBaseDN();
                }
                Set newValues = new HashSet();
                newValues.add(name);
                attributes.put(dnAttribute, newValues);
                break;
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 60 with ServiceSchemaManager

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

the class SpecialRepo method removeListener.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#removeListener()
     */
public void removeListener() {
    if (scm != null) {
        scm.removeListener(scmListenerId);
        scm = null;
    }
    if (ssm != null) {
        ssm.removeListener(ssmListenerId);
        //make sure old reference get GCed asap
        ssm = null;
        //make sure any old lingering object would be cleaned.
        try {
            SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            ssm = new ServiceSchemaManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
            ssm.removeListener(ssmListenerId);
        } catch (SSOException ssoe) {
        // listener should be removed in first try. ignoring any error
        } catch (SMSException smse) {
        // listener should be removed in first try. ignoring any error
        }
    }
    repoListener = null;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

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