Search in sources :

Example 21 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 22 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 23 with ServiceManager

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

the class IdUtils method getOrganization.

/**
     * Returns an organization which maps to the identifier used by application
     * 
     * @param orgIdentifier  Organization identifier
     * @return Organization mapping to that identifier.
     */
public static String getOrganization(SSOToken token, String orgIdentifier) throws IdRepoException, SSOException {
    // Check in cache first
    String id = null;
    if ((id = (String) orgIdentifierToOrgName.get(orgIdentifier)) != null) {
        return (id);
    }
    // Compute the organization name
    if (debug.messageEnabled()) {
        debug.message("IdUtils:getOrganization Input orgname: " + orgIdentifier);
    }
    if (orgIdentifier == null || orgIdentifier.length() == 0 || orgIdentifier.equals("/")) {
        // Return base DN
        id = DNMapper.orgNameToDN("/");
    } else if (orgIdentifier.startsWith("/")) {
        // If orgIdentifier is in "/" format covert to DN and return
        id = DNMapper.orgNameToDN(orgIdentifier);
        try {
            new OrganizationConfigManager(token, orgIdentifier);
        } catch (SMSException e) {
            debug.message("IdUtils.getOrganization Exception in getting org name from SMS", e);
            Object[] args = { orgIdentifier };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
        }
    } else if (LDAPUtils.isDN(orgIdentifier)) {
        id = orgIdentifier;
        try {
            // Search for realms with orgIdentifier name
            OrganizationConfigManager ocm = new OrganizationConfigManager(token, orgIdentifier);
        } catch (SMSException smse) {
            // debug message here.
            if (debug.messageEnabled()) {
                debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
            }
            Object[] args = { orgIdentifier };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
        }
    } else if (ServiceManager.isCoexistenceMode()) {
        // Return the org DN as determined by AMStoreConnection
        if (debug.messageEnabled()) {
            debug.message("IdUtils.getOrganization: getting from AMSDK");
        }
        try {
            AMStoreConnection amsc = new AMStoreConnection(token);
            id = amsc.getOrganizationDN(orgIdentifier, null);
        } catch (AMException ame) {
            if (debug.messageEnabled()) {
                debug.message("IdUtils.getOrganization Exception in " + "getting org name from AMSDK", ame);
            }
            throw convertAMException(ame);
        }
    } else {
        // Get the realm name from SMS
        if (debug.messageEnabled()) {
            debug.message("IdUtils.getOrganization: getting from " + "SMS realms");
        }
        try {
            boolean foundOrg = false;
            ServiceManager sm = new ServiceManager(token);
            // First search for realms with orgIdentifier name
            OrganizationConfigManager ocm = sm.getOrganizationConfigManager("/");
            Set subOrgNames = ocm.getSubOrganizationNames(orgIdentifier, true);
            if (subOrgNames != null && !subOrgNames.isEmpty()) {
                if (subOrgNames.size() == 1) {
                    id = DNMapper.orgNameToDN((String) subOrgNames.iterator().next());
                    foundOrg = true;
                } else {
                    for (Iterator items = subOrgNames.iterator(); items.hasNext(); ) {
                        // check for orgIdentifier
                        String subRealmName = (String) items.next();
                        StringTokenizer st = new StringTokenizer(subRealmName, "/");
                        // allowed
                        while (st.hasMoreTokens()) {
                            if (st.nextToken().equalsIgnoreCase(orgIdentifier)) {
                                if (!foundOrg) {
                                    id = DNMapper.orgNameToDN(subRealmName);
                                    foundOrg = true;
                                } else {
                                    Object[] args = { orgIdentifier };
                                    throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
                                }
                            }
                        }
                    }
                }
            }
            // Check if organization name has been determined
            if (debug.messageEnabled()) {
                debug.message("IdUtils.getOrganization: getting from " + "SMS realms aliases");
            }
            // perform organization alias search
            Set vals = new HashSet();
            vals.add(orgIdentifier);
            Set orgAliases = sm.searchOrganizationNames(IdConstants.REPO_SERVICE, IdConstants.ORGANIZATION_ALIAS_ATTR, vals);
            if (!foundOrg && ((orgAliases == null) || orgAliases.isEmpty())) {
                if (debug.warningEnabled()) {
                    debug.warning("IdUtils.getOrganization Unable" + " to find Org name for: " + orgIdentifier);
                }
                Object[] args = { orgIdentifier };
                throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
            } else if ((orgAliases != null) && (orgAliases.size() > 0) && (foundOrg || orgAliases.size() > 1)) {
                // Multiple realms should not have the same alias
                if (debug.warningEnabled()) {
                    debug.warning("IdUtils.getOrganization Multiple " + " matching Orgs found for: " + orgIdentifier);
                }
                Object[] args = { orgIdentifier };
                throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
            }
            if (!foundOrg) {
                String tmpS = (String) orgAliases.iterator().next();
                id = DNMapper.orgNameToDN(tmpS);
            }
        } catch (SMSException smse) {
            // debug message here.
            if (debug.messageEnabled()) {
                debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
            }
            Object[] args = { orgIdentifier };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
        }
    }
    if (debug.messageEnabled()) {
        debug.message("IdUtils:getOrganization Search for OrgIdentifier:" + orgIdentifier + " returning realm DN: " + id);
    }
    // Add to cache and return id
    orgIdentifierToOrgName.put(orgIdentifier, id);
    return id;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) AMException(com.iplanet.am.sdk.AMException) StringTokenizer(java.util.StringTokenizer) AMStoreConnection(com.iplanet.am.sdk.AMStoreConnection) ServiceManager(com.sun.identity.sm.ServiceManager) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) AMObject(com.iplanet.am.sdk.AMObject) HashSet(java.util.HashSet)

Example 24 with ServiceManager

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

the class ServiceTypeManager method getServiceTypeNames.

/**
     * Returns a set of service names that have policy privileges.
     *
     * @return set of service type names that have policy privileges
     *
     * @exception SSOException single-sign-on token has either expired
     * or is invalid
     * @exception NoPermissionException user does not have privileges
     * to access service names
     */
public Set getServiceTypeNames() throws SSOException, NoPermissionException {
    SSOTokenManager.getInstance().validateToken(token);
    try {
        ServiceManager sm = new ServiceManager(token);
        Iterator items = sm.getServiceNames().iterator();
        // Check if the service names have policy schema
        HashSet answer = new HashSet();
        while (items.hasNext()) {
            String serviceName = (String) items.next();
            try {
                ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
                if (ssm.getPolicySchema() != null)
                    answer.add(serviceName);
            } catch (Exception e) {
                PolicyManager.debug.error("ServiceTypeManager.getServiceTypeNames:", e);
            }
        }
        return (answer);
    } catch (SMSException se) {
        throw (new NoPermissionException(se));
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 25 with ServiceManager

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

the class UserIdRepo method registerService.

private void registerService(String xml, SSOToken adminSSOToken) throws SSOException, SMSException, IOException {
    ServiceManager serviceManager = new ServiceManager(adminSSOToken);
    InputStream serviceStream = null;
    try {
        serviceStream = (InputStream) new ByteArrayInputStream(xml.getBytes());
        serviceManager.registerServices(serviceStream);
    } finally {
        if (serviceStream != null) {
            serviceStream.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceManager(com.sun.identity.sm.ServiceManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

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