use of com.sun.identity.common.CaseInsensitiveHashSet 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.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class MapHelper method readMap.
/**
* Read a stream into a map of strings to sets of strings. Lines whose first non whitespace character
* is a hash are ignored as comments, while lines which do not contain an assignment are just ignored.
*
* @param is A stream to read properties from.
* @return A map of strings to sets of strings
* @throws IOException if there is an IO problem when reading the file (like it doesn't exist, etc.)
*/
public static Map<String, Set<String>> readMap(InputStream is) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
Map<String, Set<String>> result = new CaseInsensitiveHashMap();
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
// ignore blank lines and comments
if (line.length() == 0 || line.startsWith("#")) {
continue;
}
int idx = line.indexOf('=');
if (idx != -1) {
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
if (!value.isEmpty()) {
Set<String> values = result.get(key);
if (values == null) {
values = new CaseInsensitiveHashSet(1);
}
values.add(value);
result.put(key, values);
}
}
}
return result;
} finally {
IOUtils.closeIfNotNull(br);
}
}
use of com.sun.identity.common.CaseInsensitiveHashSet 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.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class UserSelfCheckCondition method setProperties.
/**
* Sets the properties of the condition.
* Evaluation of ConditionDecision is influenced by these properties.
* @param properties of the condition that governs
* whether a policy applies. The only defined property
* is <code>attributes</code>
*/
public void setProperties(Map properties) throws PolicyException {
if ((properties == null) || (properties.keySet() == null)) {
throw new PolicyException(ResBundleUtils.rbName, "properties_can_not_be_null_or_empty", null, null);
}
this.properties = Collections.unmodifiableMap(properties);
Object attrSet = properties.get(ATTRIBUTES);
Object notAttrSet = properties.get(NOT_ATTRIBUTES);
if ((attrSet == null) && (notAttrSet == null)) {
throw new PolicyException(ResBundleUtils.rbName, "properties_can_not_be_null_or_empty", null, null);
}
//Check if attributes is set
if ((attrSet != null) && (attrSet instanceof Set)) {
attributes = new CaseInsensitiveHashSet();
attributes.addAll((Set) attrSet);
} else {
if (debug.messageEnabled()) {
debug.message("UserSelfCheckCondition:setProperties: " + "Attributes are empty");
}
}
//Check if NotAttributes is set
if (notAttrSet != null && notAttrSet instanceof Set) {
notAttributes = new CaseInsensitiveHashSet();
notAttributes.addAll((Set) notAttrSet);
if (debug.messageEnabled()) {
debug.message("UserSelfCheckCondition.setProperties():" + "notAttributes = " + properties.get(NOT_ATTRIBUTES));
}
} else {
if (debug.messageEnabled()) {
debug.message("UserSelfCheckCondition:setProperties: " + "NotAttributes are empty");
}
}
// Check if all attributes are allowed
if (attributes.contains("*")) {
allowAllAttributes = true;
} else {
allowAllAttributes = false;
}
if (debug.messageEnabled()) {
debug.message("UserSelfCheckCondition.setProperties():" + "attributes, notAttributes = " + attributes + "," + notAttributes);
}
}
use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class SMSFlatFileObjectBase method searchOrgs.
private Set<String> searchOrgs(SSOToken token, String objName, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, boolean recursive, String serviceName, String attrName, Set values) throws SMSException, SSOException {
// Check the args
if ((objName == null) || (objName.length() == 0) || (filter == null) || (filter.length() == 0) || (numOfEntries < 0)) {
throw new IllegalArgumentException("SMSFlatFileObject.searchOrganizationNames(): " + "One or more arguments is null or empty: " + "objName [" + objName == null ? "null" : objName + "] filter ]" + filter == null ? "null" : filter + "]");
}
// For org search the filter prefix would be "o="
// However for root realm it would be "ou=" when search is performed
String fPrefix = "o=";
String sidFilter = null;
// construct the filename filter
if ((serviceName != null) && (attrName != null) && (values != null) && !values.isEmpty()) {
sidFilter = serviceName + "-" + attrName + "=" + values.iterator().next();
if (objName.equalsIgnoreCase(mRootDN)) {
fPrefix = "ou=";
}
}
Set<String> subentries = null;
if (sortResults) {
subentries = new CaseInsensitiveTreeSet(ascendingOrder);
} else {
subentries = new CaseInsensitiveHashSet();
}
try {
Set entries = getSubEntries(objName, fPrefix + filter, sidFilter, false, numOfEntries, sortResults, ascendingOrder);
// to make it a full DN
for (Iterator i = entries.iterator(); i.hasNext(); ) {
String suborg = (String) i.next();
subentries.add(fPrefix + suborg + "," + objName);
}
if (recursive) {
// Get the list if sub-orgs and search
Set<String> subOrgs = new HashSet();
if (!filter.equals("*") || (sidFilter != null)) {
Set ssubOrgs = getSubEntries(objName, fPrefix + "*", null, false, 0, sortResults, ascendingOrder);
for (Iterator i = ssubOrgs.iterator(); i.hasNext(); ) {
String suborg = (String) i.next();
subOrgs.add(fPrefix + suborg + "," + objName);
}
} else {
subOrgs.addAll(subentries);
}
for (String subOrgName : subOrgs) {
int reqEntries = (numOfEntries == 0) ? numOfEntries : numOfEntries - subentries.size();
if (numOfEntries < 0) {
break;
}
Set<String> subsubentries = searchOrgs(token, subOrgName, filter, reqEntries, sortResults, ascendingOrder, recursive, serviceName, attrName, values);
subentries.addAll(subsubentries);
}
}
} catch (ServiceNotFoundException e) {
// return empty set if object does not exist.
subentries = new CaseInsensitiveHashSet<>();
}
if (mDebug.messageEnabled()) {
mDebug.message("SMSFlatFileObject:searchOrgs " + "search " + filter + " for " + objName + " returned " + subentries.size() + " items");
}
return (subentries);
}
Aggregations