Search in sources :

Example 46 with ServiceSchemaManager

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

the class AMServiceUtils method getServiceAttributesWithQualifier.

/**
     * Method to get the attribute names of a service with CosQualifier. For
     * example: Return set could be: <br>
     * ["iplanet-am-web-agent-allow-list merge-schemes",
     * "iplanet-am-web-agent-deny-list merge-schemes"]
     * <p>
     * This method only populates these attributes only for Dynamic attributes.
     */
protected static Set getServiceAttributesWithQualifier(SSOToken token, String serviceName) throws SMSException, SSOException {
    ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
    ServiceSchema ss = null;
    try {
        ss = ssm.getSchema(SchemaType.DYNAMIC);
    } catch (SMSException sme) {
        if (debug.warningEnabled()) {
            debug.warning("AMServiceUtils.getServiceAttributesWithQualifier(): " + "No schema defined for SchemaType.DYNAMIC type");
        }
    }
    if (ss == null) {
        return Collections.EMPTY_SET;
    }
    Set attrNames = new HashSet();
    Set attrSchemaNames = ss.getAttributeSchemaNames();
    Iterator itr = attrSchemaNames.iterator();
    while (itr.hasNext()) {
        String attrSchemaName = (String) itr.next();
        AttributeSchema attrSchema = ss.getAttributeSchema(attrSchemaName);
        String name = attrSchemaName + " " + attrSchema.getCosQualifier();
        attrNames.add(name);
    }
    return attrNames;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 47 with ServiceSchemaManager

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

the class AMStoreConnection method getAttributeNames.

/**
     * Returns the service attribute names for a given service name and schema
     * type.
     * 
     * @param serviceName
     *            the name of the service
     * @param schemaType
     *            the type of service schema
     * @return Set of service attribute names
     * @throws AMException
     *             if an error is encountered while retrieving information.
     * @deprecated use <code>com.sun.identity.sm.ServiceSchemaManager.
     * getServiceAttributeNames(com.sun.identity.sm.SchemaType)</code>
     */
public Set getAttributeNames(String serviceName, AMSchema.Type schemaType) throws AMException {
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        SchemaType st = schemaType.getInternalSchemaType();
        return ssm.getServiceAttributeNames(st);
    } catch (SSOException se) {
        AMCommonUtils.debug.message("AMStoreConnection.getAttributeNames(String, " + "AMSchema.Type)", se);
        throw new AMException(AMSDKBundle.getString("902", locale), "902");
    } catch (SMSException se) {
        AMCommonUtils.debug.message("AMStoreConnection.getAttributeNames(String, " + "AMSchema.Type)", se);
        throw new AMException(AMSDKBundle.getString("911", locale), "911");
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) SchemaType(com.sun.identity.sm.SchemaType)

Example 48 with ServiceSchemaManager

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

the class IdServicesImpl method getServiceAttributesAscending.

/**
    * Non-javadoc, non-public methods
    * Get the service attributes of the name identity. Traverse to the global
    * configuration if necessary until all attributes are found or reached
    * the global area whichever occurs first.
    *
    * @param token is the sso token of the person performing this operation.
    * @param type is the identity type of the name parameter.
    * @param name is the identity we are interested in.
    * @param serviceName is the service we are interested in
    * @param attrNames are the name of the attributes wer are interested in.
    * @param amOrgName is the orgname.
    * @param amsdkDN is the amsdkDN.
    * @throws IdRepoException if there are repository related error conditions.
    * @throws SSOException if user's single sign on token is invalid.
    */
public Map getServiceAttributesAscending(SSOToken token, IdType type, String name, String serviceName, Set attrNames, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
    Map finalResult = new HashMap();
    Set finalAttrName = new HashSet();
    String nextName = name;
    String nextAmOrgName = amOrgName;
    String nextAmsdkDN = amsdkDN;
    IdType nextType = type;
    Set missingAttr = new HashSet(attrNames);
    do {
        // amsdkDN will change as we move up the tree.
        try {
            Map serviceResult = getServiceAttributes(token, nextType, nextName, serviceName, missingAttr, nextAmOrgName, nextAmsdkDN);
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl." + "getServiceAttributesAscending:" + " nextType=" + nextType + "; nextName=" + nextName + "; serviceName=" + serviceName + "; missingAttr=" + missingAttr + "; nextAmOrgName=" + nextAmOrgName + "; nextAmsdkDN=" + nextAmsdkDN);
                DEBUG.message("  getServiceAttributesAscending: " + "serviceResult=" + serviceResult);
                DEBUG.message("  getServiceAttributesAscending: " + " finalResult=" + finalResult);
                DEBUG.message("  getServiceAttributesAscending: " + " finalAttrName=" + finalAttrName);
            }
            if (serviceResult != null) {
                Set srvNameReturned = serviceResult.keySet();
                // save the newly found attrs
                // amsdk returns emptyset when attrname is not present.
                Iterator nameIt = srvNameReturned.iterator();
                while (nameIt.hasNext()) {
                    String attr = (String) nameIt.next();
                    Set attrValue = (Set) serviceResult.get(attr);
                    if (!attrValue.isEmpty()) {
                        finalResult.put(attr, attrValue);
                        finalAttrName.add(attr);
                    }
                }
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("    getServiceAttributesAscending:" + " serviceResult=" + serviceResult);
                    DEBUG.message("    getServiceAttributesAscending:" + " finalResult=" + finalResult);
                }
            }
            if (finalAttrName.containsAll(attrNames)) {
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("exit getServiceAttributesAscending:" + " finalResult=" + finalResult);
                }
                return (finalResult);
            }
            // find the missing attributes
            missingAttr.clear();
            Iterator it = attrNames.iterator();
            while (it.hasNext()) {
                String attrName = (String) it.next();
                if (!finalAttrName.contains(attrName)) {
                    missingAttr.add(attrName);
                }
            }
        } catch (IdRepoException idrepo) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "idrepoerr", idrepo);
            }
        } catch (SSOException ssoex) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "ssoex", ssoex);
            }
        }
        //  go up to the parent org
        try {
            if (nextType.equals(IdType.USER) || nextType.equals(IdType.AGENT)) {
                // try the user or agent's correct realm.
                nextAmsdkDN = nextAmOrgName;
                nextType = IdType.REALM;
            } else {
                OrganizationConfigManager ocm = new OrganizationConfigManager(token, nextAmOrgName);
                OrganizationConfigManager parentOCM = ocm.getParentOrgConfigManager();
                String parentName = parentOCM.getOrganizationName();
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("  getServiceAttributesAscending: " + "parentName=" + parentName);
                }
                nextType = IdType.REALM;
                if (nextAmOrgName.equalsIgnoreCase(parentName)) {
                    // at root.
                    nextName = null;
                } else {
                    nextAmOrgName = parentName;
                }
                nextAmOrgName = parentName;
                nextAmsdkDN = parentName;
            }
        } catch (SMSException smse) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "smserror", smse);
            }
            nextName = null;
        }
    } while (nextName != null);
    // get the rest from global.
    if (!missingAttr.isEmpty()) {
        try {
            ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
            ServiceSchema schema = ssm.getDynamicSchema();
            Map gAttrs = schema.getAttributeDefaults();
            Iterator missingIt = missingAttr.iterator();
            while (missingIt.hasNext()) {
                String missingAttrName = (String) missingIt.next();
                finalResult.put(missingAttrName, gAttrs.get(missingAttrName));
            }
        } catch (SMSException smse) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl(): getServiceAttributeAscending " + " Failed to get global default.", smse);
            }
        }
    }
    if (DEBUG.messageEnabled()) {
        DEBUG.message("exit end  getServiceAttributesAscending: " + " finalResult=" + finalResult);
    }
    return finalResult;
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) ServiceSchema(com.sun.identity.sm.ServiceSchema) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 49 with ServiceSchemaManager

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

the class IdRepoPluginsCache method initializeListeners.

protected void initializeListeners() {
    synchronized (debug) {
        if (!initializedListeners) {
            // Add listeners to Service Schema and Config Managers
            if (debug.messageEnabled()) {
                debug.message("IdRepoPluginsCache.initializeListeners: " + "setting up ServiceListener");
            }
            SSOToken token = getAdminToken();
            try {
                // Initialize configuration objects
                idRepoServiceConfigManager = new ServiceConfigManager(token, IdConstants.REPO_SERVICE, "1.0");
                idRepoServiceConfigManager.addListener(this);
                // Initialize schema objects
                ServiceSchemaManager idRepoServiceSchemaManager = new ServiceSchemaManager(token, IdConstants.REPO_SERVICE, "1.0");
                idRepoServiceSchemaManager.addListener(this);
                // Get the version number
                svcRevisionNumber = idRepoServiceSchemaManager.getRevisionNumber();
                // Initialize listener for JAXRPCObject
                IdRepoListener.addRemoteListener(new JAXRPCObjectImplEventListener());
                initializedListeners = true;
            } catch (SMSException smse) {
                // Exceptions will be throws during install and config
                // when these services will not be loaded
                String installTime = SystemProperties.get(Constants.SYS_PROPERTY_INSTALL_TIME, "false");
                if (!installTime.equals("true")) {
                    debug.error("IdRepoPluginsCache.initializeListeners: " + "Unable to set up a service listener for IdRepo", smse);
                }
            } catch (SSOException ssoe) {
                debug.error("IdRepoPluginsCache.initializeListeners: " + "Unable to set up a service listener for IdRepo.", ssoe);
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 50 with ServiceSchemaManager

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

the class ServiceTypeManager method getServiceType.

/**
     * Returns a <code>ServiceType</code> object for the given
     * service name. If the service does not exist, the exception
     * <code>NameNotFoundException</code> is thrown.
     *
     * @param serviceTypeName name of the service
     *
     * @return <code>ServiceType</code> object for the given service name
     *
     * @exception SSOException single-sign-on token has either expired
     * or is invalid
     * @exception NameNotFoundException service for the given <code>
     * serviceTypeName</code> does not exist
     */
public ServiceType getServiceType(String serviceTypeName) throws SSOException, NameNotFoundException {
    ServiceType st = (ServiceType) serviceTypes.get(serviceTypeName);
    if (st == null) {
        try {
            ServiceSchema policySchema = null;
            ServiceSchemaManager ssm = new ServiceSchemaManager(serviceTypeName, token);
            if ((ssm == null) || ((policySchema = ssm.getPolicySchema()) == null)) {
                if (PolicyManager.debug.messageEnabled()) {
                    PolicyManager.debug.message("ServiceTypeManager::getServiceType " + serviceTypeName + " not found with policy privileges");
                }
                String[] objs = { serviceTypeName };
                throw (new NameNotFoundException(ResBundleUtils.rbName, "service_name_not_found", objs, serviceTypeName, PolicyException.SERVICE));
            }
            st = new ServiceType(serviceTypeName, ssm, policySchema);
            serviceTypes.put(serviceTypeName, st);
        } catch (SMSException se) {
            PolicyManager.debug.error("In ServiceTypeManager::getServiceType " + serviceTypeName + " got SMS exception: ", se);
            throw (new NameNotFoundException(se, serviceTypeName, PolicyException.SERVICE));
        }
    }
    return st;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Aggregations

ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)209 SMSException (com.sun.identity.sm.SMSException)146 ServiceSchema (com.sun.identity.sm.ServiceSchema)131 SSOException (com.iplanet.sso.SSOException)119 Set (java.util.Set)87 HashSet (java.util.HashSet)60 Map (java.util.Map)56 HashMap (java.util.HashMap)49 AttributeSchema (com.sun.identity.sm.AttributeSchema)46 SSOToken (com.iplanet.sso.SSOToken)43 Iterator (java.util.Iterator)40 CLIException (com.sun.identity.cli.CLIException)33 BeforeTest (org.testng.annotations.BeforeTest)27 AfterTest (org.testng.annotations.AfterTest)26 Test (org.testng.annotations.Test)26 CLIRequest (com.sun.identity.cli.CLIRequest)25 Parameters (org.testng.annotations.Parameters)18 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)15 TreeSet (java.util.TreeSet)12 ByteString (org.forgerock.opendj.ldap.ByteString)11