org.apache.directory.shared.ldap.name.DN类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.apache.directory.shared.ldap.name.DN类的一些代码示例,展示了DN类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DN类的具体详情如下:
包路径:org.apache.directory.shared.ldap.name.DN
类名称:DN

DN介绍

[英]The DN class contains a DN (Distinguished Name). Its specification can be found in RFC 2253, "UTF-8 String Representation of Distinguished Names". We will store two representation of a DN : - a user Provider representation, which is the parsed String given by a user - an internal representation. A DN is formed of RDNs, in a specific order : RDN[n], RDN[n-1], ... RDN[1], RDN[0] It represents a tree, in which the root is the last RDN (RDN[0]) and the leaf is the first RDN (RDN[n]).
[中]DN类包含一个DN(可分辨名称)。其规范可在RFC2253“可分辨名称的UTF-8字符串表示法”中找到。我们将存储DN的两种表示形式:-用户提供程序表示形式,即用户给定的解析字符串-内部表示形式。DN由RDN组成,按特定顺序排列:RDN[n]、RDN[n-1]、。。。RDN[1],RDN[0]它表示一棵树,其中根是最后一个RDN(RDN[0]),叶是第一个RDN(RDN[n])。

代码示例

代码示例来源:origin: org.apache.directory.shared/shared-ldap

/**
 * {@inheritDoc}
 */
public String normalize( String value ) throws LdapException
{
  DN dn = null;
  
  dn = new DN( value );
  
  dn.normalize( schemaManager.getNormalizerMapping() );
  return dn.getNormName();
}

代码示例来源:origin: org.apache.directory.shared/shared-ldap

public String toString()
  {
    return name + " \"" + ctxName.getName() + "\"";
  }
}

代码示例来源:origin: org.apache.directory.server/apacheds-xdbm-tools

public String toString()
{
  StringBuffer buf = new StringBuffer();
  try
  {
    DN dn = new DN( partition.getEntryDn( id ) );
    buf.append( "(" ).append( id ).append( ") " );
    buf.append( dn.getRdn() );
  }
  catch ( Exception e )
  {
    buf.append( "ERROR: " + e.getLocalizedMessage() );
  }
  if ( children.size() > 0 )
  {
    buf.append( " [" ).append( children.size() ).append( "]" );
  }
  return buf.toString();
}

代码示例来源:origin: stackoverflow.com

private boolean isGroupContainUser(LDAPConnection ldapConnection, String groupDn, String userDn) throws LDAPException {
  boolean ret = false;
  Entry groupEntry = ldapConnection.getEntry(groupDn);

  String[] memberValues = groupEntry.getAttributeValues("uniquemember");
  if (memberValues != null) {
    DN ldapUserDn = new DN(userDn);
    for (String memberEntryDnString : memberValues) {
      DN memberEntryDn = new DN(memberEntryDnString);
      if (memberEntryDn.equals(ldapUserDn)) {
        ret = true;
        break;
      }
    }
  }
  return ret;
}

代码示例来源:origin: org.apache.directory.shared/shared-ldap

/**
 * Copies a DN to an DN.
 *
 * @param name composed of String name components.
 * @throws LdapInvalidDnException If the Name is invalid.
 */
public DN( DN dn ) throws LdapInvalidDnException
{
  if ( ( dn != null ) && ( dn.size() != 0 ) )
  {
    for ( int ii = 0; ii < dn.size(); ii++ )
    {
      String nameComponent = dn.get( ii );
      add( nameComponent );
    }
  }
  normalized = false;
}

代码示例来源:origin: org.wso2.carbon.identity.userstore.ldap/org.wso2.carbon.ldap.server

private void addPartitionAttributes(String partitionDN, List<String> objectClasses,
                  String realm, String dc)
    throws DirectoryServerException {
  try {
    DN adminDN = new DN(partitionDN);
    ServerEntry serverEntry = this.directoryService.newEntry(adminDN);
    addObjectClasses(serverEntry, objectClasses);
    serverEntry.add("o", realm);
    if (dc == null) {
      logger.warn("Domain component not found for partition with DN - " + partitionDN +
          ". Not setting domain component.");
    } else {
      serverEntry.add("dc", dc);
    }
    addAccessControlAttributes(serverEntry);
    this.directoryService.getAdminSession().add(serverEntry);
  } catch (Exception e) {
    String msg = "Could not add partition attributes for partition - " + partitionDN;
    throwDirectoryServerException(msg, e);
  }
}

代码示例来源:origin: io.vertx/vertx-auth-shiro

service.setWorkingDirectory(workDir);
service.setSystemPartition(systemPartition);
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
service.startup();
DN dnFoo = new DN("dc=foo,dc=com");
ServerEntry entryFoo = service.newEntry(dnFoo);
entryFoo.add("objectClass", "top", "domain", "extensibleObject");
entryFoo.add("dc", "foo");
service.getAdminSession().add(entryFoo);
DN usersDN=new DN("ou=users,dc=foo,dc=com");
ServerEntry usersEntry=service.newEntry(usersDN);
usersEntry.add("objectClass","organizationalUnit","top");
usersEntry.add("ou","users");
service.getAdminSession().add(usersEntry);

代码示例来源:origin: apiman/apiman

partition.setId("apiman");
partition.setPartitionDir(partitionDirectory);
partition.setSchemaManager(service.getSchemaManager());
partition.setSuffix("o=apiman");
service.addPartition(partition);
  service.getAdminSession().lookup(partition.getSuffixDn());
} catch (Exception lnnfe) {
  DN dn = new DN("o=apiman");
  ServerEntry entry = service.newEntry(dn);
  entry.add("objectClass", "top", "domain", "extensibleObject");
  entry.add("dc", "apiman");
  entry.add("cn", "o=apiman");
  service.getAdminSession().add(entry);

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

normalizedAliasTargetDn = new DN( aliasTarget );
normalizedAliasTargetDn.normalize( schemaManager.getNormalizerMapping() );
if ( aliasDn.isChildOf( normalizedAliasTargetDn ) )
  if ( aliasDn.equals( normalizedAliasTargetDn ) )
if ( !normalizedAliasTargetDn.isChildOf( suffixDn ) )
  throw new Exception( I18n.err( I18n.ERR_225, suffixDn.getName() ) );
targetId = ndnIdx.forwardLookup( normalizedAliasTargetDn.getNormName() );
aliasIdx.add( normalizedAliasTargetDn.getNormName(), aliasId );
ancestorDn = ( DN ) aliasDn.clone();
ancestorDn.remove( aliasDn.size() - 1 );
ancestorId = getEntryId( ancestorDn.getNormName() );
DN normalizedAliasTargetParentDn = ( DN ) normalizedAliasTargetDn.clone();
normalizedAliasTargetParentDn.remove( normalizedAliasTargetDn.size() - 1 );
if ( !aliasDn.isChildOf( normalizedAliasTargetParentDn ) )
while ( !ancestorDn.equals( suffixDn ) && null != ancestorId )
  ancestorDn.remove( ancestorDn.size() - 1 );
  ancestorId = getEntryId( ancestorDn.getNormName() );

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

throw new Exception( I18n.err( I18n.ERR_215 ) );
String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() );
AttributeType type = schemaManager.lookupAttributeTypeRegistry( modsOid );
  entry.add( type, value );
  addAliasIndices( id, new DN( ndnStr ), mods.getString() );

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

throw new Exception( I18n.err( I18n.ERR_215 ) );
DN normName = entry.getDn();
if ( normName.getNormName().equals( suffixDn.getNormName() ) )
  parentDn = ( DN ) normName.clone();
  parentDn.remove( parentDn.size() - 1 );
  parentId = getEntryId( parentDn.getNormName() );
  throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
  String msg = I18n.err( I18n.ERR_217, normName.getName(), entry );
  throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
if ( !Character.isDigit( normName.getNormName().charAt( 0 ) ) )
  throw new IllegalStateException( I18n.err( I18n.ERR_218, normName.getNormName() ) );
ndnIdx.add( normName.getNormName(), id );
updnIdx.add( normName.getName(), id );
oneLevelIdx.add( parentId, id );
  String msg = I18n.err( I18n.ERR_219, normName.getName(), entry );
  throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
  String msg = I18n.err( I18n.ERR_220, normName.getName(), entry );
  throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

throw new Exception( I18n.err( I18n.ERR_215 ) );
String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() );
if ( mods.size() > 0 )
  entry.put( mods );
  entry.remove( mods );
if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 )
  addAliasIndices( id, new DN( ndnStr ), mods.getString() );

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

if ( !updn.isNormalized() )
  updn.normalize( schemaManager.getNormalizerMapping() );
ndnIdx.add( updn.getNormName(), id );
updnIdx.add( updn.getName(), id );
    addAliasIndices( id, new DN( getEntryDn( id ) ), aliasTarget );
  DN childUpdn = ( DN ) updn.clone();
  DN oldUpdn = new DN( getEntryUpdn( childId ) );
  String rdn = oldUpdn.get( oldUpdn.size() - 1 );
  DN rdnDN = new DN( rdn );
  rdnDN.normalize( schemaManager.getNormalizerMapping() );
  childUpdn.add( rdnDN.getRdn() );
  entry.setDn( childUpdn );
  master.put( childId, entry );

代码示例来源:origin: dwimberger/crowd-ldap-server

public ServerEntry createGroupEntry(DN dn) {
 ServerEntry groupEntry = m_EntryCache.get(dn.getName());
 if (groupEntry == null) {
  try {
   //1. Obtain from crowd
   RDN rdn = dn.getRdn(2);
   String group = rdn.getNormValue();
   Group g = m_CrowdClient.getGroup(group);
   List<String> users = m_CrowdClient.getNamesOfUsersOfGroup(group, 0, Integer.MAX_VALUE);
   groupEntry = new DefaultServerEntry(
     m_SchemaManager,
     dn
   );
   groupEntry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.GROUP_OF_NAMES_OC);
   groupEntry.put(SchemaConstants.CN_AT, g.getName());
   groupEntry.put("description", g.getDescription());
   for (String u : users) {
    DN mdn = new DN(String.format("dn=%s,%s", u, CROWD_USERS_DN));
    groupEntry.add(SchemaConstants.MEMBER_AT, mdn.getName());
   }
   m_EntryCache.put(dn.getName(), groupEntry);
  } catch (Exception ex) {
   log.debug("createGroupEntry()", ex);
  }
 }
 return groupEntry;
}//createUserEntry

代码示例来源:origin: org.apache.directory.server/apacheds-avl-partition

public void rename( DN dn, RDN newRdn, boolean deleteOldRdn ) throws Exception
  Long id = getEntryId( dn.getNormName() );
  ServerEntry entry = lookup( id );
  DN updn = entry.getDn();
    AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType );
    entry.add( newRdnAttrType, newAtav.getUpValue() );
    RDN oldRdn = updn.getRdn();
    for ( AVA oldAtav : oldRdn )
        AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType );
        entry.remove( oldRdnAttrType, oldNormValue );
  DN newUpdn = ( DN ) updn.clone(); // copy da old updn
  newUpdn.remove( newUpdn.size() - 1 ); // remove old upRdn
  newUpdn.add( newRdn.getName() ); // add da new upRdn
  newUpdn.normalize( schemaManager.getNormalizerMapping() );

代码示例来源:origin: org.apache.directory.server/apacheds-core-entry

/**
   * @see java.util.Enumeration#nextElement()
   */
  public SearchResult nextElement()
  {
    try
    {
      ServerSearchResult rec = result.next();
      SearchResult searchResult = new SearchResult( 
          rec.getDn().getName(), 
          rec.getObject(), 
          toBasicAttributes( rec.getServerEntry() ), 
          rec.isRelative() );
      
      return searchResult;
    }
    catch ( NamingException ne )
    {
      NoSuchElementException nsee = 
        new NoSuchElementException( I18n.err( I18n.ERR_468 ) );
      nsee.initCause( ne );
      throw nsee;
    }
  }
};

代码示例来源:origin: dwimberger/crowd-ldap-server

DN crowdDN = new DN(m_Suffix);
crowdDN.normalize(
  m_SchemaManager.getRegistries().getAttributeTypeRegistry()
    .getNormalizerMapping()
);
RDN rdn = crowdDN.getRdn();
  crowdDN
);
dcEntry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.DOMAIN_OC);
dcEntry.put(SchemaConstants.DC_AT, rdn.getUpValue().toString());
dcEntry.put("description", "Crowd Domain");
m_CrowdEntry = dcEntry;
DN groupDn = new DN(CROWD_GROUPS_DN);
ServerEntry groupEntry = new DefaultServerEntry(
  m_SchemaManager,
DN usersDn = new DN(CROWD_USERS_DN);
ServerEntry usersEntry = new DefaultServerEntry(
  m_SchemaManager,
m_EntryCache.put(crowdDN.getName(), m_CrowdEntry);
m_EntryCache.put(groupDn.getName(), groupEntry);
m_EntryCache.put(usersDn.getName(), usersEntry);

代码示例来源:origin: io.vertx/vertx-auth-shiro

/**
  * Main class.
  *
  * @param args Not used.
  */
 public static void main(String[] args) {
  try {
   File workDir = new File(System.getProperty("java.io.tmpdir") + "/server-work/" + UUID.randomUUID().toString());
   workDir.mkdirs();

   // Create the server
   EmbeddedADS ads = new EmbeddedADS(workDir);

   // Read an entry
   //Entry result = ads.service.getAdminSession().lookup(new DN("dc=foo,dc=com"));

   Entry result = ads.service.getAdminSession().lookup(new DN("ou=users,dc=foo,dc=com"));

   // And print it if available
   System.out.println("Found entry : " + result);

   // optionally we can start a server too
   ads.startServer();
  } catch (Exception e) {
   // Ok, we have something wrong going on ...
   e.printStackTrace();
  }
 }
}

代码示例来源:origin: org.apache.directory.shared/shared-ldif

DN restoredDn = (DN)((DN)newSuperior.clone()).add( newRdn ); 
  reverted.setDn( restoredDn );
reverted.setNewRdn( oldRdn.getName() );
  DN oldSuperior = ( DN ) newDn.clone();
  oldSuperior.remove( oldSuperior.size() - 1 );
  reverted.setNewSuperior( oldSuperior.getName() );

代码示例来源:origin: dwimberger/crowd-ldap-server

return true;
} else {
 int dnSize = dn.size();
   m_EntryCache.put(dn.getName(), m_CrowdEntry);
   return true;
  } else {
   m_EntryCache.put(dn.getName(), m_CrowdGroupsEntry);
   return true;
  } else if (isCrowdUsers(dn)) {
   m_EntryCache.put(dn.getName(), m_CrowdUsersEntry);
   return true;
  } else {
  DN prefix = dn.getPrefix(2);
  try {
   prefix.normalize(m_SchemaManager.getNormalizerMapping());
  } catch (Exception ex) {
   log.error("hasEntry()", ex);
   RDN rdn = dn.getRdn(2);
   String user = rdn.getNormValue();
   log.debug("user=" + user);
   ServerEntry userEntry = createUserEntry(dn);
   return (userEntry != null);
  } else if(isCrowdGroups(prefix)) {
   RDN rdn = dn.getRdn(2);
   String group = rdn.getNormValue();

相关文章