| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.InetAddress; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.Socket; |
| | | import java.net.UnknownHostException; |
| | | import java.util.ArrayList; |
| | |
| | | List<Control> responseControls = new ArrayList<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), ByteString.valueOfUtf8("password"), |
| | | requestControls, responseControls); |
| | | } |
| | |
| | | List<Control> responseControls = new ArrayList<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, null, null, requestControls, responseControls); |
| | | } |
| | | } |
| | |
| | | List<Control> responseControls = new ArrayList<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.empty(), ByteString.empty(), requestControls, responseControls); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.empty(), requestControls, |
| | | responseControls); |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.valueOfUtf8("wrongPassword"), |
| | | requestControls, responseControls); |
| | |
| | | requestControls.add(new PasswordPolicyRequestControl()); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), ByteString.valueOfUtf8("password"), |
| | | requestControls, responseControls); |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSASLBind(null, null, null, saslProperties, requestControls, responseControls); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSASLBind(null, null, "", saslProperties, requestControls, responseControls); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSASLBind(null, null, "invalid", saslProperties, |
| | | requestControls, responseControls); |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | } |
| | | |
| | |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | } |
| | | handler.finalizeSASLMechanismHandler(); |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | saslProperties.put("trace", newArrayList("testDoSASLBindAnonymous")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSASLBind(ByteString.empty(), ByteString.empty(), "ANONYMOUS", saslProperties, requestControls, |
| | | responseControls); |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("CRAM-MD5", "invalidPassword", authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=test.user,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | |
| | | authHandler.doSASLBind(ByteString.empty(), ByteString.valueOfUtf8("password"), "CRAM-MD5", saslProperties, |
| | | requestControls, responseControls); |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | digestMD5(authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("DIGEST-MD5", "wrongPassword", authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | try (Socket s = factory.createSocket("127.0.0.1", TestCaseUtils.getServerLdapsPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("EXTERNAL", null, authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | try (Socket s = factory.createSocket("127.0.0.1", TestCaseUtils.getServerLdapsPort())) |
| | | { |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("EXTERNAL", null, authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = factory.createSocket("127.0.0.1", TestCaseUtils.getServerLdapsPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("EXTERNAL", null, authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | try (Socket s = factory.createSocket("127.0.0.1", TestCaseUtils.getServerLdapsPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("EXTERNAL", null, authHandler, saslProperties); |
| | | authHandler.doSASLBind(ByteString.empty(), null, "EXTERNAL", saslProperties, requestControls, responseControls); |
| | | } |
| | |
| | | |
| | | private Socket newSocket() throws UnknownHostException, IOException |
| | | { |
| | | return new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | final Socket socket=new Socket(); |
| | | socket.setReuseAddress(true); |
| | | socket.connect(new InetSocketAddress("127.0.0.1",TestCaseUtils.getServerLdapPort())); |
| | | return socket; |
| | | } |
| | | |
| | | private LDAPAuthenticationHandler newLDAPAuthenticationHandler(Socket s, String hostName2) throws IOException |
| | |
| | | { |
| | | try (Socket s = newSocket()) |
| | | { |
| | | plain(newLDAPAuthenticationHandler(s, "localhost"), saslProperties); |
| | | plain(newLDAPAuthenticationHandler(s, "127.0.0.1"), saslProperties); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try (Socket s = newSocket()) |
| | | { |
| | | cramMD5(newLDAPAuthenticationHandler(s, "localhost"), saslProperties); |
| | | cramMD5(newLDAPAuthenticationHandler(s, "127.0.0.1"), saslProperties); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try (Socket s = newSocket()) |
| | | { |
| | | digestMD5(newLDAPAuthenticationHandler(s, "localhost"), saslProperties); |
| | | digestMD5(newLDAPAuthenticationHandler(s, "127.0.0.1"), saslProperties); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try (Socket s = newSocket()) |
| | | { |
| | | gssapi(newLDAPAuthenticationHandler(s, "localhost"), saslProperties); |
| | | gssapi(newLDAPAuthenticationHandler(s, "127.0.0.1"), saslProperties); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | plain(authHandler, saslProperties); |
| | | } |
| | | finally |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=test.user,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | plain(authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | saslProperties.put("authid", newArrayList("dn:uid=does.not.exist,o=test")); |
| | | |
| | | plain(newLDAPAuthenticationHandler(s, "localhost"), saslProperties); |
| | | plain(newLDAPAuthenticationHandler(s, "127.0.0.1"), saslProperties); |
| | | } |
| | | } |
| | | |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=does.not.exist,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("PLAIN", "wrongPassword", authHandler, saslProperties); |
| | | } |
| | | } |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=test.user,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSASLBind(ByteString.empty(), ByteString.valueOfUtf8("password"), "PLAIN", saslProperties, |
| | | requestControls, responseControls); |
| | | } |
| | |
| | | { |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | assertNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | | } |
| | |
| | | |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.empty(), ByteString.empty(), requestControls, responseControls); |
| | | assertNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | |
| | | List<Control> responseControls = new ArrayList<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), ByteString.valueOfUtf8("password"), |
| | | requestControls, responseControls); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | |
| | | List<Control> responseControls = new ArrayList<>(); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("uid=test.user,o=test"), ByteString.valueOfUtf8("password"), |
| | | requestControls, responseControls); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | |
| | | saslProperties.put("trace", newArrayList("testDoSASLBindAnonymous")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | anonymous(authHandler, saslProperties); |
| | | assertNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=test.user,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | cramMD5(authHandler, saslProperties); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | |
| | | Map<String, List<String>> saslProperties = new LinkedHashMap<>(); |
| | | try (Socket s = factory.createSocket("127.0.0.1", TestCaseUtils.getServerLdapsPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | doSASLBind("EXTERNAL", null, authHandler, saslProperties); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | |
| | | saslProperties.put("authid", newArrayList("dn:uid=test.user,o=test")); |
| | | try (Socket s = newSocket()) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "localhost"); |
| | | LDAPAuthenticationHandler authHandler = newLDAPAuthenticationHandler(s, "127.0.0.1"); |
| | | plain(authHandler, saslProperties); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | } |
| | |
| | | try { |
| | | this.hostname = InetAddress.getLocalHost().getCanonicalHostName(); |
| | | } catch(UnknownHostException ex) { |
| | | this.hostname = "localhost"; |
| | | this.hostname = "127.0.0.1"; |
| | | } |
| | | } |
| | | } |