本文整理汇总了Java中org.apache.directory.shared.ldap.entry.ServerEntry类的典型用法代码示例。如果您正苦于以下问题:Java ServerEntry类的具体用法?Java ServerEntry怎么用?Java ServerEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerEntry类属于org.apache.directory.shared.ldap.entry包,在下文中一共展示了ServerEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpServer
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
@BeforeClass
public void setUpServer() throws Exception {
(server = EmbeddedLdapServer.newDefaultServer()).start();
connFactory = server.getConnectionFactory();
// first 100 users don't belong to any group
for (int i = 0; i < 100; i++) {
server.addDefaultLdapUser(i);
}
// next 200 users are members of group1/group2
final List<String> group1Members = new ArrayList<>(100);
final List<String> group2Members = new ArrayList<>(100);
for (int i = 100; i < 300; i++) {
final ServerEntry entry = server.addDefaultLdapUser(i, Pair.of("givenName", "gn-" + i));
if (i % 2 == 0) {
group1Members.add(entry.getDn().toString());
} else {
group2Members.add(entry.getDn().toString());
}
group1Members.add(entry.getDn().toString());
}
server.addDefaultLdapGroup("group1", group1Members);
server.addDefaultLdapGroup("group2", group2Members);
}
示例2: addDefaultLdapUser
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
/**
* Adds a new user which matches the default schema pattern, which is:
*
* <ul>
* <li>objectClass=inetOrgPerson
* <li>rdn - uid={id}
* <li>cn={name}
* <li>mail={mail}
* <li>sn={@literal <none>}
* <li>other.foreach(pair -> {pair.first}={pair.second})
* </ul>
*
* @return newly created and added entry instance
* @throws Exception when any error occurs
*/
public ServerEntry addDefaultLdapUser(String id, String name, String mail, Pair... other)
throws Exception {
final ServerEntry entry = newEntry("uid", id);
entry.put("objectClass", "inetOrgPerson");
entry.put("uid", id);
entry.put("cn", name);
entry.put("mail", mail);
entry.put("sn", "<none>");
for (Pair pair : other) {
if (pair.second instanceof byte[]) {
entry.put(pair.first.toString(), (byte[]) pair.second);
} else {
entry.put(pair.first.toString(), pair.second.toString());
}
}
addEntry(entry);
return entry;
}
示例3: addIndex
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
/**
* Add a new set of index on the given attributes.
*
* @param partition The partition on which we want to add index
* @param attrs The list of attributes to index
*/
private void addIndex(final Partition partition, final String... attrs) {
// Index some attributes on the apache partition
HashSet<Index<?, ServerEntry, Long>> indexedAttributes =
new HashSet<Index<?, ServerEntry, Long>>();
for (String attribute : attrs) {
indexedAttributes.add(
new JdbmIndex<String, ServerEntry>(attribute));
}
((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
示例4: addIndex
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
/**
* Add a new set of index on the given attributes
*
* @param partition
* The partition on which we want to add index
* @param attrs
* The list of attributes to index
*/
private void addIndex(Partition partition, String... attrs) {
// Index some attributes on the apache partition
HashSet<Index<?, ServerEntry, Long>> indexedAttributes = new HashSet<Index<?, ServerEntry, Long>>();
for (String attribute : attrs) {
indexedAttributes.add(new JdbmIndex<String, ServerEntry>(attribute));
}
((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
示例5: addObjectClasses
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
private static void addObjectClasses(ServerEntry serverEntry, List<String> objectClasses)
throws DirectoryServerException {
for (String objectClass : objectClasses) {
try {
serverEntry.add("objectClass", objectClass);
} catch (LdapException e) {
throwDirectoryServerException("Could not add class to partition " +
serverEntry.getDn().getName(), e);
}
}
}
示例6: addPartitionAttributes
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的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: addAdminPassword
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
private void addAdminPassword(ServerEntry adminEntry, String password,
PasswordAlgorithm algorithm,
final boolean kdcEnabled)
throws DirectoryServerException {
try {
String passwordToStore = "{" + algorithm.getAlgorithmName() + "}";
if (algorithm != PasswordAlgorithm.PLAIN_TEXT && !kdcEnabled) {
MessageDigest md = MessageDigest.getInstance(algorithm.getAlgorithmName());
md.update(password.getBytes());
byte[] bytes = md.digest();
String hash = Base64.encode(bytes);
passwordToStore = passwordToStore + hash;
} else {
if (kdcEnabled) {
logger.warn(
"KDC enabled. Enforcing passwords to be plain text. Cause - KDC " +
"cannot operate with hashed passwords.");
}
passwordToStore = password;
}
adminEntry.put("userPassword", passwordToStore.getBytes());
} catch (NoSuchAlgorithmException e) {
throwDirectoryServerException("Could not find matching hash algorithm - " +
algorithm.getAlgorithmName(), e);
}
}
示例8: addIndex
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
/**
* Add a new set of index on the given attributes
*
* @param partition The partition on which we want to add index
* @param attrs The list of attributes to index
*/
private void addIndex(Partition partition, String... attrs) {
// Index some attributes on the apache partition
HashSet<Index<?, ServerEntry, Long>> indexedAttributes = new HashSet<>();
for (String attribute : attrs) {
indexedAttributes.add(new JdbmIndex<String, ServerEntry>(attribute));
}
((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
示例9: initDirectoryService
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的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);
}
}
}
示例10: asUser
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
private static UserImpl asUser(ServerEntry entry) {
return new UserImpl(
entry.get("uid").get(0).toString(),
entry.get("mail").get(0).toString(),
entry.get("cn").get(0).toString());
}
示例11: newEntry
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
public ServerEntry newEntry(String name, String value, ServerEntry parent) throws Exception {
return service.newEntry(new DN(name + '=' + value + ',' + parent.getDn()));
}
示例12: initDirectoryService
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的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);
}
}
示例13: addAccessControlAttributes
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
private void addAccessControlAttributes(ServerEntry serverEntry)
throws LdapException {
serverEntry.add("administrativeRole", "accessControlSpecificArea");
}
示例14: createNewPartition
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的package包/类
private JdbmPartition createNewPartition(String partitionId, String partitionSuffix)
throws DirectoryServerException {
try {
JdbmPartition partition = new JdbmPartition();
String partitionDirectoryName = this.workingDirectory + File.separator + partitionId;
File partitionDirectory = new File(partitionDirectoryName);
partition.setId(partitionId);
partition.setSuffix(partitionSuffix);
partition.setPartitionDir(partitionDirectory);
Set<Index<?, ServerEntry, Long>> indexedAttrs =
new HashSet<Index<?, ServerEntry, Long>>();
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.1"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.2"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.3"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.4"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.5"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.6"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("1.3.6.1.4.1.18060.0.4.1.2.7"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("ou"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("dc"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("objectClass"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("cn"));
indexedAttrs.add(new JdbmIndex<String, ServerEntry>("uid"));
partition.setIndexedAttributes(indexedAttrs);
String message = MessageFormat.format(
"Partition created with following attributes, partition id - {0}, Partition " +
"domain - {1}, Partition working directory {2}", partitionId,
partitionSuffix, partitionDirectoryName);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
return partition;
} catch (LdapInvalidDnException e) {
String msg = "Could not add a new partition with partition id " + partitionId +
" and suffix " + partitionSuffix;
logger.error(msg, e);
throw new DirectoryServerException(msg, e);
}
}
示例15: initDirectoryService
import org.apache.directory.shared.ldap.entry.ServerEntry; //导入依赖的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);
}