use of javax.naming.directory.BasicAttributes in project iaf by ibissource.
the class LdapSender method parseAttributesFromMessage.
/**
* Digests the input message and creates a <code>BasicAttributes</code> object, containing <code>BasicAttribute</code> objects,
* which represent the attributes of the specified entry.
*
* <pre>
* BasicAttributes implements Attributes
* contains
* BasicAttribute implements Attribute
* </pre>
*
* @see javax.naming.directory.Attributes
* @see javax.naming.directory.BasicAttributes
* @see javax.naming.directory.Attribute
* @see javax.naming.directory.BasicAttribute
*/
private Attributes parseAttributesFromMessage(String message) throws SenderException {
Digester digester = new Digester();
digester.addObjectCreate("*/attributes", BasicAttributes.class);
digester.addFactoryCreate("*/attributes/attribute", BasicAttributeFactory.class);
digester.addSetNext("*/attributes/attribute", "put");
digester.addCallMethod("*/attributes/attribute/value", "add", 0);
try {
return (Attributes) digester.parse(new StringReader(message));
} catch (Exception e) {
throw new SenderException("[" + this.getClass().getName() + "] exception in digesting", e);
}
}
use of javax.naming.directory.BasicAttributes in project iaf by ibissource.
the class LdapSender method performOperationCreate.
private String performOperationCreate(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException {
if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) {
String result = null;
NamingEnumeration na = attrs.getAll();
while (na.hasMoreElements()) {
Attribute a = (Attribute) na.nextElement();
log.debug("Create attribute: " + a.getID());
NamingEnumeration values;
try {
values = a.getAll();
} catch (NamingException e1) {
storeLdapException(e1, prc);
throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1);
}
while (values.hasMoreElements()) {
Attributes partialAttrs = new BasicAttributes();
Attribute singleValuedAttribute;
String id = a.getID();
Object value = values.nextElement();
if (log.isDebugEnabled()) {
if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) {
log.debug("Create value: ***");
} else {
log.debug("Create value: " + value);
}
}
if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) {
singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value));
} else {
singleValuedAttribute = new BasicAttribute(id, value);
}
partialAttrs.put(singleValuedAttribute);
DirContext dirContext = null;
try {
dirContext = getDirContext(paramValueMap);
dirContext.modifyAttributes(entryName, DirContext.ADD_ATTRIBUTE, partialAttrs);
} catch (NamingException e) {
// [LDAP: error code 20 - Attribute Or Value Exists]
if (e.getMessage().startsWith("[LDAP: error code 20 - ")) {
if (log.isDebugEnabled())
log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
result = DEFAULT_RESULT_CREATE_OK;
} else {
storeLdapException(e, prc);
throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
}
} finally {
closeDirContext(dirContext);
}
}
}
if (result != null) {
return result;
}
return DEFAULT_RESULT;
} else {
DirContext dirContext = null;
try {
if (unicodePwd) {
Enumeration enumeration = attrs.getIDs();
while (enumeration.hasMoreElements()) {
String id = (String) enumeration.nextElement();
if ("unicodePwd".equalsIgnoreCase(id)) {
Attribute attr = attrs.get(id);
for (int i = 0; i < attr.size(); i++) {
attr.set(i, encodeUnicodePwd(attr.get(i)));
}
}
}
}
dirContext = getDirContext(paramValueMap);
dirContext.bind(entryName, null, attrs);
return DEFAULT_RESULT;
} catch (NamingException e) {
// if (log.isDebugEnabled()) log.debug("Exception in operation [" + getOperation()+ "] entryName ["+entryName+"]", e);
if (log.isDebugEnabled())
log.debug("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]: " + e.getMessage());
// [LDAP: error code 68 - Entry Already Exists]
if (e.getMessage().startsWith("[LDAP: error code 68 - ")) {
return DEFAULT_RESULT_CREATE_OK;
} else {
storeLdapException(e, prc);
throw new SenderException(e);
}
} finally {
closeDirContext(dirContext);
}
}
}
use of javax.naming.directory.BasicAttributes in project karaf by apache.
the class LdapCacheTest method addUserToGroup.
private void addUserToGroup(DirContext context, String userCn, String group) throws NamingException {
Attributes entry = new BasicAttributes();
entry.put(new BasicAttribute("cn", group));
Attribute oc = new BasicAttribute("objectClass");
oc.add("top");
oc.add("groupOfNames");
entry.put(oc);
Attribute mb = new BasicAttribute("member");
mb.add(userCn);
entry.put(mb);
context.createSubcontext("cn=" + group + ",ou=groups,dc=example,dc=com", entry);
}
use of javax.naming.directory.BasicAttributes in project jdk8u_jdk by JetBrains.
the class Rdn method toAttributes.
/**
* Retrieves the {@link javax.naming.directory.Attributes Attributes}
* view of the type/value mappings contained in this Rdn.
*
* @return The non-null attributes containing the type/value
* mappings of this Rdn.
*/
public Attributes toAttributes() {
Attributes attrs = new BasicAttributes(true);
for (int i = 0; i < entries.size(); i++) {
RdnEntry entry = entries.get(i);
Attribute attr = attrs.put(entry.getType(), entry.getValue());
if (attr != null) {
attr.add(entry.getValue());
attrs.put(attr);
}
}
return attrs;
}
use of javax.naming.directory.BasicAttributes in project activemq-artemis by apache.
the class LegacyLDAPSecuritySettingPluginListenerTest method testConsumerPermissionUpdate.
@Test
public void testConsumerPermissionUpdate() throws Exception {
server.getConfiguration().setSecurityInvalidationInterval(0);
server.start();
ClientSessionFactory cf = locator.createSessionFactory();
String queue = "queue1";
ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
ClientSession session2 = cf.createSession("second", "secret", false, true, true, false, 0);
session.createQueue(SimpleString.toSimpleString(queue), SimpleString.toSimpleString(queue));
ClientConsumer consumer = session.createConsumer(queue);
consumer.receiveImmediate();
consumer.close();
ClientConsumer consumer2 = null;
try {
session2.createConsumer(queue);
Assert.fail("Consuming here should fail due to the original security data.");
} catch (ActiveMQException e) {
// ok
}
DirContext ctx = getContext();
BasicAttributes basicAttributes = new BasicAttributes();
basicAttributes.put("uniquemember", "uid=role2");
ctx.modifyAttributes("cn=read,uid=queue1,ou=queues,ou=destinations,o=ActiveMQ,ou=system", DirContext.REPLACE_ATTRIBUTE, basicAttributes);
ctx.close();
consumer2 = session2.createConsumer(queue);
consumer2.receiveImmediate();
consumer2.close();
try {
session.createConsumer(queue);
Assert.fail("Sending here should fail due to the modified security data.");
} catch (ActiveMQException e) {
// ok
}
cf.close();
}
Aggregations