use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.
the class SearchResultIterator method hasNext.
public boolean hasNext() {
try {
if (results.hasNext()) {
if (current == null) {
if (results.isReference()) {
debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
return hasNext();
}
SearchResultEntry entry = results.readEntry();
String dn = entry.getName().toString();
if (hasExcludeDNs && excludeDNs.contains(dn)) {
return hasNext();
}
current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
}
return true;
}
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.message("SearchResultIterator: size limit exceeded");
} else {
debug.error("SearchResultIterator.hasNext", e);
}
} catch (SearchResultReferenceIOException e) {
debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
return hasNext();
}
conn.close();
return false;
}
use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.
the class SearchResultIterator method next.
public SMSDataEntry next() {
SMSDataEntry tmp = current;
current = null;
return tmp;
}
use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.
the class IndexTreeServiceImpl method createAndPopulateTree.
/**
* Populates a new instance of a index rule tree with policy path indexes retrieved from the associated realm.
*
* @param realm
* The realm for which policy path indexes are to be read from.
* @return A newly created tree populated with rules configured against the realm.
* @throws EntitlementException
* When an error occurs reading policy data.
*/
private IndexRuleTree createAndPopulateTree(String realm) throws EntitlementException {
IndexRuleTree indexTree = null;
String baseDN = String.format(REALM_DN_TEMPLATE, dnMapper.orgNameToDN(realm));
SSOToken token = AccessController.doPrivileged(adminAction);
if (smDAO.checkIfEntryExists(baseDN, token)) {
indexTree = new SimpleReferenceTree();
try {
Set<String> excludes = Collections.emptySet();
// Carry out search.
Iterator<SMSDataEntry> i = smDAO.search(token, baseDN, SEARCH_FILTER, 0, 0, false, false, excludes);
while (i.hasNext()) {
SMSDataEntry e = i.next();
// Suppressed warning as unchecked assignment is valid.
@SuppressWarnings("unchecked") Set<String> policyPathIndexes = e.getAttributeValues(INDEX_PATH_ATT);
indexTree.addIndexRules(policyPathIndexes);
}
} catch (SMSException smsE) {
throw new EntitlementException(52, new Object[] { baseDN }, smsE);
}
if (DEBUG.messageEnabled()) {
DEBUG.message(String.format("Index rule tree created for '%s'.", realm));
}
}
return indexTree;
}
use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.
the class ResourceTypeConfigurationImpl method getResourceTypes.
@Override
public Set<ResourceType> getResourceTypes(final QueryFilter<SmsAttribute> queryFilter, final Subject subject, final String realm) throws EntitlementException {
final SSOToken token = SubjectUtils.getSSOToken(subject);
final String dn = getResourceTypeBaseDN(realm);
final Filter filter = queryFilter.accept(new SmsQueryFilterVisitor(), null);
final Set<ResourceType> resourceTypes = new HashSet<ResourceType>();
try {
if (SMSEntry.checkIfEntryExists(dn, token)) {
// Interaction with legacy service.
@SuppressWarnings("unchecked") final Iterator<SMSDataEntry> iterator = (Iterator<SMSDataEntry>) SMSEntry.search(token, dn, filter.toString(), 0, 0, false, false, Collections.emptySet());
while (iterator.hasNext()) {
final SMSDataEntry entry = iterator.next();
final String name = entry.getAttributeValue(CONFIG_NAME);
// Extract the resource types UUID from the LDAP DN representation.
final String uuid = LDAPUtils.getName(DN.valueOf(entry.getDN()));
// Interaction with legacy service.
@SuppressWarnings("unchecked") final Set<String> actionSet = entry.getAttributeValues(CONFIG_ACTIONS);
final Map<String, Boolean> actions = getActions(actionSet);
// Interaction with legacy service.
@SuppressWarnings("unchecked") final Set<String> resources = entry.getAttributeValues(CONFIG_PATTERNS);
final String description = entry.getAttributeValue(CONFIG_DESCRIPTION);
final String createdBy = entry.getAttributeValue(CONFIG_CREATED_BY);
final String creationDate = entry.getAttributeValue(CONFIG_CREATION_DATE);
final String modifiedBy = entry.getAttributeValue(CONFIG_LAST_MODIFIED_BY);
final String modifiedDate = entry.getAttributeValue(CONFIG_LAST_MODIFIED_DATE);
final ResourceType resourceType = ResourceType.builder().setUUID(uuid).setName(name).setActions(actions).setPatterns(resources).setDescription(description).setCreatedBy(createdBy).setCreationDate(Long.parseLong(creationDate)).setLastModifiedBy(modifiedBy).setLastModifiedDate(Long.parseLong(modifiedDate)).build();
resourceTypes.add(resourceType);
}
}
} catch (SMSException smsE) {
throw new EntitlementException(RESOURCE_TYPE_RETRIEVAL_ERROR, realm, smsE);
}
return resourceTypes;
}
use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.
the class DataStore method searchPrivileges.
private Set<IPrivilege> searchPrivileges(String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, Set<String> subjectIndexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
Set<IPrivilege> results = new HashSet<IPrivilege>();
String filter = getFilter(indexes, subjectIndexes, bSubTree);
String baseDN = getSearchBaseDN(realm, null);
if (PolicyConstants.DEBUG.messageEnabled()) {
PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchPrivileges");
PolicyConstants.DEBUG.message("[PolicyEval] search filter: " + filter);
PolicyConstants.DEBUG.message("[PolicyEval] search DN: " + baseDN);
}
if (filter != null) {
SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
long start = DB_MONITOR_PRIVILEGE.start();
if (SMSEntry.checkIfEntryExists(baseDN, token)) {
try {
Iterator i = SMSEntry.search(token, baseDN, filter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, excludeDNs);
while (i.hasNext()) {
SMSDataEntry e = (SMSDataEntry) i.next();
Privilege privilege = Privilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
iterator.add(privilege);
results.add(privilege);
}
} catch (JSONException e) {
Object[] arg = { baseDN };
throw new EntitlementException(52, arg, e);
} catch (SMSException e) {
Object[] arg = { baseDN };
throw new EntitlementException(52, arg, e);
}
}
DB_MONITOR_PRIVILEGE.end(start);
}
return results;
}
Aggregations