@Override public void start() { if (isRunning()) { return; } try { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix); config.addAdditionalBindCredentials("uid=admin,ou=system", "secret"); config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port)); config.setEnforceSingleStructuralObjectClass(false); config.setEnforceAttributeSyntaxCompliance(true); DN dn = new DN(this.defaultPartitionSuffix); Entry entry = new Entry(dn); entry.addAttribute("objectClass", "top", "domain", "extensibleObject"); entry.addAttribute("dc", dn.getRDN().getAttributeValues()[0]); InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config); directoryServer.add(entry); importLdif(directoryServer); directoryServer.startListening(); this.port = directoryServer.getListenPort(); this.directoryServer = directoryServer; this.running = true; } catch (LDAPException ex) { throw new RuntimeException("Server startup failed", ex); } }
/** * {@inheritDoc} */ public Entry toEntry() { return new Entry(dn, attributes); }
/** * {@inheritDoc} */ public Entry toEntry() { return new Entry(dn, attributes); }
/** * Creates a new entry that is a duplicate of this entry. * * @return A new entry that is a duplicate of this entry. */ public Entry duplicate() { return new Entry(dn, schema, attributes.values()); }
/** * Creates a new entry that is a duplicate of this entry. * * @return A new entry that is a duplicate of this entry. */ public Entry duplicate() { return new Entry(dn, schema, attributes.values()); }
/** * Retrieves the entry that would be created by this add change record. * * @return The entry that would be created by this add change record. */ public Entry getEntryToAdd() { return new Entry(getDN(), attributes); }
/** * Retrieves the entry that would be created by this add change record. * * @return The entry that would be created by this add change record. */ public Entry getEntryToAdd() { return new Entry(getDN(), attributes); }
/** * Converts this compact entry to a full entry. * * @return The entry created from this compact entry. */ public Entry toEntry() { final Attribute[] attrs = new Attribute[attributes.length]; for (int i=0; i < attributes.length; i++) { attrs[i] = attributes[i].toAttribute(); } return new Entry(dn, attrs); }
/** * Converts this compact entry to a full entry. * * @return The entry created from this compact entry. */ public Entry toEntry() { final Attribute[] attrs = new Attribute[attributes.length]; for (int i=0; i < attributes.length; i++) { attrs[i] = attributes[i].toAttribute(); } return new Entry(dn, attrs); }
/** * Retrieves an {@code Entry} representation of this change record. This is * intended only for internal use by the LDIF reader when operating * asynchronously in the case that it is not possible to know ahead of time * whether a user will attempt to read an LDIF record by {@code readEntry} or * {@code readChangeRecord}. In the event that the LDIF file has an entry * whose first attribute is "changetype" and the client wants to read it as * an entry rather than a change record, then this may be used to generate an * entry representing the change record. * * @return The entry representation of this change record. * * @throws LDIFException If this change record cannot be represented as a * valid entry. */ final Entry toEntry() throws LDIFException { return new Entry(toLDIF()); }
/** * Retrieves an {@code Entry} representation of this change record. This is * intended only for internal use by the LDIF reader when operating * asynchronously in the case that it is not possible to know ahead of time * whether a user will attempt to read an LDIF record by {@code readEntry} or * {@code readChangeRecord}. In the event that the LDIF file has an entry * whose first attribute is "changetype" and the client wants to read it as * an entry rather than a change record, then this may be used to generate an * entry representing the change record. * * @return The entry representation of this change record. * * @throws LDIFException If this change record cannot be represented as a * valid entry. */ final Entry toEntry() throws LDIFException { return new Entry(toLDIF()); }
/** * Retrieves an {@link Entry} object that is the equivalent of this LDAP * entry. * * @return The {@code Entry} object that is the equivalent of this LDAP * entry. */ public final Entry toEntry() { final ArrayList<Attribute> attrs = new ArrayList<Attribute>(attributeSet.size()); final Enumeration<LDAPAttribute> attrEnum = attributeSet.getAttributes(); while (attrEnum.hasMoreElements()) { attrs.add(attrEnum.nextElement().toAttribute()); } return new Entry(dn, attrs); }
/** * {@inheritDoc} * * @see com.unboundid.ldap.listener.interceptor.InMemoryOperationInterceptor#processSearchResult(com.unboundid.ldap.listener.interceptor.InMemoryInterceptedSearchResult) */ @Override public void processSearchResult ( InMemoryInterceptedSearchResult result ) { String base = result.getRequest().getBaseDN(); Entry e = new Entry(base); try { sendResult(result, base, e); } catch ( Exception e1 ) { e1.printStackTrace(); } }
/** * {@inheritDoc} */ public ObjectPair<SearchResultEntryProtocolOp,Control[]> transformEntry( final int messageID, final SearchResultEntryProtocolOp entry, final Control[] controls) { final StringBuilder b = getBuffer(); appendHeader(b, messageID); b.append(" Search Result Entry Protocol Op:").append(EOL); final Entry e = new Entry(entry.getDN(), entry.getAttributes()); final String[] ldifLines = e.toLDIF(80); for (final String line : ldifLines) { b.append(" ").append(line).append(EOL); } appendControls(b, controls); logHandler.publish(new LogRecord(Level.INFO, b.toString())); return new ObjectPair<SearchResultEntryProtocolOp,Control[]>(entry, controls); }
private void creatOrgUnits(LDAPConnection conn) throws LDAPException { String peopleDn = config.getLdapUserBaseDN(); if (conn.getEntry(peopleDn) == null) { Entry entry = new Entry(peopleDn); entry.addAttribute("objectClass", "top"); entry.addAttribute("objectClass", "organizationalUnit"); conn.add(entry); } String groupDn = config.getLdapGroupsBaseDN(); if (conn.getEntry(groupDn) == null) { Entry entry = new Entry(groupDn); entry.addAttribute("objectClass", "top"); entry.addAttribute("objectClass", "organizationalUnit"); conn.add(entry); } }
protected void startExternalAuthenticationServer() throws Exception { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com"); config.setListenerConfigs(ldapListenerConfig); Entry defaultEntry = new Entry( "dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"); Entry userEntry = new Entry( "dn: uid=user,dc=example,dc=com", "objectClass: inetorgperson", "cn: admin", "sn: User", "uid: user", "userPassword: realtime"); ldapServer = new InMemoryDirectoryServer(config); ldapServer.addEntries(defaultEntry, userEntry); ldapServer.startListening(); }
/** * {@inheritDoc} */ @Override() public int hashCode() { try { int hashCode = getParsedDN().hashCode(); for (final Attribute a : attributes) { hashCode += a.hashCode(); } return hashCode; } catch (final Exception e) { debugException(e); return new Entry(getDN(), attributes).hashCode(); } }
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port) throws Exception { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig( defaultPartitionSuffix); config.addAdditionalBindCredentials("uid=admin,ou=system", "secret"); config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port)); config.setEnforceSingleStructuralObjectClass(false); config.setEnforceAttributeSyntaxCompliance(true); Entry entry = new Entry(new DN(defaultPartitionSuffix)); entry.addAttribute("objectClass", "top", "domain", "extensibleObject"); entry.addAttribute("dc", defaultPartitionName); InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config); directoryServer.add(entry); directoryServer.startListening(); return new EmbeddedLdapServer(directoryServer); }
private void initializeEmbeddedLDAPServer() throws Exception { log.info("Creating Embedded LDAP server"); InMemoryListenerConfig inMemoryListenerConfig = InMemoryListenerConfig.createLDAPConfig("default", ldapPort); InMemoryDirectoryServerConfig directoryServerConfig = new InMemoryDirectoryServerConfig(new DN(baseDN)); directoryServerConfig.setListenerConfigs(inMemoryListenerConfig); directoryServerConfig.addAdditionalBindCredentials(securityPrincipal, securityCredentials); ldapServer = new InMemoryDirectoryServer(directoryServerConfig); ldapServer.startListening(); Entry wso2Entry = new Entry(baseDN); wso2Entry.addAttribute("objectClass", "dcObject"); wso2Entry.addAttribute("objectClass", "organizationalUnit"); wso2Entry.addAttribute("ou", "WSO2"); wso2Entry.addAttribute("dc", "WSO2"); ldapServer.add(wso2Entry); Entry entry = new Entry(userBase); entry.addAttribute("objectClass", "organizationalUnit"); ldapServer.add(entry); }
@Override public void createAccount(LdapAccount account) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { String entryDN = getAccountDN(account); log.info("Creating user with DN {}", entryDN); Entry entry = new Entry(entryDN); entry.addAttribute("objectClass", "inetOrgPerson"); for (String email : account.getEmails()) { entry.addAttribute("mail", email); } entry.addAttribute("givenName", account.getGivenName()); entry.addAttribute("sn", account.getFamilyName()); entry.addAttribute("cn", account.getName()); entry.addAttribute("employeeNumber", account.getSubject()); entry.addAttribute("userPassword", account.getPassword()); entry.addAttribute("employeeType", account.getRole().toString()); conn.add(entry); } catch (LDAPException e) { throw new LdapSystemException(e); } }