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;
}
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);
}
}
}
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations