Search in sources :

Example 26 with ServiceManager

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

the class SCConfigModelImpl method getServiceNames.

private void getServiceNames() {
    try {
        ServiceManager sm = new ServiceManager(getUserSSOToken());
        Set serviceNames = sm.getServiceNames();
        Set authServices = AMAuthenticationManager.getAuthenticationServiceNames();
        if (serviceNames != null) {
            for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
                String svcName = (String) i.next();
                String sectionName = null;
                try {
                    sectionName = rbServiceTable.getString(svcName);
                } catch (MissingResourceException e) {
                    /*
                        * we want all authentication services to be displayed
                        * in the authentication section. The rest of the 
                        * unknown services can be put into the global section.
                        */
                    if (authServices.contains(svcName)) {
                        sectionName = SEC_AUTH;
                    } else {
                        sectionName = SEC_GLOBAL;
                    }
                }
                // hide section name with "."
                if (!sectionName.equals(".")) {
                    List list = (List) mapSectionNameToServiceNames.get(sectionName);
                    if (list == null) {
                        list = new ArrayList(20);
                        mapSectionNameToServiceNames.put(sectionName, list);
                    }
                    list.add(svcName);
                }
            }
        }
    } catch (SSOException ssoe) {
        debug.error("SCConfigModelImpl.getServiceNames", ssoe);
    } catch (SMSException smse) {
        debug.error("SCConfigModelImpl.getServiceNames", smse);
    }
}
Also used : Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) MissingResourceException(java.util.MissingResourceException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 27 with ServiceManager

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

the class SmsRequestHandler method createServices.

/**
     * Creates a {@link Router} for all the registered services, and then assigns that router to the instance so that
     * it will be used for all future requests.
     * @throws SMSException From downstream service manager layer.
     * @throws SSOException From downstream service manager layer.
     */
private synchronized void createServices() throws SSOException, SMSException {
    Map<String, Map<SmsRouteTree, Set<RouteMatcher<Request>>>> serviceRoutes = new HashMap<>();
    ServiceManager sm = getServiceManager();
    Set<String> serviceNames = sm.getServiceNames();
    for (String serviceName : serviceNames) {
        Map<SmsRouteTree, Set<RouteMatcher<Request>>> routes = addService(sm, serviceName, DEFAULT_VERSION);
        if (routes != null) {
            serviceRoutes.put(serviceName, routes);
        }
    }
    if (schemaType == SchemaType.GLOBAL) {
        addServersRoutes(sm, serviceRoutes);
    }
    this.serviceRoutes = serviceRoutes;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashMap(java.util.HashMap) ServiceManager(com.sun.identity.sm.ServiceManager) RouteMatcher(org.forgerock.services.routing.RouteMatcher) SmsRouteTree(org.forgerock.openam.core.rest.sms.SmsRouteTree) CreateRequest(org.forgerock.json.resource.CreateRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) QueryRequest(org.forgerock.json.resource.QueryRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) Request(org.forgerock.json.resource.Request) PatchRequest(org.forgerock.json.resource.PatchRequest) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 28 with ServiceManager

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

the class AMStoreConnection method getServiceHierarchy.

/**
     * Returns the service hierarchy for all registered services.
     * 
     * @return the service hierarchy for all registered services.
     * @throws AMException
     *             if an error is encountered in retrieving the service
     *             hierarchy. The return value is a Set of strings in slash
     *             format.
     */
public Set getServiceHierarchy() throws AMException {
    try {
        Set retSet = new HashSet();
        ServiceManager sm = new ServiceManager(token);
        Set serviceNames = sm.getServiceNames();
        Iterator itr = serviceNames.iterator();
        while (itr.hasNext()) {
            String st = (String) itr.next();
            ServiceSchemaManager scm = new ServiceSchemaManager(st, token);
            String sh = scm.getServiceHierarchy();
            if ((sh != null) && (sh.length() != 0)) {
                retSet.add(sh);
            }
        }
        return retSet;
    } catch (SSOException so) {
        AMCommonUtils.debug.error("AMStoreConnection.getServiceNames(): ", so);
        throw new AMException(AMSDKBundle.getString("902", locale), "902");
    } catch (SMSException se) {
        AMCommonUtils.debug.error("AMStoreConnection.getServiceNames(): ", se);
        throw new AMException(AMSDKBundle.getString("905", locale), "905");
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 29 with ServiceManager

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

the class ImportServiceConfiguration method deleteOuServicesDescendents.

private void deleteOuServicesDescendents(SSOToken ssoToken, String ouServices) throws SSOException, SMSException {
    CachedSubEntries smsEntry = CachedSubEntries.getInstance(ssoToken, ouServices);
    Set children = smsEntry.searchSubOrgNames(ssoToken, "*", false);
    for (Iterator i = children.iterator(); i.hasNext(); ) {
        String child = (String) i.next();
        child = "o=" + child + "," + ouServices;
        SMSEntry s = new SMSEntry(ssoToken, child);
        s.delete();
    }
    {
        // hardcoding hidden realm, cannot find a better option.
        SMSEntry s = new SMSEntry(ssoToken, "o=sunamhiddenrealmdelegationservicepermissions," + ouServices);
        s.delete();
    }
    children = smsEntry.getSubEntries(ssoToken, "*");
    for (Iterator i = children.iterator(); i.hasNext(); ) {
        String child = (String) i.next();
        child = "ou=" + child + "," + ouServices;
        SMSEntry s = new SMSEntry(ssoToken, child);
        s.delete();
    }
    ServiceManager mgr = new ServiceManager(ssoToken);
    mgr.clearCache();
    AMIdentityRepository.clearCache();
}
Also used : CachedSubEntries(com.sun.identity.sm.CachedSubEntries) Set(java.util.Set) ServiceManager(com.sun.identity.sm.ServiceManager) Iterator(java.util.Iterator) SMSEntry(com.sun.identity.sm.SMSEntry)

Example 30 with ServiceManager

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

the class ImportServiceConfiguration method importData.

private void importData(String xmlFile, String encryptSecret, SSOToken ssoToken) throws CLIException, SSOException, SMSException, IOException {
    // set the correct password encryption key.
    // without doing so, the default encryption key will be used.
    String encKey = getEncKey(xmlFile);
    if (encKey != null) {
        SystemProperties.initializeProperties(Constants.ENC_PWD_PROPERTY, encKey);
        Crypt.reinitialize();
    }
    IOutput outputWriter = getOutputWriter();
    FileInputStream fis = null;
    try {
        AMEncryption encryptObj = new JCEEncryption();
        ((ConfigurableKey) encryptObj).setPassword(encryptSecret);
        ServiceManager ssm = new ServiceManager(ssoToken);
        fis = new FileInputStream(xmlFile);
        ssm.registerServices(fis, encryptObj);
        InitializeSystem initSys = CommandManager.initSys;
        String instanceName = initSys.getInstanceName();
        String serverConfigXML = initSys.getServerConfigXML();
        ServerConfiguration.setServerConfigXML(ssoToken, instanceName, serverConfigXML);
        outputWriter.printlnMessage(getResourceString("import-service-configuration-succeeded"));
    } catch (IOException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (Exception e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ie) {
            //ignore if file input stream cannot be closed.
            }
        }
    }
}
Also used : AMEncryption(com.iplanet.services.util.AMEncryption) JCEEncryption(com.iplanet.services.util.JCEEncryption) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) ConfigurableKey(com.iplanet.services.util.ConfigurableKey) FileInputStream(java.io.FileInputStream) LoginException(javax.security.auth.login.LoginException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) InitializeSystem(com.sun.identity.cli.InitializeSystem) IOutput(com.sun.identity.cli.IOutput) ServiceManager(com.sun.identity.sm.ServiceManager) CLIException(com.sun.identity.cli.CLIException)

Aggregations

ServiceManager (com.sun.identity.sm.ServiceManager)34 SMSException (com.sun.identity.sm.SMSException)20 SSOException (com.iplanet.sso.SSOException)17 SSOToken (com.iplanet.sso.SSOToken)11 IOException (java.io.IOException)10 CLIException (com.sun.identity.cli.CLIException)7 Iterator (java.util.Iterator)7 Set (java.util.Set)7 IOutput (com.sun.identity.cli.IOutput)6 FileInputStream (java.io.FileInputStream)6 HashSet (java.util.HashSet)6 ByteString (org.forgerock.opendj.ldap.ByteString)5 AMEncryption (com.iplanet.services.util.AMEncryption)4 ConfigurableKey (com.iplanet.services.util.ConfigurableKey)4 JCEEncryption (com.iplanet.services.util.JCEEncryption)4 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 List (java.util.List)4 AMException (com.iplanet.am.sdk.AMException)3