use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project OpenAM by OpenRock.
the class DJLDAPv3Repo method getFilteredRoleMemberships.
/**
* Returns the filtered and non-filtered role memberships for this given user. This will execute a read on the user
* entry to retrieve the nsRole attribute. The values of the attribute will be returned along with the non-filtered
* role memberships.
*
* @param dn The DN of the user identity.
* @return The DNs of the filtered roles this user is member of.
* @throws IdRepoException If there was an error while retrieving the filtered or non-filtered role membership
* information.
*/
private Set<String> getFilteredRoleMemberships(String dn) throws IdRepoException {
Set<String> results = new CaseInsensitiveHashSet();
Connection conn = null;
try {
conn = connectionFactory.getConnection();
SearchResultEntry entry = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn, roleAttr));
Attribute attr = entry.getAttribute(roleAttr);
if (attr != null) {
results.addAll(LDAPUtils.getAttributeValuesAsStringSet(attr));
}
} catch (LdapException ere) {
DEBUG.error("An error occurred while trying to retrieve filtered role memberships for " + dn + " using " + roleAttr + " attribute", ere);
handleErrorResult(ere);
} finally {
IOUtils.closeIfNotNull(conn);
}
results.addAll(getRoleMemberships(dn));
return results;
}
use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project OpenAM by OpenRock.
the class DJLDAPv3Repo method getGroupMembers.
/**
* Returns the DNs of the members of this group. If the MemberURL attribute has been configured, then this
* will also try to retrieve dynamic group members using the memberURL.
*
* @param dn The DN of the group to query.
* @return The DNs of the members.
* @throws IdRepoException If there is an error while trying to retrieve the members.
*/
private Set<String> getGroupMembers(String dn) throws IdRepoException {
Set<String> results = new HashSet<String>();
Connection conn = null;
String[] attrs;
if (memberURLAttr != null) {
attrs = new String[] { uniqueMemberAttr, memberURLAttr };
} else {
attrs = new String[] { uniqueMemberAttr };
}
try {
conn = connectionFactory.getConnection();
SearchResultEntry entry = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn, attrs));
Attribute attr = entry.getAttribute(uniqueMemberAttr);
if (attr != null) {
results.addAll(LDAPUtils.getAttributeValuesAsStringSet(attr));
} else if (memberURLAttr != null) {
attr = entry.getAttribute(memberURLAttr);
if (attr != null) {
for (ByteString byteString : attr) {
LDAPUrl url = LDAPUrl.valueOf(byteString.toString());
SearchRequest searchRequest = LDAPRequests.newSearchRequest(url.getName(), url.getScope(), url.getFilter(), DN_ATTR);
searchRequest.setTimeLimit(defaultTimeLimit);
searchRequest.setSizeLimit(defaultSizeLimit);
ConnectionEntryReader reader = conn.search(searchRequest);
while (reader.hasNext()) {
if (reader.isEntry()) {
results.add(reader.readEntry().getName().toString());
} else {
//ignore search result references
reader.readReference();
}
}
}
}
}
} catch (LdapException ere) {
DEBUG.error("An error occurred while retrieving group members for " + dn, ere);
handleErrorResult(ere);
} catch (SearchResultReferenceIOException srrioe) {
//should never ever happen...
DEBUG.error("Got reference instead of entry", srrioe);
throw newIdRepoException(IdRepoErrorCode.SEARCH_FAILED, CLASS_NAME);
} finally {
IOUtils.closeIfNotNull(conn);
}
return results;
}
use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project OpenAM by OpenRock.
the class UpgradeUtils method getSunServiceID.
/**
* Returns the value of <code>sunserviceid</code> attribute of a service
* sub-configuration.
*
* @param subConfig name of the service sub-configuration
* @return string value of <code>sunserviceid</code> attribute.
*/
static String getSunServiceID(ServiceConfig subConfig) {
String classMethod = "UpgradeUtils:getSunServiceID : ";
String serviceID = "";
try (Connection conn = getLDAPConnection()) {
String dn = subConfig.getDN();
SearchResultEntry result = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn));
if (result != null) {
for (Attribute attribute : result.getAllAttributes()) {
String attrName = attribute.getAttributeDescriptionAsString();
if (attrName != null && ATTR_SUNSERVICE_ID.equalsIgnoreCase(attrName)) {
serviceID = attribute.firstValueAsString();
break;
}
}
}
if (debug.messageEnabled()) {
debug.message(classMethod + " sunserviceID is :" + serviceID);
}
} catch (Exception e) {
e.printStackTrace();
}
return serviceID;
}
use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project OpenAM by OpenRock.
the class UpgradeUtils method delete.
/**
* Delete an entry, recursing if the entry has children
*
* @param dn DN of the entry to delete
* @param ld active connection to server
* @param doDelete true if the entries really
* are to be deleted
*/
public static void delete(String dn, Connection ld, boolean doDelete) {
String theDN = "";
try {
// Find all immediate child nodes; return no
// attributes
ConnectionEntryReader res = ld.search(LDAPRequests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, "objectclass=*"));
while (res.hasNext()) {
if (res.isReference()) {
//ignore
res.readReference();
} else {
// Next directory entry
SearchResultEntry entry = res.readEntry();
theDN = entry.getName().toString();
// Recurse down
delete(theDN, ld, doDelete);
}
}
// so stop recursing and delete the node
try {
if (doDelete) {
ld.delete(LDAPRequests.newDeleteRequest(dn));
if (debug.messageEnabled()) {
debug.message(dn + " deleted");
}
}
} catch (LdapException e) {
if (debug.messageEnabled()) {
debug.message(e.toString());
}
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message(e.toString());
}
}
} catch (Exception me) {
// do nothing
}
}
use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project OpenAM by OpenRock.
the class UpgradeEntitlementsStep method upgradeEntitlementIndexes.
private void upgradeEntitlementIndexes() throws UpgradeException {
Connection conn = null;
Connection modConn = null;
try {
conn = getConnection();
//obtaining a second connection to perform the modifications.
modConn = getConnection();
SearchRequest sr = LDAPRequests.newSearchRequest(SMSEntry.getRootSuffix(), SearchScope.WHOLE_SUBTREE, ENTITLEMENT_INDEX_FILTER, SUN_KEY_VALUE, SUN_XML_KEY_VALUE);
ConnectionEntryReader reader = conn.search(sr);
int counter = 0;
long lastReport = System.currentTimeMillis();
while (reader.hasNext()) {
if (reader.isEntry()) {
if (System.currentTimeMillis() - lastReport > 3000) {
UpgradeProgress.reportEnd("upgrade.entitlement.privilege", counter, policyRuleCount);
lastReport = System.currentTimeMillis();
}
SearchResultEntry entry = reader.readEntry();
Set<String> newValues = processEntry(entry);
ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(entry.getName());
modifyRequest.addModification(ModificationType.REPLACE, SUN_XML_KEY_VALUE, newValues.toArray());
if (DEBUG.messageEnabled()) {
DEBUG.message("Upgrading entitlements index for: " + entry.getName());
}
modConn.modify(modifyRequest);
counter++;
} else {
reader.readReference();
}
}
UpgradeProgress.reportEnd("upgrade.entitlement.privilege", policyRuleCount, policyRuleCount);
} catch (Exception ex) {
DEBUG.error("An error occurred while upgrading the entitlement indexes", ex);
throw new UpgradeException(ex);
} finally {
IOUtils.closeIfNotNull(conn);
IOUtils.closeIfNotNull(modConn);
}
}
Aggregations