本文整理匯總了Java中javax.naming.ldap.LdapContext.getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java LdapContext.getAttributes方法的具體用法?Java LdapContext.getAttributes怎麽用?Java LdapContext.getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.ldap.LdapContext
的用法示例。
在下文中一共展示了LdapContext.getAttributes方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGroup
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Group getGroup(String groupName) throws GroupNotFoundException {
LdapContext ctx = null;
try {
String groupDN = manager.findGroupDN(groupName);
// Load record.
ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);
return processGroup(ctx, attrs);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
}
finally {
try {
if (ctx != null) {
ctx.setRequestControls(null);
ctx.close();
}
}
catch (Exception ignored) {
// Ignore.
}
}
}
示例2: defineTriggerExecutionSpecificPoint
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
* Defines the Administration point and administrative role for the TriggerExecution specific point
* @param apCtx The administrative point context
* @throws NamingException If the operation failed
*/
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException
{
Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } );
Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT );
if ( administrativeRole == null
|| !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) )
{
Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT,
SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true );
apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
}
}
示例3: getObject
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected Identity getObject(String distinguishedName, String scope) {
LdapContext context = null;
try {
LdapName object = new LdapName(distinguishedName);
context = getServiceContext();
Attributes search;
search = context.getAttributes(object);
if (!isType(search, scope) && !hasPermission(search)){
return null;
}
return attributesToIdentity(object);
}
catch (NamingException e) {
getLogger().error("Failed to get object: {} : {}", distinguishedName, e.getExplanation());
if(!LDAPUtils.isRecoverable(e)) {
invalidateServiceContext(context);
context = null;
}
return null;
}
finally {
if (context != null) {
returnServiceContext(context);
}
}
}
示例4: loadRoleByRoleNameAttributeID
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected void loadRoleByRoleNameAttributeID(LdapContext searchContext, String roleDN)
{
String[] returnAttribute = {roleNameAttributeID};
if (trace) {
log.trace("Using roleDN: " + roleDN);
}
try
{
Attributes result2 = searchContext.getAttributes(roleDN, returnAttribute);
Attribute roles2 = result2.get(roleNameAttributeID);
if (roles2 != null)
{
for (int m = 0; m < roles2.size(); m++)
{
String roleName = (String) roles2.get(m);
addRole(roleName);
}
}
}
catch (NamingException e)
{
if (trace) {
log.trace("Failed to query roleNameAttrName", e);
}
}
}
示例5: getByDn
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Attributes getByDn(final String dn) throws NamingException {
LdapContext ctx = new InitialLdapContext(env, null);
Attributes result = ctx.getAttributes(dn);
ctx.close();
return result;
}
示例6: getGroup
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
@Override
public Group getGroup(String groupName) throws GroupNotFoundException {
LdapContext ctx = null;
try {
String groupDN = manager.findGroupDN(groupName);
// Load record.
ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);
return processGroup(ctx, attrs);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
}
finally {
try {
if (ctx != null) {
ctx.setRequestControls(null);
ctx.close();
}
}
catch (Exception ignored) {
// Ignore.
}
}
}
示例7: getGroupMembershipLists
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
* Returns the distinguished-names (DNs) of all the members of the groups
* specified in the restriction list. The information is organised as a list
* of <code>"<groupDN>=<
* [userDN1,userDN2,...,userDNn]>"</code>. Put differently, each
* <code>groupDN</code> is associated to a list of <code>userDNs</code>.
*
* @param connection
* The connection to the LDAP directory server.
* @return Returns a map of groupDNs to userDN lists.
* @throws NamingException
* Propagated from underlying LDAP communication layer.
*/
protected Map<String, Collection<String>> getGroupMembershipLists(LdapContext ldapContext) throws NamingException {
Map<String, Collection<String>> result = new HashMap<String, Collection<String>>();
Iterator<String> groupDNsIterator = groupDNs.iterator();
Attributes groupAttributes;
while (groupDNsIterator.hasNext()) {
String groupDN = (String) groupDNsIterator.next();
groupAttributes = ldapContext.getAttributes(groupDN);
result.put(groupDN, extractMembers(groupAttributes));
}
return result;
}
示例8: findRolsAmbCodi
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public List<String> findRolsAmbCodi(String codi) throws PersonesPluginException {
List<String> roles = new ArrayList<String>();
String userFilter = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.filter.user");
String filter = new String(userFilter).replace("###", codi);
String roleAtt = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role");
String roleName = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role.name");
if (roleAtt != null && roleName != null) {
LdapContext ctx = null;
try {
ctx = getContext();
SearchControls searchCtls = new SearchControls();
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> answer = ctx.search(
GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.searchbase"),
filter,
searchCtls);
if (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
Attribute memberOf = sr.getAttributes().get(roleAtt);
if (memberOf != null) {
for (int i = 0; i < memberOf.size(); i++) {
Attributes atts = ctx.getAttributes(memberOf.get(i).toString(), new String[] {roleName});
Attribute att = atts.get(roleName);
if (att.get() != null)
roles.add(att.get().toString());
}
}
}
ctx.close();
} catch (Exception ex) {
throw new PersonesPluginException("No s'ha pogut trobar cap persona", ex);
}
}
return roles;
}
示例9: attributesToIdentity
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected Identity attributesToIdentity(LdapName dn){
LdapContext context = getServiceContext();
try {
Attributes search = context.getAttributes(dn);
log.trace("Attributes for dn: " + dn + " to translate: " + search);
String externalIdType;
String accountName;
String externalId = dn.toString();
String login;
boolean user = false;
if (isType(search, getConstantsConfig().getUserObjectClass())){
externalIdType = getConstantsConfig().getUserScope();
if (search.get(getConstantsConfig().getUserNameField()) != null) {
accountName = (String) search.get(getConstantsConfig().getUserNameField()).get();
} else {
accountName = externalId;
}
login = (String) search.get(getConstantsConfig().getUserLoginField()).get();
user = true;
} else if (isType(search, getConstantsConfig().getGroupObjectClass())) {
externalIdType = getConstantsConfig().getGroupScope();
if (search.get(getConstantsConfig().getGroupNameField()) != null) {
accountName = (String) search.get(getConstantsConfig().getGroupNameField()).get();
} else {
accountName = externalId;
}
if (search.get(getConstantsConfig().getUserLoginField()) != null) {
login = (String) search.get(getConstantsConfig().getUserLoginField()).get();
} else {
login = accountName;
}
} else {
return null;
}
return new Identity(externalIdType, externalId, accountName, null, null, login, user);
} catch (NamingException e) {
getLogger().error("Failed to get attributes: {} : {}", dn, e.getExplanation());
if(!LDAPUtils.isRecoverable(e)) {
invalidateServiceContext(context);
context = null;
}
return null;
} finally {
if (context != null) {
returnServiceContext(context);
}
}
}
示例10: obtainRole
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected void obtainRole(LdapContext searchContext, String dn, SearchResult sr) throws NamingException, LoginException
{
if (trace) {
log.trace("rolesSearch resultDN = " + dn);
}
String[] attrNames =
{roleAttributeID};
Attributes result = null;
if (sr == null || ( sr.isRelative() && sr.getAttributes().size() == 0 ) ) {
result = searchContext.getAttributes(dn, attrNames);
}
else if (sr != null && sr.isRelative() && sr.getAttributes().size() != 0 ) {
result = sr.getAttributes();
}
else
{
result = getAttributesFromReferralEntity(sr);
}
if (result != null && result.size() > 0)
{
Attribute roles = result.get(roleAttributeID);
for (int n = 0; n < roles.size(); n++)
{
String roleName = (String) roles.get(n);
if (roleAttributeIsDN)
{
// Query the roleDN location for the value of roleNameAttributeID
String roleDN = "\"" + roleName + "\"";
loadRoleByRoleNameAttributeID(searchContext, roleDN);
recurseRolesSearch(searchContext, roleName);
}
else
{
// The role attribute value is the role name
addRole(roleName);
}
}
}
}