Search in sources :

Example 86 with ServiceConfig

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

the class SpecialRepo method isSpecialUser.

private boolean isSpecialUser(IdType type, String name) throws SSOException {
    boolean isSpecUser = false;
    if (type.equals(IdType.USER)) {
        if ((specialUsers == null) || specialUsers.isEmpty()) {
            try {
                ServiceConfig userConfig = getUserConfig();
                Set userSet = new CaseInsensitiveHashSet();
                userSet.addAll(userConfig.getSubConfigNames());
                specialUsers = userSet;
            } catch (SMSException smse) {
                isSpecUser = false;
            }
        }
        if ((specialUsers != null) && specialUsers.contains(name)) {
            isSpecUser = true;
        }
    }
    return isSpecUser;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException)

Example 87 with ServiceConfig

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

the class SpecialRepo method delete.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#delete(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String)
     */
public void delete(SSOToken token, IdType type, String name) throws IdRepoException, SSOException {
    if (isSpecialUser(type, name)) {
        // Need to support delete for anonymous only
        if (name.equalsIgnoreCase(IdConstants.ANONYMOUS_USER)) {
            try {
                // Obtain userconfig and delete anonymous user
                ServiceConfig sc = getUserConfig();
                sc.removeSubConfig(name);
            } catch (SMSException smse) {
                debug.error("SpecialRepo: Unable to delete anonymous user ", smse);
                Object[] args = { NAME };
                throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_READ_ATTRIBUTES, args);
            }
        }
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException)

Example 88 with ServiceConfig

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

the class ResourceManager method removeRuleFromResourceTree.

private void removeRuleFromResourceTree(String policyName, String resourceName, String serviceTypeName, ServiceType st) throws PolicyException, SSOException {
    if (resourceName == null || resourceName.length() == 0) {
        resourceName = EMPTY_RESOURCE_NAME;
    }
    ServiceConfig resources = getResourcesServiceConfig(false);
    if (resources == null) {
        return;
    }
    ServiceConfig leafConfig = null;
    try {
        leafConfig = resources.getSubConfig(serviceTypeName);
    } catch (SMSException e1) {
        throw new PolicyException(e1);
    }
    if (leafConfig == null) {
        // no resource node for this service type
        return;
    }
    // else, see if the attribute is there and non-empty
    Map existingAttrs = null;
    existingAttrs = leafConfig.getAttributes();
    if ((existingAttrs == null) || (!existingAttrs.containsKey(RESOURCES_XML))) {
        return;
    }
    // else, need to look into the attribute
    int n = existingAttrs.size();
    Set existingRes = (Set) existingAttrs.get(RESOURCES_XML);
    if (existingRes.isEmpty()) {
        return;
    }
    // else, the attribute really contains something
    Object[] retVal = getXMLRootNode(existingRes);
    Node rootNode = (Node) retVal[0];
    boolean modified = matchAndRemoveReferenceNode(rootNode, resourceName, policyName, st, new Stack());
    if (!modified) {
        return;
    }
    if (!rootNode.hasChildNodes()) {
        try {
            leafConfig.removeAttribute(RESOURCES_XML);
            if (n == 1) {
                resources.removeSubConfig(serviceTypeName);
            }
            return;
        } catch (SMSException e3) {
            throw new PolicyException(e3);
        }
    }
    // finally reset the modified xml content
    String modifiedResourcesXml = SMSSchema.nodeToString(rootNode);
    Map modifiedAttrs = new HashMap();
    Set modifiedSet = new HashSet();
    modifiedSet.add(modifiedResourcesXml);
    modifiedAttrs.put(RESOURCES_XML, modifiedSet);
    try {
        leafConfig.setAttributes(modifiedAttrs);
    } catch (SMSException e4) {
        throw new PolicyException(e4);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Stack(java.util.Stack) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 89 with ServiceConfig

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

the class ResourceManager method saveResourceIndex.

/**
     * Saves the resource index to data store
     * @param resourceType resource type
     * @param indexXML xml representation of index ( index to 
     *        policies keyed by resource name, in a tree structure)
     * @throws PolicyException
     * @throws SSOException
     */
void saveResourceIndex(String resourceType, String indexXML) throws PolicyException, SSOException {
    Map newAttrs = new HashMap();
    Set newSet = new HashSet();
    newSet.add(indexXML);
    newAttrs.put(RESOURCES_XML, newSet);
    ServiceConfig resources = getResourcesServiceConfig(true);
    if (resources != null) {
        ServiceConfig leafConfig = null;
        try {
            leafConfig = resources.getSubConfig(resourceType);
            if (leafConfig == null) {
                // no resource node for this service type
                resources.addSubConfig(resourceType, PolicyManager.RESOURCES_POLICY_ID, 0, newAttrs);
            } else {
                leafConfig.setAttributes(newAttrs);
            }
        } catch (SMSException e1) {
            throw new PolicyException(e1);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 90 with ServiceConfig

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

the class ResourceManager method addRuleToResourceTree.

private void addRuleToResourceTree(String policyName, Rule rule) throws PolicyException, SSOException {
    // to do: investigate this
    String resourceName = rule.getResourceName();
    String serviceTypeName = rule.getServiceTypeName();
    ServiceType st = rule.getServiceType();
    if (resourceName == null || resourceName.length() == 0) {
        resourceName = EMPTY_RESOURCE_NAME;
    }
    ServiceConfig resources = getResourcesServiceConfig(true);
    if (resources == null) {
        return;
    }
    ServiceConfig leafConfig = null;
    try {
        leafConfig = resources.getSubConfig(serviceTypeName);
    } catch (SMSException e1) {
        throw new PolicyException(e1);
    }
    if (leafConfig == null) {
        // no resource node for this service type
        try {
            String newResourcesXml = rule.toResourcesXml(policyName);
            Map newAttrs = new HashMap();
            Set newSet = new HashSet();
            newSet.add(newResourcesXml);
            newAttrs.put(RESOURCES_XML, newSet);
            resources.addSubConfig(serviceTypeName, PolicyManager.RESOURCES_POLICY_ID, 0, newAttrs);
        } catch (SMSException e2) {
            throw new PolicyException(e2);
        }
        return;
    }
    // else, see if the attribute is there and non-empty
    Map existingAttrs = null;
    existingAttrs = leafConfig.getAttributes();
    if ((existingAttrs == null) || (!existingAttrs.containsKey(RESOURCES_XML))) {
        try {
            String newResourcesXml = rule.toResourcesXml(policyName);
            Set newSet = new HashSet();
            newSet.add(newResourcesXml);
            leafConfig.addAttribute(RESOURCES_XML, newSet);
        } catch (SMSException e4) {
            throw new PolicyException(e4);
        }
        return;
    }
    // else, need to look into the attribute
    Set existingRes = (Set) existingAttrs.get(RESOURCES_XML);
    if (existingRes.isEmpty()) {
        try {
            String newResourcesXml = rule.toResourcesXml(policyName);
            Map newAttrs = new HashMap();
            Set newSet = new HashSet();
            newSet.add(newResourcesXml);
            newAttrs.put(RESOURCES_XML, newSet);
            leafConfig.setAttributes(newAttrs);
        } catch (SMSException e5) {
            throw new PolicyException(e5);
        }
        return;
    }
    // else, the attribute really contains something
    Object[] retVal = getXMLRootNode(existingRes);
    Node rootNode = (Node) retVal[0];
    Document doc = (Document) retVal[1];
    boolean modified = matchAndAddReferenceNode(doc, rootNode, resourceName, policyName, st);
    if (!modified) {
        return;
    }
    // finally reset the modified xml content
    String modifiedResourcesXml = SMSSchema.nodeToString(rootNode);
    Map modifiedAttrs = new HashMap();
    Set modifiedSet = new HashSet();
    modifiedSet.add(modifiedResourcesXml);
    modifiedAttrs.put(RESOURCES_XML, modifiedSet);
    try {
        leafConfig.setAttributes(modifiedAttrs);
    } catch (SMSException e6) {
        throw new PolicyException(e6);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ServiceConfig (com.sun.identity.sm.ServiceConfig)285 SMSException (com.sun.identity.sm.SMSException)180 Set (java.util.Set)144 SSOException (com.iplanet.sso.SSOException)143 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)124 HashSet (java.util.HashSet)119 Map (java.util.Map)101 HashMap (java.util.HashMap)96 SSOToken (com.iplanet.sso.SSOToken)52 Iterator (java.util.Iterator)41 IdRepoException (com.sun.identity.idm.IdRepoException)27 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)22 EntitlementException (com.sun.identity.entitlement.EntitlementException)19 LinkedHashSet (java.util.LinkedHashSet)18 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)17 CLIException (com.sun.identity.cli.CLIException)16 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)16 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)13 ServiceSchema (com.sun.identity.sm.ServiceSchema)12