Search in sources :

Example 1 with ServiceConfigManager

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

the class DelegationPolicyImpl method initialize.

/**
     * Initialize (or configure) the <code>DelegationInterface</code>
     * object. Usually it will be initialized with the environmrnt
     * parameters set by the system administrator via Service management service.
     *
     * @param token <code>SSOToken</code> of an administrator
     * @param configParams configuration parameters as a <code>Map</code>.
     * The values in the <code>Map</code> is <code>java.util.Set</code>,
     * which contains one or more configuration parameters.
     *
     * @throws DelegationException if an error occurred during
     * initialization of <code>DelegationInterface</code> instance
     */
public void initialize(SSOToken token, Map configParams) throws DelegationException {
    this.appToken = token;
    try {
        maxCacheSize = SystemProperties.getAsInt(CONFIGURED_CACHE_SIZE, DEFAULT_CACHE_SIZE);
        // specifying cache size as 0 would virtually disable the delegation cache.
        if (maxCacheSize < 0) {
            maxCacheSize = DEFAULT_CACHE_SIZE;
        }
        delegationCache = new Cache(maxCacheSize);
        if (DelegationManager.debug.messageEnabled()) {
            DelegationManager.debug.message("DelegationPolicyImpl.initialize(): cache size=" + maxCacheSize);
        }
        pe = new PolicyEvaluator(POLICY_REPOSITORY_REALM, DelegationManager.DELEGATION_SERVICE);
        // listen on delegation policy changes. once there is 
        // delegation policy change, we need to update the cache.
        pe.addPolicyListener(this);
        // listen on root realm subject changes.
        AMIdentityRepository idRepo = new AMIdentityRepository(appToken, "/");
        idRepo.addEventListener(this);
        if (DelegationManager.debug.messageEnabled()) {
            DelegationManager.debug.message("DelegationPolicyImpl: IdRepo event listener added " + "for root realm.");
        }
        // listen on sub realm subject changes.     
        OrganizationConfigManager ocm = new OrganizationConfigManager(appToken, "/");
        Set orgNames = ocm.getSubOrganizationNames("*", true);
        if ((orgNames != null) && (!orgNames.isEmpty())) {
            Iterator it = orgNames.iterator();
            while (it.hasNext()) {
                String org = (String) it.next();
                AMIdentityRepository idr = new AMIdentityRepository(appToken, org);
                idr.addEventListener(this);
                idRepoListeners.put(org, idRepo);
                if (DelegationManager.debug.messageEnabled()) {
                    DelegationManager.debug.message("DelegationPolicyImpl: IdRepo event listener " + "added for realm (" + org + ").");
                }
            }
        }
        scm = new ServiceConfigManager(PolicyConfig.POLICY_CONFIG_SERVICE, token);
        //DelegationManager.DELEGATION_SERVICE, token);
        /**
             *  listen on org config changes. once there is realm added,
             * or removed, we need to add or remove listeners on the
             * affected realm accordingly.
             */
        scm.addListener(this);
    } catch (Exception e) {
        DelegationManager.debug.error("DelegationPolicyImpl: initialize() failed");
        throw new DelegationException(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PolicyEvaluator(com.sun.identity.policy.PolicyEvaluator) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) DelegationException(com.sun.identity.delegation.DelegationException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) DelegationException(com.sun.identity.delegation.DelegationException) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) Cache(com.iplanet.am.util.Cache) SubjectEvaluationCache(com.sun.identity.policy.SubjectEvaluationCache)

Example 2 with ServiceConfigManager

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

the class Gateway method addGWServletUtilsToMap.

private GatewayServletUtils addGWServletUtilsToMap(String orgName, String module) {
    GatewayServletUtils utils = null;
    String authService = AMAuthConfigUtils.getModuleServiceName(module);
    try {
        ServiceConfigManager scm = new ServiceConfigManager(authService, defToken);
        utils = new GatewayServletUtils(scm, module);
        utils.organizationConfigChanged(orgName);
        AuthServiceConfigInfo info = utils.getAuthConfigInfo(orgName);
        if ((info != null) && (info.getPortNumber() != null)) {
            scm.addListener(utils);
            gwServletUtilsMap.put(authService, utils);
        } else {
            gwServletUtilsMap.put(authService, utils = null);
        }
    } catch (Exception e) {
        debug.error("GatewayServlet: " + "Unable to add Auth Service Info : " + authService, e);
    }
    return utils;
}
Also used : ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with ServiceConfigManager

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

the class OpenSSOPolicyDataStore method getOrgConfig.

private ServiceConfig getOrgConfig(SSOToken adminToken, String realm) throws SMSException, SSOException {
    ServiceConfigManager mgr = new ServiceConfigManager(PolicyManager.POLICY_SERVICE_NAME, adminToken);
    ServiceConfig orgConf = mgr.getOrganizationConfig(realm, null);
    if (orgConf == null) {
        mgr.createOrganizationConfig(realm, null);
        orgConf = mgr.getOrganizationConfig(realm, null);
    }
    return orgConf;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 4 with ServiceConfigManager

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

the class DelegationUtils method getPermissionConfig.

/**
     * Returns service config information for a delegation permission.
     * @param  orgName name of the organization whose organization config
     *         is searched.
     * @param  name name of the delegation permission whose information is.
               sought.
     * @param  global <code>boolean</code> indicating if global config
     *         of the delegation service is expected.
     * @return <code>ServiceConfig</code> information for a delegation 
     *         permission
     */
static ServiceConfig getPermissionConfig(String orgName, String name, boolean global) throws SSOException, DelegationException {
    ServiceConfig orgConfig = null;
    ServiceConfig permsConfig = null;
    ServiceConfig perm = null;
    try {
        // get the service configuration manager of the
        // delegation service
        ServiceConfigManager scm = new ServiceConfigManager(DelegationManager.DELEGATION_SERVICE, DelegationManager.getAdminToken());
        // get the organization configuration of this realm
        if (global) {
            orgConfig = scm.getGlobalConfig(null);
        } else {
            orgConfig = scm.getOrganizationConfig(orgName, null);
        }
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_org_config_failed", null, se);
    }
    if (orgConfig == null) {
        throw new DelegationException(ResBundleUtils.rbName, "get_perms_config_failed", null, null);
    }
    try {
        // get the sub configuration "Permissions"
        permsConfig = orgConfig.getSubConfig(DelegationManager.PERMISSIONS);
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_perms_config_failed", null, se);
    }
    try {
        // get the sub configuration for the defined permission
        perm = permsConfig.getSubConfig(name);
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_permission_config_failed", null, se);
    }
    return (perm);
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 5 with ServiceConfigManager

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

the class IdUtils method initialize.

protected static void initialize() {
    if (ServiceManager.isConfigMigratedTo70()) {
        // entities from there
        try {
            SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            serviceConfigManager = new ServiceConfigManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
            ServiceConfig ss = serviceConfigManager.getGlobalConfig(null);
            Set typeSchemaNames = ss.getSubConfigNames("*", IdConstants.SUPPORTED_TYPES);
            if (typeSchemaNames == null || typeSchemaNames.isEmpty()) {
                loadDefaultTypes();
            } else {
                Iterator it = typeSchemaNames.iterator();
                while (it.hasNext()) {
                    String typeSchema = (String) it.next();
                    IdType idType = new IdType(typeSchema);
                    supportedTypes.add(idType);
                    mapSupportedTypes.put(idType.getName(), idType);
                    ServiceConfig tsc = ss.getSubConfig(typeSchema);
                    Map attributes = tsc.getAttributes();
                    Set serviceNameSet = (Set) attributes.get(IdConstants.SERVICE_NAME);
                    Set canBeMembersOf = (Set) attributes.get(IdConstants.ATTR_MEMBER_OF);
                    Set canHaveMembers = (Set) attributes.get(IdConstants.ATTR_HAVE_MEMBERS);
                    Set canAddMembers = (Set) attributes.get(IdConstants.ATTR_ADD_MEMBERS);
                    if (serviceNameSet != null && !serviceNameSet.isEmpty()) {
                        mapTypesToServiceNames.put(typeSchema, (String) serviceNameSet.iterator().next());
                    }
                    if (canBeMembersOf != null && !canBeMembersOf.isEmpty()) {
                        Set memberOfSet = getMemberSet(canBeMembersOf);
                        typesCanBeMemberOf.put(typeSchema, memberOfSet);
                    }
                    if (canHaveMembers != null && !canHaveMembers.isEmpty()) {
                        Set memberSet = getMemberSet(canHaveMembers);
                        typesCanHaveMembers.put(typeSchema, memberSet);
                    }
                    if (canAddMembers != null && !canAddMembers.isEmpty()) {
                        Set memberSet = getMemberSet(canAddMembers);
                        typesCanAddMembers.put(typeSchema, memberSet);
                    }
                }
            }
        } catch (SMSException e) {
            String installTime = SystemProperties.get(Constants.SYS_PROPERTY_INSTALL_TIME, "false");
            if (!installTime.equals("true")) {
                debug.error("IdUtils.initialize: Loading default types.", e);
            }
            loadDefaultTypes();
        } catch (SSOException ssoe) {
            debug.error("dUtils.initialize: Loading default types", ssoe);
            loadDefaultTypes();
        }
    } else {
        loadDefaultTypes();
    }
    // Register for SMS notifications to root realm
    if (notificationId == null) {
        try {
            SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            if (serviceConfigManager == null) {
                serviceConfigManager = new ServiceConfigManager(adminToken, IdConstants.REPO_SERVICE, "1.0");
            }
            notificationId = serviceConfigManager.addListener(new IdUtilsListener());
        } catch (SMSException e) {
            String installTime = SystemProperties.get(Constants.SYS_PROPERTY_INSTALL_TIME, "false");
            if (!installTime.equals("true")) {
                debug.error("IdUtils.initialize: Register notification", e);
            }
        } catch (SSOException ssoe) {
            String installTime = SystemProperties.get(Constants.SYS_PROPERTY_INSTALL_TIME, "false");
            if (!installTime.equals("true")) {
                debug.error("IdUtils.initialize: Register notification", ssoe);
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) 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