use of com.disney.http.auth.server.basic.PasswordChecker 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;
}
use of com.disney.http.auth.server.basic.PasswordChecker 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;
}
use of com.disney.http.auth.server.basic.PasswordChecker 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());
}
Aggregations