本文整理汇总了Java中org.apache.directory.shared.ldap.name.DN类的典型用法代码示例。如果您正苦于以下问题:Java DN类的具体用法?Java DN怎么用?Java DN使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DN类属于org.apache.directory.shared.ldap.name包,在下文中一共展示了DN类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EmbeddedLdapServer
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
public EmbeddedLdapServer(
File workingDir,
String partitionDn,
String partitionId,
int port,
boolean enableChangelog,
boolean allowAnonymousAccess,
long maxSizeLimit)
throws Exception {
requireNonNull(partitionDn, "Required non-null partition dn");
requireNonNull(partitionId, "Required non-null partition id");
this.workingDir = workingDir;
this.baseDn = new DN(partitionDn);
this.port = port > 0 ? port : PORT_SERVICE.acquire();
this.url = "ldap://localhost:" + this.port;
ldapServer = new LdapServer();
ldapServer.setTransports(new TcpTransport(this.port));
if (maxSizeLimit > 0) {
ldapServer.setMaxSizeLimit(maxSizeLimit);
}
service =
initDirectoryService(
workingDir, partitionId, partitionDn, enableChangelog, allowAnonymousAccess);
ldapServer.setDirectoryService(service);
}
示例2: main
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/**
* 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();
}
}
示例3: addAttribute
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
public void addAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification addValue = new ClientModification(
ModificationOperation.ADD_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(addValue));
}
示例4: removeAttribute
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
public void removeAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification removeValue = new ClientModification(
ModificationOperation.REMOVE_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(removeValue));
}
示例5: contextInitialized
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/**
* Startup ApacheDS embedded.
*
* @param sce ServletContext event
*/
@Override
public void contextInitialized(final ServletContextEvent sce) {
File workDir = (File) sce.getServletContext().getAttribute(
"javax.servlet.context.tempdir");
workDir = new File(workDir, "server-work");
if (!workDir.mkdirs()) {
throw new RuntimeException("Could not create " + workDir.
getAbsolutePath());
}
Entry result;
try {
initDirectoryService(sce.getServletContext(), workDir);
server = new LdapServer();
server.setTransports(new TcpTransport(Integer.valueOf(
sce.getServletContext().
getInitParameter("testds.port"))));
server.setDirectoryService(service);
server.start();
// store directoryService in context to provide it to servlets etc.
sce.getServletContext().setAttribute(DirectoryService.JNDI_KEY,
service);
result = service.getAdminSession().lookup(new DN("o=isp"));
} catch (Exception e) {
sce.getServletContext().log("Fatal error in context init", e);
throw new RuntimeException(e);
}
if (result == null) {
throw new RuntimeException("Base DN not found");
} else {
sce.getServletContext().log(
"ApacheDS startup completed succesfully");
}
}
示例6: addPartitionAttributes
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
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);
}
}
示例7: initDirectoryService
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/**
* Initialize the server. It creates the partition, injects the context
* entries for the created partitions, and loads an LDIF file (
* {@link #ldifLoadFile}) for initial entries.
*
* @param workDir
* the directory to be used for storing the data
* @throws Exception
* if there were some problems while initializing the system
*/
private void initDirectoryService(File workDir) throws Exception {
// Initialize the LDAP service
service = new DefaultDirectoryService();
service.setWorkingDirectory(workDir);
// first load the schema
initSchemaPartition();
// then the system partition
// this is a MANDATORY partition
Partition systemPartition = addPartition("system",
ServerDNConstants.SYSTEM_DN);
service.setSystemPartition(systemPartition);
// create the partition for testing
Partition testingPartition = addPartition("ldapTesting",
"ou=ldapTesting,dc=pune,dc=gemstone,dc=com");
// Disable the shutdown hook
service.setShutdownHookEnabled(false);
// Disable the ChangeLog system
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
// And start the service
service.startup();
// inject the entry for testing
if (!service.getAdminSession().exists(testingPartition.getSuffixDn())) {
DN dnTesting = new DN("ou=ldapTesting,dc=pune,dc=gemstone,dc=com");
ServerEntry entryTesting = service.newEntry(dnTesting);
entryTesting.add("objectClass", "top", "domain", "extensibleObject");
entryTesting.add("dc", "pune");
service.getAdminSession().add(entryTesting);
}
// load schema from LDIF
if (ldifLoadFile != null) {
LdifFileLoader ldifLoader = new LdifFileLoader(
service.getAdminSession(), ldifLoadFile);
int numLoaded = ldifLoader.execute();
if (numLoaded <= 0) {
throw new Exception(
"Failed to load any entries from " + ldifLoadFile);
} else {
System.out.println(
"LDAP loaded " + numLoaded + " entries from " + ldifLoadFile);
}
}
}
示例8: newEntry
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
public ServerEntry newEntry(String name, String value, ServerEntry parent) throws Exception {
return service.newEntry(new DN(name + '=' + value + ',' + parent.getDn()));
}
示例9: removeEntry
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/** Removes an entity with rdn {name}={value} in base dn. */
public void removeEntry(String name, String value) throws Exception {
service.getAdminSession().delete(new DN(name + '=' + value + ',' + baseDn));
}
示例10: modify
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/** Applies given modifications on the entity with rdn {rdnKey}={rdnValue} in base dn. */
public void modify(String rdnKey, String rdnValue, Modification... mods) throws Exception {
service
.getAdminSession()
.modify(new DN(rdnKey + '=' + rdnValue + ',' + baseDn), Arrays.asList(mods));
}
示例11: initDirectoryService
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/**
* Initialize the server. It creates the partition, adds the index, and
* injects the context entries for the created partitions.
*
* @param workDir the directory to be used for storing the data
* @throws Exception if there were some problems while initializing
*/
private void initDirectoryService(final ServletContext servletContext,
final File workDir)
throws Exception {
// Initialize the LDAP service
service = new DefaultDirectoryService();
service.setWorkingDirectory(workDir);
// first load the schema
initSchemaPartition(servletContext);
// then the system partition
// this is a MANDATORY partition
Partition systemPartition = addPartition("system",
ServerDNConstants.SYSTEM_DN);
service.setSystemPartition(systemPartition);
// Disable the ChangeLog system
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
// Now we can create as many partitions as we need
Partition ispPartition = addPartition("isp", "o=isp");
addIndex(ispPartition, "objectClass", "ou", "uid");
// And start the service
service.startup();
// Inject the foo root entry if it does not already exist
try {
service.getAdminSession().lookup(ispPartition.getSuffixDn());
} catch (LdapException lnnfe) {
DN dnIsp = new DN("o=isp");
ServerEntry rootEntry = service.newEntry(dnIsp);
rootEntry.add("objectClass", "top", "organization");
rootEntry.add("o", "isp");
service.getAdminSession().add(rootEntry);
DN dnPeople = new DN("ou=People,o=isp");
ServerEntry peopleEntry = service.newEntry(dnPeople);
peopleEntry.add("objectClass", "top", "organizationalUnit");
peopleEntry.add("ou", "People");
service.getAdminSession().add(peopleEntry);
}
}
示例12: initDirectoryService
import org.apache.directory.shared.ldap.name.DN; //导入依赖的package包/类
/**
* Initialize the server. It creates the partition, adds the index, and
* injects the context entries for the created partitions.
*
* @param workDir the directory to be used for storing the data
* @throws Exception if there were some problems while initializing the system
*/
private void initDirectoryService(File workDir) throws Exception {
// Initialize the LDAP service
service = new DefaultDirectoryService();
service.setWorkingDirectory(workDir);
// first load the schema
initSchemaPartition();
// then the system partition
// this is a MANDATORY partition
Partition systemPartition = addPartition("system", ServerDNConstants.SYSTEM_DN);
service.setSystemPartition(systemPartition);
// Disable the ChangeLog system
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
// Now we can create as many partitions as we need
// Create some new partitions named 'foo', 'bar' and 'apache'.
Partition fooPartition = addPartition("foo", "dc=foo,dc=com");
// Index some attributes on the apache partition
addIndex(fooPartition, "objectClass", "ou", "uid");
// And start the service
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);
}