use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class SchemaTest method removeAttributeDefaultValues.
@Parameters({ "subschema" })
@Test(groups = { "schema", "remove-attr-defs", "attribute-schema-ops", "subschema" }, dependsOnMethods = { "showAttributeDefaultValues" })
public void removeAttributeDefaultValues(String subschema) throws CLIException, SMSException, SSOException {
Object[] params = { subschema };
entering("removeAttributeDefaultValues", params);
String[] args = (subschema.length() == 0) ? new String[7] : new String[9];
args[0] = "remove-attr-defs";
args[1] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.SERVICE_NAME;
args[2] = TEST_SERVICE;
args[3] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.SCHEMA_TYPE;
args[4] = "global";
args[5] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.ATTRIBUTE_NAMES;
args[6] = "mock-add";
if (subschema.length() > 0) {
args[7] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.SUBSCHEMA_NAME;
args[8] = subschema;
}
CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
cmdManager.addToRequestQueue(req);
try {
cmdManager.serviceRequestQueue();
ServiceSchemaManager mgr = new ServiceSchemaManager(TEST_SERVICE, getAdminSSOToken());
ServiceSchema serviceSchema = mgr.getGlobalSchema();
if (subschema.length() > 0) {
serviceSchema = serviceSchema.getSubSchema(subschema);
}
AttributeSchema as = serviceSchema.getAttributeSchema("mock-add");
Set values = as.getDefaultValues();
assert values.isEmpty();
exiting("removeAttributeDefaultValues");
} catch (CLIException e) {
this.log(Level.SEVERE, "removeAttributeDefaultValues", e.getMessage());
throw e;
} catch (SMSException e) {
this.log(Level.SEVERE, "removeAttributeDefaultValues", e.getMessage());
throw e;
} catch (SSOException e) {
this.log(Level.SEVERE, "removeAttributeDefaultValues", e.getMessage());
throw e;
}
}
use of com.sun.identity.sm.ServiceSchema 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.ServiceSchema 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.ServiceSchema 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.ServiceSchema 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);
}
Aggregations