use of javax.naming.directory.Attribute in project OpenAM by OpenRock.
the class SMSAuditor method deriveFinalState.
/**
* Uses a series of modifications to establish the final state of a set of attributes, based on their original
* value.
* @param mods The list of modifications made
* @return A map representing the final state
*/
private Map<String, Object> deriveFinalState(ModificationItem[] mods) {
Map<String, Object> finalState = new CaseInsensitiveHashMap<>(getInitialState());
for (int i = 0; i < mods.length; i++) {
Attribute currentAttr = mods[i].getAttribute();
if (mods[i].getModificationOp() == DirContext.REMOVE_ATTRIBUTE) {
finalState.remove(currentAttr.getID());
} else {
HashSet values = new HashSet();
for (int j = 0; j < currentAttr.size(); j++) {
try {
values.add(currentAttr.get(j));
} catch (NamingException e) {
//no operation here
}
}
finalState.put(currentAttr.getID(), values);
}
}
return finalState;
}
use of javax.naming.directory.Attribute in project OpenAM by OpenRock.
the class CertUtils method getAttributeValue.
/**
* Retrieves a given attribute value from the provided {@link X500Principal} even if the attribute was enclosed in
* a multi-valued RDN.
*
* @param principal The principal to retrieve the value from.
* @param attributeName The non-null name of the attribute to retrieve.
* @return The attribute value from the principal.
*/
public static String getAttributeValue(X500Principal principal, String attributeName) {
try {
LdapName ldapName = new LdapName(principal.getName(X500Principal.RFC2253, OID_MAP));
for (Rdn rdn : ldapName.getRdns()) {
Attributes attrs = rdn.toAttributes();
NamingEnumeration<? extends Attribute> values = attrs.getAll();
while (values.hasMoreElements()) {
Attribute attr = values.next();
if (attributeName.equalsIgnoreCase(attr.getID())) {
return attr.get() == null ? null : attr.get().toString();
}
}
}
} catch (NamingException ne) {
DEBUG.warning("A naming error occurred while trying to retrieve " + attributeName + " from principal: " + principal, ne);
}
return null;
}
use of javax.naming.directory.Attribute in project nhin-d by DirectProject.
the class RESTSmtpAgentConfigFunctional_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());
certService = new DefaultCertificateService(ConfigServiceRunner.getRestAPIBaseURL(), HttpClientFactory.createHttpClient(), new OpenServiceSecurityManager());
}
use of javax.naming.directory.Attribute in project uPortal by Jasig.
the class LDAPGroupStore method processLdapResults.
protected void processLdapResults(NamingEnumeration results, ArrayList keys) {
//long loop1=System.currentTimeMillis();
try {
while (results.hasMore()) {
//long loop2 = System.currentTimeMillis();
//long cast1=System.currentTimeMillis();
//looping=looping+loop2-loop1;
SearchResult result = (SearchResult) results.next();
//long cast2 = System.currentTimeMillis();
//long get1 = System.currentTimeMillis();
Attributes ldapattribs = result.getAttributes();
//long get2 = System.currentTimeMillis();
//long set1 = System.currentTimeMillis();
Attribute attrib = ldapattribs.get(keyfield);
if (attrib != null) {
keys.add(String.valueOf(attrib.get()).toLowerCase());
}
//long set2 = System.currentTimeMillis();
//loop1=System.currentTimeMillis();
//casting=casting+cast2-cast1;
//setting=setting+set2-set1;
//getting=getting+get2-get1;
}
} catch (NamingException nex) {
log.error("LDAPGroupStore: error processing results", nex);
} finally {
try {
results.close();
} catch (Exception e) {
}
}
//long time5 = System.currentTimeMillis();
//System.out.println("Result processing took "+(time5-time1)+": "+getting+" for getting, "
// +setting+" for setting, "+casting+" for casting, "+looping+" for looping,"
// +(time5-loop1)+" for closing");
}
use of javax.naming.directory.Attribute in project uPortal by Jasig.
the class SimpleAttributesMapper method mapFromAttributes.
/*
* Public API.
*/
public Object mapFromAttributes(Attributes attr) {
// Assertions.
if (keyAttributeName == null) {
String msg = "The property 'keyAttributeName' must be set.";
throw new IllegalStateException(msg);
}
if (groupNameAttributeName == null) {
String msg = "The property 'groupNameAttributeName' must be set.";
throw new IllegalStateException(msg);
}
if (membershipAttributeName == null) {
String msg = "The property 'membershipAttributeName' must be set.";
throw new IllegalStateException(msg);
}
if (log.isDebugEnabled()) {
String msg = "SimpleAttributesMapper.mapFromAttributes() :: settings: keyAttributeName='" + keyAttributeName + "', groupNameAttributeName='" + groupNameAttributeName + "', groupNameAttributeName='" + groupNameAttributeName + "'";
log.debug(msg);
}
LdapRecord rslt;
try {
String key = (String) attr.get(keyAttributeName).get();
String groupName = (String) attr.get(groupNameAttributeName).get();
IEntityGroup g = new EntityTestingGroupImpl(key, IPerson.class);
g.setCreatorID("System");
g.setName(groupName);
g.setDescription(GROUP_DESCRIPTION);
List<String> membership = new LinkedList<String>();
Attribute m = attr.get(membershipAttributeName);
if (m != null) {
for (Enumeration<?> en = m.getAll(); en.hasMoreElements(); ) {
membership.add((String) en.nextElement());
}
}
rslt = new LdapRecord(g, membership);
if (log.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Record Details:").append("\n\tkey=").append(key).append("\n\tgroupName=").append(groupName).append("\n\tmembers:");
for (String s : membership) {
msg.append("\n\t\t").append(s);
}
log.debug(msg.toString());
}
} catch (Throwable t) {
log.error("Error in SimpleAttributesMapper", t);
String msg = "SimpleAttributesMapper failed to create a LdapRecord " + "from the specified Attributes: " + attr;
throw new RuntimeException(msg, t);
}
return rslt;
}
Aggregations