use of com.iplanet.am.sdk.AMSearchControl in project OpenAM by OpenRock.
the class DSAMERole method getValidValues.
/**
* Returns a list of possible values for the <code>Subject
* </code> that matches the pattern.
*
* @param token the <code>SSOToken</code> that will be used
* to determine the possible values
*
* @return <code>ValidValues</code> object
*
* @exception SSOException if SSO token is not valid
* @exception PolicyException if unable to get the list of valid
* names.
*/
public ValidValues getValidValues(SSOToken token, String pattern) throws SSOException, PolicyException {
if (!initialized) {
throw (new PolicyException(ResBundleUtils.rbName, "role_subject_not_yet_initialized", null, null));
}
try {
AMStoreConnection amConnection = new AMStoreConnection(token);
AMOrganization orgObject = amConnection.getOrganization(organizationDN);
AMSearchControl sc = new AMSearchControl();
sc.setMaxResults(maxResults);
sc.setTimeOut(timeLimit);
sc.setSearchScope(roleSearchScope);
AMSearchResults results = orgObject.searchAllRoles(pattern, sc);
int status;
switch(results.getErrorCode()) {
case AMSearchResults.SUCCESS:
status = ValidValues.SUCCESS;
break;
case AMSearchResults.SIZE_LIMIT_EXCEEDED:
status = ValidValues.SIZE_LIMIT_EXCEEDED;
break;
case AMSearchResults.TIME_LIMIT_EXCEEDED:
status = ValidValues.TIME_LIMIT_EXCEEDED;
break;
default:
status = ValidValues.SUCCESS;
}
return new ValidValues(status, results.getSearchResults());
} catch (AMException e) {
LdapException lde = e.getLDAPException();
if (lde != null) {
ResultCode ldapErrorCode = lde.getResult().getResultCode();
if (ResultCode.INVALID_CREDENTIALS.equals(ldapErrorCode)) {
throw new PolicyException(ResBundleUtils.rbName, "ldap_invalid_password", null, null);
} else if (ResultCode.NO_SUCH_OBJECT.equals(ldapErrorCode)) {
String[] objs = { organizationDN };
throw new PolicyException(ResBundleUtils.rbName, "no_such_am_roles_base_dn", objs, null);
}
String errorMsg = lde.getResult().getDiagnosticMessage();
String additionalMsg = lde.getResult().getResultCode().getName().toString(Locale.ROOT);
if (additionalMsg != null) {
throw new PolicyException(errorMsg + ": " + additionalMsg);
} else {
throw new PolicyException(errorMsg);
}
}
throw new PolicyException(e);
}
}
use of com.iplanet.am.sdk.AMSearchControl in project OpenAM by OpenRock.
the class AMClientCapData method getMinimalClientInfo.
/**
* Demand Load stuff
*/
/**
* Gets a minimal set of client properties for all clients.
*
* @return Set of Maps. Each Map has the propertyNames for the Key and Value
* is Set of Property values. By default, the keys returned are
* clientType, userAgent & parentID.
*/
public Set getMinimalClientInfo() {
Set clients = new HashSet();
AMSearchControl amsrchCntrl = new AMSearchControl();
amsrchCntrl.setReturnAttributes(minClient);
try {
long st = System.currentTimeMillis();
AMSearchResults results = amClientOrg.searchEntities("*", amsrchCntrl, null, UMS_SRCH_TEMPLATE_NAME);
long end = System.currentTimeMillis();
if (debug.messageEnabled()) {
debug.message(dbStr + "getMinimalClientInfo() Srch Time (ms) = " + (end - st));
}
st = System.currentTimeMillis();
Map m = results.getResultAttributes();
Iterator keys = m.keySet().iterator();
while (keys.hasNext()) {
String dn = (String) keys.next();
Map attrsMap = (Map) m.get(dn);
Map data = parsePropertyNames(attrsMap);
clients.add(data);
}
end = System.currentTimeMillis();
if (debug.messageEnabled()) {
debug.message(dbStr + "getMinimalClientInfo() Parse Time (ms) = " + (end - st));
}
} catch (Exception e) {
debug.error(dbStr + " getMinimalClientInfo(): Search Error: ", e);
}
return clients;
}
Aggregations