use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.
the class AMIdentity method getServiceAttributesName.
private Set getServiceAttributesName(String serviceName) throws IdRepoException, SSOException {
Set attrNames = Collections.EMPTY_SET;
try {
// Get attribute names for USER type only, so plugin knows
// what attributes to remove.
attrNames = new HashSet();
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema uss = ssm.getSchema(type.getName());
if (uss != null) {
attrNames = uss.getAttributeSchemaNames();
}
// realm, need to add dynamic attributes also
if (!(type.equals(IdType.ROLE) || type.equals(IdType.REALM) || type.equals(IdType.FILTEREDROLE))) {
uss = ssm.getDynamicSchema();
if (uss != null) {
if (attrNames == Collections.EMPTY_SET) {
attrNames = uss.getAttributeSchemaNames();
} else {
attrNames.addAll(uss.getAttributeSchemaNames());
}
}
} else {
// Add COS priority attribute
attrNames.add(COS_PRIORITY);
}
} catch (SMSException smse) {
if (debug.messageEnabled()) {
debug.message("AMIdentity.getServiceAttributes: Caught SM exception", smse);
}
// just returned whatever we find or empty set
// if services is not found.
}
return attrNames;
}
use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.
the class AMIdentity method unassignService.
/**
* Removes a service from the identity.
*
* This method is only valid for AMIdentity object of type User.
*
* @param serviceName
* Name of service to be removed.
* @throws IdRepoException
* If there are repository related error conditions.
* @throws SSOException
* If user's single sign on token is invalid.
* @supported.api
*/
public void unassignService(String serviceName) throws IdRepoException, SSOException {
IdServices idServices = IdServicesFactory.getDataStoreServices();
Set OCs = getServiceOCs(token, serviceName);
Map tMap = new HashMap();
tMap.put(serviceName, OCs);
Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
if (!assignedServices.contains(serviceName)) {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
}
Map attrMap = new HashMap();
Set objectclasses = getAttribute("objectclass");
if (objectclasses != null && !objectclasses.isEmpty()) {
Set removeOCs = AMCommonUtils.updateAndGetRemovableOCs(objectclasses, OCs);
try {
// Get attribute names for USER type only, so plugin knows
// what attributes to remove.
Set attrNames = new HashSet();
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema uss = ssm.getSchema(type.getName());
if (uss != null) {
attrNames = uss.getAttributeSchemaNames();
}
Iterator it = attrNames.iterator();
while (it.hasNext()) {
String a = (String) it.next();
attrMap.put(a, Collections.EMPTY_SET);
}
} catch (SMSException smse) {
/*
* debug.error( "AMIdentity.unassignService: Caught SM
* exception", smse); do nothing
*/
}
attrMap.put("objectclass", removeOCs);
// The protocol is to pass service Name and Map of objectclasses
// to be removed from entry.
}
idServices.unassignService(token, type, name, serviceName, attrMap, orgName, univDN);
}
use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.
the class AMIdentity method getServiceConfig.
/**
* Get service default config from SMS
*
* @param token
* SSOToken a valid SSOToken
* @param serviceName
* the service name
* @param type
* service schema type (Dynamic, Policy etc)
* @return returns a Map of Default Configuration values for the specified
* service.
*/
private Map getServiceConfig(SSOToken token, String serviceName, SchemaType type) throws SMSException, SSOException {
// Map of attribute/value pairs
Map attrMap = null;
if (type != SchemaType.POLICY) {
ServiceSchemaManager scm = new ServiceSchemaManager(serviceName, token);
ServiceSchema gsc = scm.getSchema(type);
attrMap = gsc.getAttributeDefaults();
}
return attrMap;
}
use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.
the class AMIdentity method modifyService.
/**
* Set attributes related to a specific service. The assumption is that the
* service is already assigned to the identity. The attributes for the
* service are validated against the service schema.
*
* This method is only valid for AMIdentity object of type User.
*
* @param serviceName
* Name of the service.
* @param attrMap
* Map of attribute-values.
* @throws IdRepoException
* If there are repository related error conditions.
* @throws SSOException
* If user's single sign on token is invalid.
* @supported.api
*/
public void modifyService(String serviceName, Map attrMap) throws IdRepoException, SSOException {
IdServices idServices = IdServicesFactory.getDataStoreServices();
Set OCs = getServiceOCs(token, serviceName);
SchemaType stype;
Map tMap = new HashMap();
tMap.put(serviceName, OCs);
Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
if (!assignedServices.contains(serviceName)) {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
}
// Check if attrMap has cos priority attribute
// If present, remove it for validating the attributes
boolean hasCosPriority = (new CaseInsensitiveHashSet(attrMap.keySet()).contains(COS_PRIORITY));
Object values = null;
if (hasCosPriority) {
attrMap = new CaseInsensitiveHashMap(attrMap);
values = attrMap.remove(COS_PRIORITY);
}
// Validate the attributes
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema ss = ssm.getSchema(type.getName());
if (ss != null) {
attrMap = ss.validateAndInheritDefaults(attrMap, false);
stype = ss.getServiceType();
} else if ((ss = ssm.getSchema(SchemaType.DYNAMIC)) != null) {
attrMap = ss.validateAndInheritDefaults(attrMap, false);
stype = SchemaType.DYNAMIC;
} else {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
}
} catch (SMSException smse) {
// debug.error
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.DATA_INVALID_FOR_SERVICE, args);
}
// Add COS priority if present
if (hasCosPriority) {
attrMap.put(COS_PRIORITY, values);
}
// modify service attrs
if (debug.messageEnabled()) {
debug.message("AMIdentity.modifyService befre idService " + "serviceName=" + serviceName + "; attrMap=" + attrMap);
}
idServices.modifyService(token, type, name, serviceName, stype, attrMap, orgName, univDN);
}
use of com.sun.identity.sm.ServiceSchemaManager in project OpenAM by OpenRock.
the class AMIdentity method serviceHasSubSchema.
/**
* Returns true if the service has the subSchema. False otherwise.
*
* @param token
* SSOToken a valid SSOToken
* @param serviceName
* the service name
* @param schemaType
* service schema type (Dynamic, Policy etc)
* @return true if the service has the subSchema.
*/
private boolean serviceHasSubSchema(SSOToken token, String serviceName, SchemaType schemaType) throws SMSException, SSOException {
boolean schemaTypeFlg = false;
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
Set types = ssm.getSchemaTypes();
if (debug.messageEnabled()) {
debug.message("AMServiceUtils.serviceHasSubSchema() " + "SchemaTypes types for " + serviceName + " are: " + types);
}
schemaTypeFlg = types.contains(schemaType);
} catch (ServiceNotFoundException ex) {
if (debug.warningEnabled()) {
debug.warning("AMServiceUtils.serviceHasSubSchema() " + "Service does not exist : " + serviceName);
}
}
return (schemaTypeFlg);
}
Aggregations