Search in sources :

Example 1 with BasicVerifierImpl

use of com.disney.http.auth.server.basic.BasicVerifierImpl in project groovity by disney.

the class VerifierFactory method processBasic.

@SuppressWarnings({ "rawtypes", "unchecked" })
private BasicVerifierImpl processBasic(Map basic, Class scriptClass) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    BasicVerifierImpl verifier = new BasicVerifierImpl();
    processCommon(verifier, basic, scriptClass);
    List<PasswordChecker> passwordCheckers = new ArrayList<PasswordChecker>();
    Map passwords = (Map) basic.get("passwords");
    if (passwords != null) {
        passwordCheckers.add(new MapPasswordChecker(passwords));
    }
    Object passwordChecker = basic.get("passwordChecker");
    addPasswordChecker(passwordChecker, passwordCheckers, scriptClass);
    List pcs = (List) basic.get("passwordCheckers");
    if (pcs != null) {
        for (Object pc : pcs) {
            addPasswordChecker(pc, passwordCheckers, scriptClass);
        }
    }
    verifier.setPasswordCheckers(passwordCheckers);
    return verifier;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) PasswordChecker(com.disney.http.auth.server.basic.PasswordChecker) Map(java.util.Map) HashMap(java.util.HashMap) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) BasicVerifierImpl(com.disney.http.auth.server.basic.BasicVerifierImpl)

Example 2 with BasicVerifierImpl

use of com.disney.http.auth.server.basic.BasicVerifierImpl in project groovity by disney.

the class XmlPolicyParser method processBasic.

private static BasicVerifierImpl processBasic(Element basic) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    BasicVerifierImpl bc = new BasicVerifierImpl();
    processCommon(bc, basic);
    List<PasswordChecker> passwordCheckers = new ArrayList<PasswordChecker>();
    NodeList bcnodes = basic.getChildNodes();
    for (int j = 0; j < bcnodes.getLength(); j++) {
        Node bcnode = bcnodes.item(j);
        if (bcnode instanceof Element) {
            Element bcel = (Element) bcnode;
            if (bcel.getNodeName().equals("passwords")) {
                passwordCheckers.add(new MapPasswordChecker(processPasswords(bcel)));
            } else if (bcel.getNodeName().equals("passwordChecker")) {
                passwordCheckers.add((PasswordChecker) Class.forName(bcel.getAttribute("class")).newInstance());
            }
        }
    }
    bc.setPasswordCheckers(passwordCheckers);
    return bc;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) PasswordChecker(com.disney.http.auth.server.basic.PasswordChecker) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) BasicVerifierImpl(com.disney.http.auth.server.basic.BasicVerifierImpl)

Example 3 with BasicVerifierImpl

use of com.disney.http.auth.server.basic.BasicVerifierImpl in project groovity by disney.

the class TestBasicAuth method testBasic.

@Test
public void testBasic() throws Exception {
    BasicVerifierImpl verifier = new BasicVerifierImpl();
    Map<String, String> pmap = new HashMap<String, String>();
    List<String> accessList = new ArrayList<String>();
    ACLAccessControllerImpl acl = new ACLAccessControllerImpl();
    acl.setAcl(accessList);
    pmap.put("mykey", "mypass");
    PasswordChecker pc = new MapPasswordChecker(pmap);
    verifier.setPasswordCheckers(Arrays.asList(pc));
    verifier.setAccessControllers(Arrays.asList((AccessController) acl));
    MockHttpServletRequest request = new MockHttpServletRequest();
    ServerAuthorizationRequest areq = new ServletAuthorizationRequest(request);
    VerifierResult result = verifier.verify(areq);
    Assert.assertEquals(ERROR_MISSING_CREDENTIALS, result.getMessage());
    request.addHeader("Authorization", "Basic " + DatatypeConverter.printBase64Binary("mykey:wrongpass".getBytes()));
    result = verifier.verify(areq);
    Assert.assertEquals(ERROR_UNKNOWN_CREDENTIALS, result.getMessage());
    request = new MockHttpServletRequest();
    request.addHeader("Authorization", "Basic " + DatatypeConverter.printBase64Binary("mykey:mypass".getBytes()));
    areq = new ServletAuthorizationRequest(request);
    result = verifier.verify(areq);
    Assert.assertTrue("Expected successful authentication", result.isAuthenticated());
    Assert.assertFalse("Expected failed authorization", result.isAuthorized());
    accessList.add("mykey");
    result = verifier.verify(areq);
    Assert.assertTrue("Expected successful authentication", result.isAuthenticated());
    Assert.assertTrue("Expected successful authorization", result.isAuthorized());
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) ServletAuthorizationRequest(com.disney.http.auth.server.ServletAuthorizationRequest) PasswordChecker(com.disney.http.auth.server.basic.PasswordChecker) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) AccessController(com.disney.http.auth.server.AccessController) VerifierResult(com.disney.http.auth.server.VerifierResult) ACLAccessControllerImpl(com.disney.http.auth.server.ACLAccessControllerImpl) MapPasswordChecker(com.disney.http.auth.server.basic.MapPasswordChecker) ServerAuthorizationRequest(com.disney.http.auth.server.ServerAuthorizationRequest) BasicVerifierImpl(com.disney.http.auth.server.basic.BasicVerifierImpl) Test(org.junit.Test)

Aggregations

BasicVerifierImpl (com.disney.http.auth.server.basic.BasicVerifierImpl)3 MapPasswordChecker (com.disney.http.auth.server.basic.MapPasswordChecker)3 PasswordChecker (com.disney.http.auth.server.basic.PasswordChecker)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 ACLAccessControllerImpl (com.disney.http.auth.server.ACLAccessControllerImpl)1 AccessController (com.disney.http.auth.server.AccessController)1 ServerAuthorizationRequest (com.disney.http.auth.server.ServerAuthorizationRequest)1 ServletAuthorizationRequest (com.disney.http.auth.server.ServletAuthorizationRequest)1 VerifierResult (com.disney.http.auth.server.VerifierResult)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1