Search in sources :

Example 71 with BasicAttributes

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);
    }
}
Also used : Digester(org.apache.commons.digester.Digester) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) StringReader(java.io.StringReader) SenderException(nl.nn.adapterframework.core.SenderException) NamingException(javax.naming.NamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 72 with BasicAttributes

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);
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Enumeration(java.util.Enumeration) NamingEnumeration(javax.naming.NamingEnumeration) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Example 73 with BasicAttributes

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);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 74 with BasicAttributes

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;
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 75 with BasicAttributes

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();
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Aggregations

BasicAttributes (javax.naming.directory.BasicAttributes)100 Attributes (javax.naming.directory.Attributes)62 BasicAttribute (javax.naming.directory.BasicAttribute)57 Attribute (javax.naming.directory.Attribute)44 Test (org.junit.Test)22 SearchResult (javax.naming.directory.SearchResult)21 DirContext (javax.naming.directory.DirContext)18 NamingException (javax.naming.NamingException)15 InitialDirContext (javax.naming.directory.InitialDirContext)14 NamingEnumeration (javax.naming.NamingEnumeration)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)10 LdapContext (javax.naming.ldap.LdapContext)9 HashMap (java.util.HashMap)8 InitialLdapContext (javax.naming.ldap.InitialLdapContext)8 File (java.io.File)7 Map (java.util.Map)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 IOException (java.io.IOException)6