use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class OpenAMScopeValidator method getUpdatedAt.
private String getUpdatedAt(String username, String realm, OAuth2Request request) throws NotFoundException {
try {
final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
String modifyTimestampAttributeName;
String createdTimestampAttributeName;
try {
modifyTimestampAttributeName = providerSettings.getModifiedTimestampAttributeName();
createdTimestampAttributeName = providerSettings.getCreatedTimestampAttributeName();
} catch (ServerException e) {
logger.error("Unable to read last modified attribute from datastore", e);
return DEFAULT_TIMESTAMP;
}
if (modifyTimestampAttributeName == null && createdTimestampAttributeName == null) {
return null;
}
final AMHashMap timestamps = getTimestamps(username, realm, modifyTimestampAttributeName, createdTimestampAttributeName);
final String modifyTimestamp = CollectionHelper.getMapAttr(timestamps, modifyTimestampAttributeName);
if (modifyTimestamp != null) {
synchronized (TIMESTAMP_DATE_FORMAT) {
return Long.toString(TIMESTAMP_DATE_FORMAT.parse(modifyTimestamp).getTime() / 1000);
}
} else {
final String createTimestamp = CollectionHelper.getMapAttr(timestamps, createdTimestampAttributeName);
if (createTimestamp != null) {
synchronized (TIMESTAMP_DATE_FORMAT) {
return Long.toString(TIMESTAMP_DATE_FORMAT.parse(createTimestamp).getTime() / 1000);
}
} else {
return DEFAULT_TIMESTAMP;
}
}
} catch (IdRepoException e) {
if (logger.errorEnabled()) {
logger.error("ScopeValidatorImpl" + ".getUpdatedAt: " + "error searching Identities with username : " + username, e);
}
} catch (SSOException e) {
logger.warning("Error getting updatedAt attribute", e);
} catch (ParseException e) {
logger.warning("Error getting updatedAt attribute", e);
}
return null;
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class IdRepoUtils method getAttrMapWithoutPasswordAttrs.
/**
* Returns an attribute map with all the password attributes being masked.
*
* @param attrMap an attribute map
* @param pwdAttrs a set of password attribute names
*
* @return an attribute map with all the password attributes being masked.
*/
public static Map<String, ?> getAttrMapWithoutPasswordAttrs(Map<String, ?> attrMap, Set<String> pwdAttrs) {
if (attrMap == null || attrMap.isEmpty()) {
return attrMap;
}
//the attrmap needs to be case-insensitive in order to detect password attributes correctly
attrMap = new CaseInsensitiveHashMap(attrMap);
Set<String> allPwdAttrs = new HashSet<String>(defaultPwdAttrs);
if (pwdAttrs != null) {
allPwdAttrs.addAll(pwdAttrs);
}
AMHashMap returnAttrMap = null;
for (String pwdAttr : allPwdAttrs) {
if (attrMap.containsKey(pwdAttr)) {
if (returnAttrMap == null) {
returnAttrMap = new AMHashMap();
returnAttrMap.copy(attrMap);
}
returnAttrMap.put(pwdAttr, "xxx...");
}
}
return (returnAttrMap == null ? attrMap : returnAttrMap);
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class IdServicesImpl method combineAttrMaps.
private Map combineAttrMaps(Set setOfMaps, boolean isString) {
Map resultMap = new AMHashMap(!isString);
Iterator it = setOfMaps.iterator();
while (it.hasNext()) {
Map currMap = (Map) it.next();
if (currMap != null) {
Iterator keyset = currMap.keySet().iterator();
while (keyset.hasNext()) {
String thisAttr = (String) keyset.next();
if (isString) {
Set resultSet = (Set) resultMap.get(thisAttr);
Set thisSet = (Set) currMap.get(thisAttr);
if (resultSet != null) {
resultSet.addAll(thisSet);
} else {
/*
* create a new Set so that we do not alter the set
* that is referenced in setOfMaps
*/
resultSet = new HashSet((Set) currMap.get(thisAttr));
resultMap.put(thisAttr, resultSet);
}
} else {
// binary attributes
byte[][] resultSet = (byte[][]) resultMap.get(thisAttr);
byte[][] thisSet = (byte[][]) currMap.get(thisAttr);
int combinedSize = thisSet.length;
if (resultSet != null) {
combinedSize = resultSet.length + thisSet.length;
byte[][] tmpSet = new byte[combinedSize][];
for (int i = 0; i < resultSet.length; i++) {
tmpSet[i] = (byte[]) resultSet[i];
}
for (int i = 0; i < thisSet.length; i++) {
tmpSet[i] = (byte[]) thisSet[i];
}
resultSet = tmpSet;
} else {
resultSet = (byte[][]) thisSet.clone();
}
resultMap.put(thisAttr, resultSet);
}
}
}
}
return resultMap;
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method getAttributes.
// @Override
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isStringValues) throws IdRepoException, SSOException {
// Currently not needed as AMIdentity does not have getAllBinaryAttr..
if ((attrNames == null) || attrNames.isEmpty()) {
return (getAttributes(token, type, name, amOrgName, amsdkDN));
}
cacheStats.incrementGetRequestCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incGetRqts(li);
}
// Get the identity dn
AMIdentity id = new AMIdentity(token, name, type, amOrgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
// Get the principal DN
AMIdentity tokenId = IdUtils.getIdentity(token);
String principalDN = tokenId.getUniversalId();
if (DEBUG.messageEnabled()) {
DEBUG.message("In IdRemoteCachedServicesImpl." + "getAttributes(SSOToken type, name, attrNames, " + "amOrgName, amsdkDN) (" + principalDN + ", " + dn + ", " + attrNames + " ," + amOrgName + " , " + amsdkDN + " method.");
}
// Attributes to be returned
AMHashMap attributes;
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb == null) {
// Entry not present in cache
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): NO entry found in Cachefor key = " + dn + ". Getting all these attributes from DS: " + attrNames);
}
// If the attributes returned here have an empty set as value, then
// such attributes do not have a value or invalid attributes.
// Internally keep track of these attributes.
attributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
// These attributes are either not present or not found in DS.
// Try to check if they need to be fetched by external
// plugins
Set missAttrNames = attributes.getMissingAndEmptyKeys(attrNames);
cb = new IdCacheBlock(dn, true);
cb.putAttributes(principalDN, attributes, missAttrNames, false, !isStringValues);
idRepoCache.put(dn, cb);
} else {
// Entry present in cache
attributes = (AMHashMap) cb.getAttributes(principalDN, attrNames, !isStringValues);
// Find the missing attributes that need to be obtained from DS
// Only find the missing keys as the ones with empty sets are not
// found in DS
Set missAttrNames = attributes.getMissingKeys(attrNames);
if (!missAttrNames.isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): Trying to gett these missing " + "attributes from DS: " + missAttrNames);
}
AMHashMap dsAttributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
attributes.putAll(dsAttributes);
// Add these attributes, just mark to hem as
// invalid (Attribute level Negative caching)
Set newMissAttrNames = dsAttributes.getMissingAndEmptyKeys(missAttrNames);
cb.putAttributes(principalDN, dsAttributes, newMissAttrNames, false, !isStringValues);
} else {
// All attributes found in cache
cacheStats.updateGetHitCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incCacheHits(li);
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): found all attributes in Cache.");
}
}
}
return attributes;
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class RemoteServicesImpl method getAttributes.
/**
* Gets all attributes corresponding to the entryDN. This method obtains the
* DC Tree node attributes and also performs compliance related verification
* checks in compliance mode. Note: In compliance mode you can skip the
* compliance checks by setting ignoreCompliance to "false".
*
* @param token
* a valid SSOToken
* @param entryDN
* the DN of the entry whose attributes need to retrieved
* @param ignoreCompliance
* a boolean value specificying if compliance related entries
* need to ignored or not. Ignored if true.
* @return a Map containing attribute names as keys and Set of values
* corresponding to each key.
* @throws AMException
* if an error is encountered in fetching the attributes
*/
public Map getAttributes(SSOToken token, String entryDN, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
try {
String tokenID = token.getTokenID().toString();
Object[] objs = { tokenID, entryDN, Boolean.valueOf(ignoreCompliance), Boolean.valueOf(byteValues), new Integer(profileType) };
Map map = (Map) client.send(client.encodeMessage("getAttributes3", objs), sessionCookies.getLBCookie(tokenID), null);
AMHashMap res = new AMHashMap();
res.copy(map);
return res;
} catch (AMRemoteException amrex) {
if (getDebug().messageEnabled()) {
getDebug().message("RemoteServicesImpl.getAttributes 3: entryDN=" + entryDN + "; AMRemoteException caught exception=", amrex);
}
throw convertException(amrex);
} catch (RemoteException rex) {
getDebug().error("RemoteServicesImpl.getAttributes: caught exception=", rex);
throw new AMException(AMSDKBundle.getString("1000"), "1000");
} catch (SSOException ssoe) {
getDebug().error("RemoteServicesImpl.getAttributes: caught SSOException=", ssoe);
throw ssoe;
} catch (Exception ex) {
if (getDebug().messageEnabled()) {
getDebug().message("RemoteServicesImpl.getAttributes3: entryDN=" + entryDN + "; caught exception=", ex);
}
throw new AMException(AMSDKBundle.getString("1000"), "1000");
}
}
Aggregations