List of usage examples for javax.naming.directory BasicAttributes BasicAttributes
public BasicAttributes(String attrID, Object val, boolean ignoreCase)
From source file:org.nuxeo.ecm.directory.ldap.MockLdapServer.java
public void createManagerUser() { Attributes user = new BasicAttributes("cn", "manager", true); user.put("userPassword", "secret"); Attribute objectClass = new BasicAttribute("objectClass"); user.put(objectClass);// ww w . ja v a 2s .co m objectClass.add("top"); objectClass.add("person"); objectClass.add("organizationalPerson"); objectClass.add("inetOrgPerson"); user.put("sn", "Manager"); user.put("cn", "manager"); try { serverContext.createSubcontext("cn=manager", user); } catch (NameAlreadyBoundException ignore) { log.warn("Manager user already exists."); } catch (NamingException ne) { log.error("Failed to create manager user", ne); } }
From source file:org.apache.nifi.processors.enrich.QueryDNS.java
/** * This method performs a simple DNS lookup using JNDI * @param queryInput String containing the query body itself (e.g. 4.3.3.1.in-addr.arpa); * @param queryType String containing the query type (e.g. TXT); */// w w w . j a v a 2 s. co m protected Attributes doLookup(String queryInput, String queryType) throws NamingException { // This is a simple DNS lookup attempt Attributes attrs; try { // Uses pre-existing context to resolve attrs = ictx.getAttributes(queryInput, new String[] { queryType }); return attrs; } catch (NameNotFoundException e) { getLogger().debug("Resolution for domain {} failed due to {}", new Object[] { queryInput, e }); attrs = new BasicAttributes(queryType, "NXDOMAIN", true); return attrs; } }
From source file:org.apache.directory.server.operations.bind.MiscBindIT.java
/** * Test case for <a href="http://issues.apache.org/jira/browse/DIREVE-284" where users in * mixed case partitions were not able to authenticate properly. This test case creates * a new partition under dc=aPache,dc=org, it then creates the example user in the JIRA * issue and attempts to authenticate as that user. * * @throws Exception if the user cannot authenticate or test fails *//*from w w w. ja v a 2s . co m*/ @Test public void testUserAuthOnMixedCaseSuffix() throws Exception { getLdapServer().getDirectoryService().setAllowAnonymousAccess(true); Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.PROVIDER_URL, Network.ldapLoopbackUrl(getLdapServer().getPort()) + "/dc=aPache,dc=org"); env.put("java.naming.ldap.version", "3"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); InitialDirContext ctx = new InitialDirContext(env); Attributes attrs = ctx.getAttributes(""); assertTrue(attrs.get("dc").get().equals("aPache")); Attributes user = new BasicAttributes("cn", "Kate Bush", true); Attribute oc = new BasicAttribute("objectClass"); oc.add("top"); oc.add("person"); oc.add("organizationalPerson"); oc.add("inetOrgPerson"); user.put(oc); user.put("sn", "Bush"); user.put("userPassword", "Aerial"); ctx.createSubcontext("cn=Kate Bush", user); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_CREDENTIALS, "Aerial"); env.put(Context.SECURITY_PRINCIPAL, "cn=Kate Bush,dc=aPache,dc=org"); InitialDirContext userCtx = new InitialDirContext(env); assertNotNull(userCtx); ctx.destroySubcontext("cn=Kate Bush"); }
From source file:org.apache.directory.server.operations.bind.MiscBindIT.java
@Test public void testFailureWithUnsupportedControl() throws Exception { Control unsupported = new OpaqueControl("1.1.1.1"); unsupported.setCritical(true);/* w w w .j a va 2s . c o m*/ getLdapServer().getDirectoryService().setAllowAnonymousAccess(true); Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.PROVIDER_URL, Network.ldapLoopbackUrl(getLdapServer().getPort()) + "/ou=system"); env.put("java.naming.ldap.version", "3"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_CREDENTIALS, "secret"); env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); InitialLdapContext ctx = new InitialLdapContext(env, null); Attributes user = new BasicAttributes("cn", "Kate Bush", true); Attribute oc = new BasicAttribute("objectClass"); oc.add("top"); oc.add("person"); oc.add("organizationalPerson"); oc.add("inetOrgPerson"); user.put(oc); user.put("sn", "Bush"); user.put("userPassword", "Aerial"); ctx.setRequestControls(JndiUtils.toJndiControls(getLdapServer().getDirectoryService().getLdapCodecService(), new Control[] { unsupported })); try { ctx.createSubcontext("cn=Kate Bush", user); fail(); } catch (OperationNotSupportedException e) { } unsupported.setCritical(false); ctx.setRequestControls(JndiUtils.toJndiControls(getLdapServer().getDirectoryService().getLdapCodecService(), new Control[] { unsupported })); DirContext kate = ctx.createSubcontext("cn=Kate Bush", user); assertNotNull(kate); assertTrue(ArrayUtils.isEquals(Asn1StringUtils.getBytesUtf8("Aerial"), kate.getAttributes("").get("userPassword").get())); ctx.destroySubcontext("cn=Kate Bush"); }