use of com.sun.identity.sm.SchemaType in project OpenAM by OpenRock.
the class AMIdentity method assignService.
/**
* Assigns the service and service related attributes to the identity.
*
* This method is only valid for AMIdentity object of type User.
*
* @param serviceName
* Name of service to be assigned.
* @param attributes
* 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 assignService(String serviceName, Map attributes) 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, type.getName() };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_ALREADY_ASSIGNED, args);
}
// Validate the service attributes
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema ss = ssm.getSchema(type.getName());
if (ss != null) {
// Check if attrMap has cos priority attribute
// If present, remove it for validating the attributes
Set cosPriority = (attributes != null) ? (Set) attributes.remove(COS_PRIORITY) : null;
attributes = ss.validateAndInheritDefaults(attributes, orgName, true);
if (cosPriority != null) {
attributes.put(COS_PRIORITY, cosPriority);
}
attributes = AMCommonUtils.removeEmptyValues(attributes);
stype = ss.getServiceType();
} else {
ss = ssm.getSchema(SchemaType.DYNAMIC);
if (ss == null) {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
}
if (attributes == null) {
try {
attributes = getServiceConfig(token, serviceName, SchemaType.DYNAMIC);
} catch (SMSException smsex) {
Object[] args = { serviceName, type.getName() };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, "451", args);
}
} else {
attributes = ss.validateAndInheritDefaults(attributes, orgName, true);
}
attributes = AMCommonUtils.removeEmptyValues(attributes);
stype = SchemaType.DYNAMIC;
}
// TODO: Remove this dependency of AMCrypt
attributes = AMCrypt.encryptPasswords(attributes, ss);
} catch (SMSException smse) {
// debug.error here
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
}
attributes.put("objectclass", OCs);
// The protocol for params is to pass the
// name of the service, and attribute Map containing the
// OCs to be set and validated attribute map
idServices.assignService(token, type, name, serviceName, stype, attributes, orgName, univDN);
}
use of com.sun.identity.sm.SchemaType in project OpenAM by OpenRock.
the class UpgradeUtils method getServiceSchema.
/**
* Returns the <code>ServiceSchema</code> of a service.
*
* @param serviceName the service name
* @param subSchemaName the sub schema.
* @param schemaType the schema type.
* @return the <code>ServiceSchema</code> object.
* @throws UpgradeException if there is an error.
*/
public static ServiceSchema getServiceSchema(String serviceName, String subSchemaName, String schemaType, SSOToken adminToken) throws UpgradeException {
ServiceSchema ss = null;
try {
SchemaType sType = getSchemaType(schemaType);
ServiceSchemaManager ssm = getServiceSchemaManager(serviceName, adminToken);
ss = ssm.getSchema(sType);
if (subSchemaName != null) {
ss = ss.getSubSchema(subSchemaName);
}
} catch (SMSException sme) {
throw new UpgradeException("Cannot get service schema : " + sme.getMessage());
}
return ss;
}
use of com.sun.identity.sm.SchemaType in project OpenAM by OpenRock.
the class PropertyXMLBuilder method getAttributeSchemas.
private Map getAttributeSchemas(String serviceName) throws SMSException, SSOException {
Map map = new HashMap();
if (schemaTypes == null) {
schemaTypes = svcSchemaManager.getSchemaTypes();
}
for (Iterator iter = schemaTypes.iterator(); iter.hasNext(); ) {
SchemaType type = (SchemaType) iter.next();
Object sectionTitle = mapSchemaTypeToName.get(type);
if (sectionTitle != null) {
Set set = getAttributeSchemas(type);
if ((set != null) && !set.isEmpty()) {
map.put(type, set);
}
}
}
return map;
}
use of com.sun.identity.sm.SchemaType in project OpenAM by OpenRock.
the class PropertyXMLBuilder method discardAttribute.
/**
* Discards attributes from the builder.
*
* @param discard Set of attribute names to be discarded.
*/
public void discardAttribute(Set discard) {
for (Iterator i = mapTypeToAttributeSchema.keySet().iterator(); i.hasNext(); ) {
SchemaType type = (SchemaType) i.next();
Set attributeSchema = (Set) mapTypeToAttributeSchema.get(type);
if ((attributeSchema != null) && !attributeSchema.isEmpty()) {
for (Iterator j = attributeSchema.iterator(); j.hasNext(); ) {
AttributeSchema as = (AttributeSchema) j.next();
if (discard.contains(as.getName())) {
j.remove();
}
}
}
}
}
use of com.sun.identity.sm.SchemaType in project OpenAM by OpenRock.
the class ServicesModelImpl method removeNonDisplayableServices.
private void removeNonDisplayableServices(Set serviceNames, Set schemaTypes) {
for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
String svcName = (String) i.next();
if (getServicePropertiesViewBeanURL(svcName) == null) {
boolean hasAttr = false;
for (Iterator j = schemaTypes.iterator(); j.hasNext() && !hasAttr; ) {
SchemaType type = (SchemaType) j.next();
Set displayable = AMAdminUtils.getDisplayableAttributeNames(svcName, type);
hasAttr = !displayable.isEmpty();
}
if (!hasAttr) {
i.remove();
}
}
}
}
Aggregations