use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class AMServiceUtils method getServiceAttributesWithQualifier.
/**
* Method to get the attribute names of a service with CosQualifier. For
* example: Return set could be: <br>
* ["iplanet-am-web-agent-allow-list merge-schemes",
* "iplanet-am-web-agent-deny-list merge-schemes"]
* <p>
* This method only populates these attributes only for Dynamic attributes.
*/
protected static Set getServiceAttributesWithQualifier(SSOToken token, String serviceName) throws SMSException, SSOException {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema ss = null;
try {
ss = ssm.getSchema(SchemaType.DYNAMIC);
} catch (SMSException sme) {
if (debug.warningEnabled()) {
debug.warning("AMServiceUtils.getServiceAttributesWithQualifier(): " + "No schema defined for SchemaType.DYNAMIC type");
}
}
if (ss == null) {
return Collections.EMPTY_SET;
}
Set attrNames = new HashSet();
Set attrSchemaNames = ss.getAttributeSchemaNames();
Iterator itr = attrSchemaNames.iterator();
while (itr.hasNext()) {
String attrSchemaName = (String) itr.next();
AttributeSchema attrSchema = ss.getAttributeSchema(attrSchemaName);
String name = attrSchemaName + " " + attrSchema.getCosQualifier();
attrNames.add(name);
}
return attrNames;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class IdServicesImpl method getServiceAttributesAscending.
/**
* Non-javadoc, non-public methods
* Get the service attributes of the name identity. Traverse to the global
* configuration if necessary until all attributes are found or reached
* the global area whichever occurs first.
*
* @param token is the sso token of the person performing this operation.
* @param type is the identity type of the name parameter.
* @param name is the identity we are interested in.
* @param serviceName is the service we are interested in
* @param attrNames are the name of the attributes wer are interested in.
* @param amOrgName is the orgname.
* @param amsdkDN is the amsdkDN.
* @throws IdRepoException if there are repository related error conditions.
* @throws SSOException if user's single sign on token is invalid.
*/
public Map getServiceAttributesAscending(SSOToken token, IdType type, String name, String serviceName, Set attrNames, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
Map finalResult = new HashMap();
Set finalAttrName = new HashSet();
String nextName = name;
String nextAmOrgName = amOrgName;
String nextAmsdkDN = amsdkDN;
IdType nextType = type;
Set missingAttr = new HashSet(attrNames);
do {
// amsdkDN will change as we move up the tree.
try {
Map serviceResult = getServiceAttributes(token, nextType, nextName, serviceName, missingAttr, nextAmOrgName, nextAmsdkDN);
if (DEBUG.messageEnabled()) {
DEBUG.message("IdServicesImpl." + "getServiceAttributesAscending:" + " nextType=" + nextType + "; nextName=" + nextName + "; serviceName=" + serviceName + "; missingAttr=" + missingAttr + "; nextAmOrgName=" + nextAmOrgName + "; nextAmsdkDN=" + nextAmsdkDN);
DEBUG.message(" getServiceAttributesAscending: " + "serviceResult=" + serviceResult);
DEBUG.message(" getServiceAttributesAscending: " + " finalResult=" + finalResult);
DEBUG.message(" getServiceAttributesAscending: " + " finalAttrName=" + finalAttrName);
}
if (serviceResult != null) {
Set srvNameReturned = serviceResult.keySet();
// save the newly found attrs
// amsdk returns emptyset when attrname is not present.
Iterator nameIt = srvNameReturned.iterator();
while (nameIt.hasNext()) {
String attr = (String) nameIt.next();
Set attrValue = (Set) serviceResult.get(attr);
if (!attrValue.isEmpty()) {
finalResult.put(attr, attrValue);
finalAttrName.add(attr);
}
}
if (DEBUG.messageEnabled()) {
DEBUG.message(" getServiceAttributesAscending:" + " serviceResult=" + serviceResult);
DEBUG.message(" getServiceAttributesAscending:" + " finalResult=" + finalResult);
}
}
if (finalAttrName.containsAll(attrNames)) {
if (DEBUG.messageEnabled()) {
DEBUG.message("exit getServiceAttributesAscending:" + " finalResult=" + finalResult);
}
return (finalResult);
}
// find the missing attributes
missingAttr.clear();
Iterator it = attrNames.iterator();
while (it.hasNext()) {
String attrName = (String) it.next();
if (!finalAttrName.contains(attrName)) {
missingAttr.add(attrName);
}
}
} catch (IdRepoException idrepo) {
if (DEBUG.warningEnabled()) {
DEBUG.warning(" getServiceAttributesAscending: " + "idrepoerr", idrepo);
}
} catch (SSOException ssoex) {
if (DEBUG.warningEnabled()) {
DEBUG.warning(" getServiceAttributesAscending: " + "ssoex", ssoex);
}
}
// go up to the parent org
try {
if (nextType.equals(IdType.USER) || nextType.equals(IdType.AGENT)) {
// try the user or agent's correct realm.
nextAmsdkDN = nextAmOrgName;
nextType = IdType.REALM;
} else {
OrganizationConfigManager ocm = new OrganizationConfigManager(token, nextAmOrgName);
OrganizationConfigManager parentOCM = ocm.getParentOrgConfigManager();
String parentName = parentOCM.getOrganizationName();
if (DEBUG.messageEnabled()) {
DEBUG.message(" getServiceAttributesAscending: " + "parentName=" + parentName);
}
nextType = IdType.REALM;
if (nextAmOrgName.equalsIgnoreCase(parentName)) {
// at root.
nextName = null;
} else {
nextAmOrgName = parentName;
}
nextAmOrgName = parentName;
nextAmsdkDN = parentName;
}
} catch (SMSException smse) {
if (DEBUG.warningEnabled()) {
DEBUG.warning(" getServiceAttributesAscending: " + "smserror", smse);
}
nextName = null;
}
} while (nextName != null);
// get the rest from global.
if (!missingAttr.isEmpty()) {
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema schema = ssm.getDynamicSchema();
Map gAttrs = schema.getAttributeDefaults();
Iterator missingIt = missingAttr.iterator();
while (missingIt.hasNext()) {
String missingAttrName = (String) missingIt.next();
finalResult.put(missingAttrName, gAttrs.get(missingAttrName));
}
} catch (SMSException smse) {
if (DEBUG.messageEnabled()) {
DEBUG.message("IdServicesImpl(): getServiceAttributeAscending " + " Failed to get global default.", smse);
}
}
}
if (DEBUG.messageEnabled()) {
DEBUG.message("exit end getServiceAttributesAscending: " + " finalResult=" + finalResult);
}
return finalResult;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class ServiceTypeManager method getServiceType.
/**
* Returns a <code>ServiceType</code> object for the given
* service name. If the service does not exist, the exception
* <code>NameNotFoundException</code> is thrown.
*
* @param serviceTypeName name of the service
*
* @return <code>ServiceType</code> object for the given service name
*
* @exception SSOException single-sign-on token has either expired
* or is invalid
* @exception NameNotFoundException service for the given <code>
* serviceTypeName</code> does not exist
*/
public ServiceType getServiceType(String serviceTypeName) throws SSOException, NameNotFoundException {
ServiceType st = (ServiceType) serviceTypes.get(serviceTypeName);
if (st == null) {
try {
ServiceSchema policySchema = null;
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceTypeName, token);
if ((ssm == null) || ((policySchema = ssm.getPolicySchema()) == null)) {
if (PolicyManager.debug.messageEnabled()) {
PolicyManager.debug.message("ServiceTypeManager::getServiceType " + serviceTypeName + " not found with policy privileges");
}
String[] objs = { serviceTypeName };
throw (new NameNotFoundException(ResBundleUtils.rbName, "service_name_not_found", objs, serviceTypeName, PolicyException.SERVICE));
}
st = new ServiceType(serviceTypeName, ssm, policySchema);
serviceTypes.put(serviceTypeName, st);
} catch (SMSException se) {
PolicyManager.debug.error("In ServiceTypeManager::getServiceType " + serviceTypeName + " got SMS exception: ", se);
throw (new NameNotFoundException(se, serviceTypeName, PolicyException.SERVICE));
}
}
return st;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method getAttributeValueString.
/**
* Returns a value of an attribute.
* This method assumes that the attribute is single valued.
*
* @param serviceName name of the service.
* @param attributeName name of the attribute.
* @param schemaType the schema type.
* @return the value of the attribute
* @throws UpgradeException if there is an error.
*/
public static String getAttributeValueString(String serviceName, String attributeName, String schemaType) throws UpgradeException {
String value = null;
try {
ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
ServiceSchema ss = sm.getSchema(schemaType);
Map attributeDefaults = ss.getAttributeDefaults();
if (attributeDefaults.containsKey(attributeName)) {
HashSet hashSet = (HashSet) attributeDefaults.get(attributeName);
value = (String) (hashSet.iterator().next());
}
} catch (SMSException sme) {
throw new UpgradeException("Error getting attr value : " + sme.getMessage());
}
return value;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method removeAttributeSchema.
/**
* Remove an attribute schema from an existing service.
*
* @param serviceName the service name.
* @param subSchemaName name of the subschema
* @param schemaType the schema type.
* @param attributeName attribute to remove
* @param adminToken admin SSOToken
* @throws UpgradeException if there is an error removing the
* attribute schema.
* @supported.api
*/
public static void removeAttributeSchema(String serviceName, String subSchemaName, String schemaType, String attributeName, SSOToken adminToken) throws UpgradeException {
ServiceSchema ss = getServiceSchema(serviceName, subSchemaName, schemaType, adminToken);
removeAttributeSchema(ss, attributeName);
}
Aggregations