use of javax.naming.directory.Attributes in project nhin-d by DirectProject.
the class LDAPResearchTest method testDummy.
@SuppressWarnings("unchecked")
public void testDummy() throws Exception {
CertCacheFactory.getInstance().flushAll();
DirContext dirContext = createContext("cn=lookupTest");
Attributes attributes = dirContext.getAttributes("");
assertNotNull(attributes);
NamingEnumeration<Attribute> namingEnum = (NamingEnumeration<Attribute>) attributes.getAll();
while (namingEnum.hasMoreElements()) {
Attribute attr = namingEnum.nextElement();
System.out.println("Name: " + attr.getID() + "\r\nValue: " + attr.get() + "\r\n\r\n");
}
Set<SearchResult> results = searchDNs("(email=gm2552@cerner.com)", "", "ou=privKeys, ou=cerner, ou=com", SearchControls.SUBTREE_SCOPE, dirContext);
for (SearchResult result : results) {
System.out.println(result.getName());
// get the priv cert
String privKey = (String) result.getAttributes().get("privKeyStore").get();
System.out.println("Privkey BASE64: " + privKey);
}
}
use of javax.naming.directory.Attributes in project nhin-d by DirectProject.
the class LDAPPublicCertUtil_ldapSearch_Test method setUp.
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
// create the LDAP server
MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
pcfg.setName("lookupTestPublic");
pcfg.setSuffix("cn=lookupTestPublic");
// 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"));
Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
configuration.setBootstrapSchemas(schemas);
mockLookup = mock(Lookup.class);
LookupFactory.getFactory().addOverrideImplementation(mockLookup);
super.setUp();
}
use of javax.naming.directory.Attributes in project midpoint by Evolveum.
the class BasicExpressionFunctions method determineLdapSingleAttributeValue.
// We cannot have Collection<String> here. The generic type information will disappear at runtime and the scripts can pass
// anything that they find suitable. E.g. XPath is passing elements
public String determineLdapSingleAttributeValue(String dn, String attributeName, Collection<?> values) throws NamingException {
if (values == null || values.isEmpty()) {
return null;
}
Collection<String> stringValues = null;
// Determine item type, try to convert to strings
Object firstElement = values.iterator().next();
if (firstElement instanceof String) {
stringValues = (Collection) values;
} else if (firstElement instanceof Element) {
stringValues = new ArrayList<String>(values.size());
for (Object value : values) {
Element element = (Element) value;
stringValues.add(element.getTextContent());
}
} else {
throw new IllegalArgumentException("Unexpected value type " + firstElement.getClass());
}
if (stringValues.size() == 1) {
return stringValues.iterator().next();
}
if (StringUtils.isBlank(dn)) {
throw new IllegalArgumentException("No dn argument specified, cannot determine which of " + values.size() + " values to use");
}
LdapName parsedDn = new LdapName(dn);
for (int i = 0; i < parsedDn.size(); i++) {
Rdn rdn = parsedDn.getRdn(i);
Attributes rdnAttributes = rdn.toAttributes();
NamingEnumeration<String> rdnIDs = rdnAttributes.getIDs();
while (rdnIDs.hasMore()) {
String rdnID = rdnIDs.next();
Attribute attribute = rdnAttributes.get(rdnID);
if (attributeName.equals(attribute.getID())) {
for (int j = 0; j < attribute.size(); j++) {
Object value = attribute.get(j);
if (stringValues.contains(value)) {
return (String) value;
}
}
}
}
}
// Fallback. No values in DN. Just return the first alphabetically-wise value.
return Collections.min(stringValues);
}
use of javax.naming.directory.Attributes 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.Attributes 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