use of javax.naming.directory.BasicAttributes in project perun by CESNET.
the class LdapConnectorImpl method createResource.
//------------------RESOURCE MODIFICATION METHODS----------------------------
public void createResource(Resource resource, String entityID) 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("perunResource");
// Add attributes
attributes.put(objClasses);
attributes.put("cn", resource.getName());
attributes.put("perunResourceId", String.valueOf(resource.getId()));
attributes.put("perunFacilityId", String.valueOf(resource.getFacilityId()));
attributes.put("perunVoId", String.valueOf(resource.getVoId()));
if (resource.getDescription() != null && !resource.getDescription().isEmpty())
attributes.put("description", resource.getDescription());
// get info about entityID attribute if exists
if (entityID != null)
attributes.put("entityID", entityID);
// Create the entry
try {
ldapTemplate.bind(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId())), null, attributes);
log.debug("New entry created in LDAP: Resource {} in Vo with Id=" + resource.getVoId() + " and Facility with ID=" + resource.getFacilityId() + ".", resource);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttributes in project perun by CESNET.
the class LdapConnectorImpl method addGroup.
//------------------GROUP MODIFICATION METHODS-------------------------------
public void addGroup(Group group) 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("perunGroup");
// Add attributes
attributes.put(objClasses);
attributes.put("cn", group.getName());
attributes.put("perunGroupId", String.valueOf(group.getId()));
attributes.put("perunUniqueGroupName", new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
attributes.put("perunVoId", String.valueOf(group.getVoId()));
if (group.getDescription() != null && !group.getDescription().isEmpty())
attributes.put("description", group.getDescription());
if (group.getParentGroupId() != null) {
attributes.put("perunParentGroup", "perunGroupId=" + group.getParentGroupId().toString() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
attributes.put("perunParentGroupId", group.getParentGroupId().toString());
}
// Create the entry
try {
ldapTemplate.bind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())), null, attributes);
log.debug("New entry created in LDAP: Group {} in Vo with Id=" + group.getVoId() + ".", group);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttributes in project perun by CESNET.
the class LdapConnectorImpl method createVo.
//--------------------------VO MODIFICATION METHODS---------------------------
public void createVo(Vo vo) throws InternalErrorException {
// Create a set of attributes for vo
Attributes voAttributes = new BasicAttributes();
// Create the objectclass to add
Attribute voObjClasses = new BasicAttribute("objectClass");
voObjClasses.add("top");
voObjClasses.add("organization");
voObjClasses.add("perunVO");
// Add attributes
voAttributes.put(voObjClasses);
voAttributes.put("o", vo.getShortName());
voAttributes.put("description", vo.getName());
voAttributes.put("perunVoId", String.valueOf(vo.getId()));
// Create the entires
try {
ldapTemplate.bind(getVoDNByVoId(String.valueOf(vo.getId())), null, voAttributes);
log.debug("New entry created in LDAP: Vo {}.", vo);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttributes in project nhin-d by DirectProject.
the class WSSmtpAgentConfigFunctional_Test method setUp.
/**
* Initialize the servers- LDAP and HTTP.
*/
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
// check for Windows... it doens't like file://<drive>... turns it into FTP
File file = new File("./src/test/resources/bundles/testBundle.p7b");
if (file.getAbsolutePath().contains(":/"))
filePrefix = "file:///";
else
filePrefix = "file:///";
CertCacheFactory.getInstance().flushAll();
/*
* Setup 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);
//
//
//
// add the lookupTestPublic
//
//
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"));
// 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 = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
if (stream == null)
throw new IOException("Failed to load ldif file");
importLdif(stream);
// setup the mock DNS SRV adapter
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 });
// create the web service and proxy
ConfigServiceRunner.startConfigService();
proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
}
use of javax.naming.directory.BasicAttributes in project nhin-d by DirectProject.
the class XMLSmtpAgentConfigFunctional_Test method setUp.
/**
* Initialize the server.
*/
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
CertCacheFactory.getInstance().flushAll();
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);
this.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();
// import the ldif file
InputStream stream = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
if (stream == null)
throw new IOException("Failed to load ldif file");
importLdif(stream);
}
Aggregations