use of javax.naming.directory.BasicAttributes in project camel by apache.
the class SpringLdapProducerTest method testBind.
@Test
public void testBind() throws Exception {
String dn = "some dn";
BasicAttributes attributes = new BasicAttributes();
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage();
Map<String, Object> body = new HashMap<String, Object>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.ATTRIBUTES, attributes);
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.BIND);
processBody(exchange, in, body);
verify(ldapTemplate).bind(eq(dn), isNull(), eq(attributes));
}
use of javax.naming.directory.BasicAttributes in project jmeter by apache.
the class LDAPSampler method getUserAttributes.
/**
* Collect all the value from the table (Arguments), using this create the
* basicAttributes. This will create the Basic Attributes for the User
* defined TestCase for Add Test.
*
* @return the BasicAttributes
*/
private BasicAttributes getUserAttributes() {
//$NON-NLS-1$
BasicAttribute basicattribute = new BasicAttribute("objectclass");
//$NON-NLS-1$
basicattribute.add("top");
//$NON-NLS-1$
basicattribute.add("person");
//$NON-NLS-1$
basicattribute.add("organizationalPerson");
//$NON-NLS-1$
basicattribute.add("inetOrgPerson");
BasicAttributes attrs = new BasicAttributes(true);
attrs.put(basicattribute);
BasicAttribute attr;
for (JMeterProperty jMeterProperty : getArguments()) {
Argument item = (Argument) jMeterProperty.getObjectValue();
attr = getBasicAttribute(item.getName(), item.getValue());
attrs.put(attr);
}
return attrs;
}
use of javax.naming.directory.BasicAttributes in project karaf by apache.
the class LdapCacheTest method testAdminLogin.
@Test
public void testAdminLogin() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPLoginModule module = new LDAPLoginModule();
CallbackHandler cb = new NamePasswordCallbackHandler("admin", "admin123");
Subject subject = new Subject();
module.initialize(subject, cb, null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
assertTrue(module.login());
assertTrue(module.commit());
assertEquals(2, subject.getPrincipals().size());
boolean foundUser = false;
boolean foundRole = false;
for (Principal pr : subject.getPrincipals()) {
if (pr instanceof UserPrincipal) {
assertEquals("admin", pr.getName());
foundUser = true;
} else if (pr instanceof RolePrincipal) {
assertEquals("admin", pr.getName());
foundRole = true;
}
}
assertTrue(foundUser);
assertTrue(foundRole);
assertTrue(module.logout());
assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());
DirContext context = new LDAPCache(new LDAPOptions(options)).open();
// Make "admin" user a member of a new "another" group
// dn: cn=admin,ou=groups,dc=example,dc=com
// objectClass: top
// objectClass: groupOfNames
// cn: admin
// member: cn=admin,ou=people,dc=example,dc=com
Attributes entry = new BasicAttributes();
entry.put(new BasicAttribute("cn", "another"));
Attribute oc = new BasicAttribute("objectClass");
oc.add("top");
oc.add("groupOfNames");
entry.put(oc);
Attribute mb = new BasicAttribute("member");
mb.add("cn=admin,ou=people,dc=example,dc=com");
entry.put(mb);
context.createSubcontext("cn=another,ou=groups,dc=example,dc=com", entry);
Thread.sleep(100);
module = new LDAPLoginModule();
subject = new Subject();
module.initialize(subject, cb, null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
assertTrue(module.login());
assertTrue(module.commit());
assertEquals("Postcondition", 3, subject.getPrincipals().size());
}
use of javax.naming.directory.BasicAttributes in project jackrabbit-oak by apache.
the class InternalLdapServer method addMember.
public void addMember(String groupDN, String memberDN) throws Exception {
LdapContext ctxt = getWiredContext();
BasicAttributes attrs = new BasicAttributes();
attrs.put("member", memberDN);
ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs);
}
use of javax.naming.directory.BasicAttributes in project nhin-d by DirectProject.
the class LDAPCertificateStore_functional_test method setUp.
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
// create the LDAP server
MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
pcfg.setName("lookupTest");
pcfg.setSuffix("cn=lookupTest");
// Create some indices
Set<String> indexedAttrs = new HashSet<String>();
indexedAttrs.add("objectClass");
indexedAttrs.add("cn");
pcfg.setIndexedAttributes(indexedAttrs);
// Create a first entry associated to the partition
Attributes attrs = new BasicAttributes(true);
// First, the objectClass attribute
Attribute attr = new BasicAttribute("objectClass");
attr.add("top");
attrs.put(attr);
// Associate this entry to the partition
pcfg.setContextEntry(attrs);
// As we can create more than one partition, we must store
// each created partition in a Set before initialization
Set<MutablePartitionConfiguration> pcfgs = new HashSet<MutablePartitionConfiguration>();
pcfgs.add(pcfg);
configuration.setContextPartitionConfigurations(pcfgs);
configuration.setWorkingDirectory(new File("LDAP-TEST"));
// add the private key schema
///
Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
schemas.add(new PrivkeySchema());
configuration.setBootstrapSchemas(schemas);
super.setUp();
}
Aggregations