use of javax.naming.directory.BasicAttributes in project perun by CESNET.
the class LdapConnectorImpl method createUser.
//-----------------------USER MODIFICATION METHODS----------------------------
public void createUser(User user) throws InternalErrorException {
// Create a set of attributes
Attributes attributes = new BasicAttributes();
// Create the objectclass to add
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("person");
objClasses.add("organizationalPerson");
objClasses.add("inetOrgPerson");
objClasses.add("perunUser");
objClasses.add("tenOperEntry");
objClasses.add("inetUser");
String firstName = user.getFirstName();
String lastName = user.getLastName();
if (firstName == null)
firstName = "";
if (lastName == null || lastName.isEmpty())
lastName = "N/A";
// Add attributes
attributes.put(objClasses);
attributes.put("entryStatus", "active");
attributes.put("sn", lastName);
attributes.put("cn", firstName + " " + lastName);
if (!firstName.isEmpty())
attributes.put("givenName", firstName);
attributes.put("perunUserId", String.valueOf(user.getId()));
if (user.isServiceUser())
attributes.put("isServiceUser", "1");
else
attributes.put("isServiceUser", "0");
if (user.isSponsoredUser())
attributes.put("isSponsoredUser", "1");
else
attributes.put("isSponsoredUser", "0");
// Create the entry
try {
ldapTemplate.bind(getUserDN(String.valueOf(user.getId())), null, attributes);
log.debug("New entry created in LDAP: User {} in Group with Id=" + user.getId() + ".", user);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
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 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();
}
use of javax.naming.directory.BasicAttributes in project nhin-d by DirectProject.
the class LdapCertificateStoreTest method setUp.
/**
* Initialize the server.
*/
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
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);
// Create the public LDAP partition
pcfg = new MutablePartitionConfiguration();
pcfg.setName("lookupTestPublic");
pcfg.setSuffix("cn=lookupTestPublic");
// Create some indices
indexedAttrs = new HashSet<String>();
indexedAttrs.add("objectClass");
indexedAttrs.add("cn");
pcfg.setIndexedAttributes(indexedAttrs);
// Create a first entry associated to the partition
attrs = new BasicAttributes(true);
// First, the objectClass 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
pcfgs.add(pcfg);
configuration.setContextPartitionConfigurations(pcfgs);
this.configuration.setWorkingDirectory(new File("LDAP-TEST"));
/*MutableAuthenticatorConfiguration authConfig = new MutableAuthenticatorConfiguration();
this.configuration.setAuthenticatorConfigurations(arg0)
*/
// add the private key schema
///
Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
schemas.add(new PrivkeySchema());
configuration.setBootstrapSchemas(schemas);
super.setUp();
// import the ldif file
InputStream stream = LDAPResearchTest.class.getClassLoader().getResourceAsStream("ldifs/privCertsOnly.ldif");
if (stream == null)
throw new IOException("Failed to load ldif file");
importLdif(stream);
mockLookup = mock(Lookup.class);
LookupFactory.getFactory().addOverrideImplementation(mockLookup);
SRVRecord srvRecord = new SRVRecord(new Name("_ldap._tcp.example.com."), DClass.IN, 3600, 0, 1, port, new Name("localhost."));
when(mockLookup.run()).thenReturn(new Record[] { srvRecord });
CertCacheFactory.getInstance().flushAll();
}
Aggregations