Search in sources :

Example 86 with ServiceConfigManager

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

the class SMServiceListener method registerForNotifications.

public void registerForNotifications() {
    if (listenerId != null) {
        // Listener already registered
        return;
    }
    SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        // Try Delegation Service, present only in OpenSSO
        // Since Delegation Service is being added only in OpenSSO
        // check for its presence in root realm. If not present,
        // it is an upgrade from AM 7.1 and use AuthService
        ServiceConfigManager scm = null;
        try {
            scm = new ServiceConfigManager(DelegationManager.DELEGATION_SERVICE, token);
            if (scm.getOrganizationConfig("/", null) == null) {
                // Delegation Service does not exist for realm
                // Default to auth service
                scm = null;
            }
        } catch (SMSException smse) {
        // Ignore exception and continue with Auth Service
        }
        if (scm == null) {
            // Delegation Service not found, use Auth service
            scm = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, token);
        }
        listenerId = scm.addListener(this);
    } catch (SMSException ex) {
        debug.error("Unable to register SMS notification for Delegation", ex);
    } catch (SSOException ex) {
        debug.error("Unable to register SMS notification for Delegation", ex);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 87 with ServiceConfigManager

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

the class SpecialRepo method getUserConfig.

private ServiceConfig getUserConfig() throws SMSException, SSOException {
    if ((userConfigCache == null) || !userConfigCache.isValid()) {
        if (scm == null) {
            SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            scm = new ServiceConfigManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
        }
        ServiceConfig globalConfig = scm.getGlobalConfig(null);
        userConfigCache = globalConfig.getSubConfig("users");
    }
    return (userConfigCache);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 88 with ServiceConfigManager

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

the class SpecialRepo method addListener.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#addListener(com.iplanet.sso.SSOToken,
     *      com.iplanet.am.sdk.IdRepoListener)
     */
public int addListener(SSOToken token, IdRepoListener listener) throws IdRepoException, SSOException {
    if (debug.messageEnabled()) {
        debug.message(": SpecialRepo addListener");
    }
    repoListener = listener;
    try {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        if (ssm == null) {
            ssm = new ServiceSchemaManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
        }
        if (scm == null) {
            scm = new ServiceConfigManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
        }
        ssmListenerId = ssm.addListener(this);
        scmListenerId = scm.addListener(this);
    } catch (SMSException smse) {
        debug.error("SpecialRepo.addListener: Unable to add listener to" + " SM Updates to special users will not reflect", smse);
    }
    return 0;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 89 with ServiceConfigManager

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

the class STSInstanceConfigStoreBase method updateSTSInstance.

/**
     * Updates attributes corresponding to the existing STS instance.
     * @param stsInstanceId the identifier for the to-be-updated sts instance
     * @param realm The realm in which the sts instance should be deployed
     * @param instance The updated STSInstanceConfig subclass
     * @throws STSPublishException if the SMS encounters a problem during persistence.
     */
@Override
public synchronized void updateSTSInstance(String stsInstanceId, String realm, T instance) throws STSPublishException {
    /*
        Model for code below taken from AuthPropertiesModelImpl#setValues
         */
    ServiceConfig baseService;
    try {
        baseService = new ServiceConfigManager(serviceName, getAdminToken()).getOrganizationConfig(realm, null);
        if (baseService != null) {
            ServiceConfig serviceConfig = baseService.getSubConfig(stsInstanceId);
            if (serviceConfig != null) {
                serviceConfig.setAttributes(instanceConfigMarshaller.toMap(instance));
                logger.debug(restOrSoap() + "sts instance " + stsInstanceId + " in realm " + realm + " updated in persistent store.");
            } else {
                throw new STSPublishException(ResourceException.NOT_FOUND, "Could not create ServiceConfig for realm " + realm + " in order to update " + restOrSoap() + " sts instance with id " + stsInstanceId);
            }
        } else {
            throw new STSPublishException(ResourceException.NOT_FOUND, "Could not create ServiceConfigManager for realm " + realm + " in order to update " + restOrSoap() + " sts instance with id " + stsInstanceId);
        }
    } catch (SMSException | SSOException e) {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Exception caught updating " + restOrSoap() + " sts instance with id " + stsInstanceId + " in realm " + realm + ". Exception: " + e, e);
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) STSPublishException(org.forgerock.openam.sts.STSPublishException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 90 with ServiceConfigManager

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

the class STSInstanceConfigStoreBase method getPublishedInstances.

@Override
@SuppressWarnings("unchecked")
public List<T> getPublishedInstances(String realm) throws STSPublishException {
    List<T> instances = new ArrayList<>();
    ServiceConfig baseService;
    try {
        baseService = new ServiceConfigManager(serviceName, getAdminToken()).getOrganizationConfig(realm, null);
    } catch (SMSException | SSOException e) {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Could not obtain ServiceConfig instance for realm " + realm + "." + restOrSoap() + " sts instances for this realm cannot be returned from getAllPublishedInstances(String realm). " + "Exception: " + e, e);
    }
    if (baseService != null) {
        Set<String> subConfigNames;
        try {
            subConfigNames = baseService.getSubConfigNames();
        } catch (SMSException e) {
            throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Could not get list of " + restOrSoap() + "sts instances in realm " + realm + ". Exception: " + e, e);
        }
        for (String stsInstanceId : subConfigNames) {
            ServiceConfig instanceService;
            try {
                instanceService = baseService.getSubConfig(stsInstanceId);
            } catch (SSOException | SMSException e) {
                logger.error("Could not get " + restOrSoap() + " sts state for id " + stsInstanceId + " in realm " + realm + ". Exception: " + e);
                continue;
            }
            if (instanceService != null) {
                Map<String, Set<String>> instanceAttrs = instanceService.getAttributes();
                try {
                    instances.add(instanceConfigMarshaller.fromMapAttributes(instanceAttrs));
                } catch (STSPublishException e) {
                    logger.error("Exception caught in getAllPublishedInstances(String realm) marshalling attributes " + "corresponding to sts " + stsInstanceId + " in realm + " + realm + "; Exception: " + e, e);
                }
            } else {
                logger.error("Could not obtain the " + restOrSoap() + " sts state for instance with id " + stsInstanceId + " in realm " + realm);
            }
        }
    } else {
        logger.error("Could not obtain ServiceConfig instance for realm " + realm + "." + restOrSoap() + " sts instances for this realm cannot be returned from getAllPublishedInstances.");
    }
    return instances;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) SSOException(com.iplanet.sso.SSOException) ServiceConfig(com.sun.identity.sm.ServiceConfig) STSPublishException(org.forgerock.openam.sts.STSPublishException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)163 ServiceConfig (com.sun.identity.sm.ServiceConfig)123 SMSException (com.sun.identity.sm.SMSException)116 SSOException (com.iplanet.sso.SSOException)107 SSOToken (com.iplanet.sso.SSOToken)53 Set (java.util.Set)50 Map (java.util.Map)31 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)28 CLIException (com.sun.identity.cli.CLIException)17 Iterator (java.util.Iterator)16 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)15 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)12 ByteString (org.forgerock.opendj.ldap.ByteString)12 JsonValue (org.forgerock.json.JsonValue)10 IOException (java.io.IOException)9 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)9 IOutput (com.sun.identity.cli.IOutput)8 PolicyException (com.sun.identity.policy.PolicyException)7