Search in sources :

Example 61 with ServiceConfigManager

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

the class AuthUtils method getZeroPageLoginConfig.

/**
     * Gets the ZPL configuration for the given realm.
     *
     * @param realm the realm to get the ZPL configuration for. Not null.
     * @return the ZPL configuration object. Never null.
     * @throws SSOException if there is a problem authenticating the configuration lookup.
     * @throws SMSException if there is a problem fetching the configuration data.
     */
public static ZeroPageLoginConfig getZeroPageLoginConfig(final String realm) throws SSOException, SMSException {
    Reject.ifNull(realm);
    final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
    final ServiceConfigManager mgr = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, token);
    final ServiceConfig serviceConfig = mgr.getOrganizationConfig(realm, null);
    @SuppressWarnings("unchecked") final Map<String, Set<String>> configMap = serviceConfig.getAttributes();
    return new ZeroPageLoginConfig(CollectionHelper.getBooleanMapAttr(configMap, Constants.ZERO_PAGE_LOGIN_ENABLED, false), configMap.get(Constants.ZERO_PAGE_LOGIN_WHITELIST), CollectionHelper.getBooleanMapAttr(configMap, Constants.ZERO_PAGE_LOGIN_ALLOW_MISSING_REFERER, true));
}
Also used : ZeroPageLoginConfig(com.sun.identity.authentication.client.ZeroPageLoginConfig) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 62 with ServiceConfigManager

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

the class AllowedModulesChoiceValues method getChoiceValues.

/**
     * Returns choice values from  environment parameters
     * @param envParams map of environment parameters
     * @return choice values from  environment parameters
     */
public Map getChoiceValues(Map envParams) {
    // Get default choice values
    getChoiceValues();
    Set serviceNames = null;
    String orgDN = null;
    Map registeredServices = new HashMap();
    if (envParams != null) {
        orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
    }
    if (orgDN == null || orgDN.length() == 0) {
        orgDN = SMSEntry.getRootSuffix();
    }
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        OrganizationConfigManager orgConfig = getOrgConfigManager(orgDN, adminToken);
        serviceNames = orgConfig.getAssignedServices();
    } catch (Exception e) {
    // this Exception should have been (or will be) caught by the
    // caller of of this plugin(console). it does not worth to
    // duplicate log/debug here.
    }
    if (serviceNames != null) {
        for (Iterator ite = choiceValues.keySet().iterator(); ite.hasNext(); ) {
            String value = (String) ite.next();
            if (serviceRegistered(value, serviceNames)) {
                registeredServices.put(value, value);
            } else {
                String serviceName = AuthUtils.getModuleServiceName(value);
                try {
                    new ServiceConfigManager(serviceName, adminToken);
                } catch (SMSException e) {
                    // services don't have template.
                    registeredServices.put(value, value);
                } catch (Exception e) {
                // SSO, do nothing
                }
            }
        }
    }
    return registeredServices;
}
Also used : Set(java.util.Set) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) SMSException(com.sun.identity.sm.SMSException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 63 with ServiceConfigManager

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

the class CommonUtils method populateManagedObjects.

protected static boolean populateManagedObjects() {
    try {
        ServiceConfigManager scm = new ServiceConfigManager("DAI", getInternalToken());
        ServiceConfig gc = scm.getGlobalConfig(null);
        Set managedObjects = gc.getSubConfigNames("*", "ManagedObjects");
        if (managedObjects == null || managedObjects.isEmpty()) {
            debug.message("CommonUtils.populateManagedObject " + "managedObjects=null");
            return false;
        // populateManagedObjectsWithDefaults();
        }
        Iterator mIter = managedObjects.iterator();
        while (mIter.hasNext()) {
            String mo = (String) mIter.next();
            mo = mo.toLowerCase();
            ServiceConfig sc = gc.getSubConfig(mo);
            if (sc != null) {
                Map attrs = sc.getAttributes();
                Set ocSet = (Set) attrs.get("objectclass");
                Set ctSet = (Set) attrs.get("creationtemplatename");
                Set stSet = (Set) attrs.get("searchtemplatename");
                Set typeSet = (Set) attrs.get("type");
                Set stAttr = (Set) attrs.get("statusattribute");
                String oc = getObjectClass(ocSet, mo);
                String ct = getCreationTemplateName(ctSet, mo);
                String st = getSearchTemplateName(stSet, mo);
                String stAttrName = getStatusAttributeName(stAttr);
                // Assumes a type is always defined in the config.
                // TODO be careful with NPE here.
                String typeS = (String) typeSet.iterator().next();
                // int type = Integer.parseInt(typeS);
                supportedTypes.put(mo, typeS);
                supportedNames.put(typeS, mo);
                if (oc != null) {
                    ObjectClassManager.objectClassMap.put(typeS, oc);
                    ObjectClassManager.objectTypeMap.put(oc, typeS);
                }
                if (st != null)
                    searchtemplateMap.put(typeS, st);
                if (ct != null)
                    creationtemplateMap.put(typeS, ct);
                if (stAttrName != null)
                    statusAttributeMap.put(typeS, stAttrName);
            }
        }
        if (debug.messageEnabled()) {
            debug.message("CreationTemplate MAP = " + creationtemplateMap.toString());
            debug.message("SearchTemplate Map = " + searchtemplateMap.toString());
            debug.message("ObjectClass-Type Map = " + ObjectClassManager.objectClassMap.toString());
            debug.message("Type-ObjectClass MAP = " + ObjectClassManager.objectTypeMap.toString());
            debug.message("Supported names-type = " + supportedTypes.toString());
            debug.message("Status Attributes= " + statusAttributeMap.toString());
        }
    } catch (SMSException se) {
        return false;
    // populateManagedObjectsWithDefaults();
    } catch (SSOException ssoe) {
        return false;
    // populateManagedObjectsWithDefaults();
    }
    return true;
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 64 with ServiceConfigManager

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

the class DeleteDataStores method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List names = (List) rc.getOption(DatastoreOptions.DATASTORE_NAMES);
    validateRealm(realm);
    String[] params = { realm, names.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_DATASTORES", params);
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        if (cfg != null) {
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                cfg.removeSubConfig((String) i.next());
            }
            if (names.size() > 1) {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastores-succeeded"));
            } else {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-succeeded"));
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-not-found"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_DATASTORES", params);
    } catch (SMSException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 65 with ServiceConfigManager

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

the class ListDataStores method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    validateRealm(realm);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_DATASTORES", params);
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        Set names = (cfg != null) ? cfg.getSubConfigNames() : Collections.EMPTY_SET;
        if ((names != null) && !names.isEmpty()) {
            getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-succeeded"));
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                String name = (String) i.next();
                getOutputWriter().printlnMessage(name);
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-no-entries"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_LIST_DATASTORES", params);
    } catch (SMSException e) {
        debugError("ListDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("ListDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) 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