/** * Add a simple login form. Useful for development and quick startup. * * @param pattern Pattern to protect.ver * @return This module. */ public Pac4j form(String pattern) { return clientInternal(pattern, conf -> { showDevLogin = true; return new FormClient("/login", new SimpleTestUsernamePasswordAuthenticator()); }, null); }
protected Authenticator getAuthenticator(final String name) { if (AUTHENTICATOR_TEST_TOKEN.equals(name)) { return new SimpleTestTokenAuthenticator(); } else if (AUTHENTICATOR_TEST_USERNAME_PASSWORD.equals(name)) { return new SimpleTestUsernamePasswordAuthenticator(); } else { return authenticators.get(name); } } }
private DirectFormClient getFormClient() { return new DirectFormClient(new SimpleTestUsernamePasswordAuthenticator()); }
private IndirectBasicAuthClient getBasicAuthClient() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); basicAuthClient.setCallbackUrl(CALLBACK_URL); return basicAuthClient; }
private FormClient getFormClient() { final FormClient client = new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator()); client.setCallbackUrl(CALLBACK_URL); return client; }
@Test public void testHasDefaultProfileCreator() { final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); basicAuthClient.init(); }
@Test public void testMissingCallbackUrl() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); TestsHelper.initShouldFail(basicAuthClient, "callbackUrl cannot be blank: set it up either on this IndirectClient or on the global Config"); }
@Test public void testHasDefaultProfileCreator() { final DirectFormClient formClient = new DirectFormClient(new LocalCachingAuthenticator<>(new SimpleTestUsernamePasswordAuthenticator(), 10, 10, TimeUnit.DAYS)); formClient.init(); }
@Test public void testMissingRealm() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(null, new SimpleTestUsernamePasswordAuthenticator()); basicAuthClient.setCallbackUrl(CALLBACK_URL); TestsHelper.initShouldFail(basicAuthClient, "realmName cannot be blank"); }
@Test public void testHasDefaultProfileCreator() { final FormClient formClient = new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator()); formClient.setCallbackUrl(CALLBACK_URL); formClient.init(); }
@Test public void testMissingLoginUrl() { final FormClient formClient = new FormClient(null, new SimpleTestUsernamePasswordAuthenticator()); formClient.setCallbackUrl(CALLBACK_URL); TestsHelper.initShouldFail(formClient, "loginUrl cannot be blank"); }
@Test public void testHasDefaultProfileCreator() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); basicAuthClient.setCallbackUrl(CALLBACK_URL); basicAuthClient.init(); }
final IndirectBasicAuthClient indirectBasicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); indirectBasicAuthClient.setRealmName("Knox TEST"); config = new Config(pac4jCallbackUrl, indirectBasicAuthClient);
@Test public void testAuthentication() { final DirectBasicAuthClient client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); final MockWebContext context = MockWebContext.create(); final String header = USERNAME + ":" + USERNAME; context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))); final UsernamePasswordCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(USERNAME, profile.getId()); }
@Test public void testAuthenticationLowercase() { final DirectBasicAuthClient client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); final MockWebContext context = MockWebContext.create(); final String header = USERNAME + ":" + USERNAME; context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER.toLowerCase(), "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))); final UsernamePasswordCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(USERNAME, profile.getId()); } }
final IndirectBasicAuthClient indirectBasicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); indirectBasicAuthClient.setRealmName("Knox TEST"); config = new Config(pac4jCallbackUrl, indirectBasicAuthClient);
@Test public void testMissingProfileCreator() { final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator(), null); TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final DirectFormClient formClient = new DirectFormClient(new SimpleTestUsernamePasswordAuthenticator(), null); TestsHelper.expectException(() -> formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
"2kAzunH5Btc4gRSaMr7D7MkyoJ5u1VzbOOzE8rBofs"); final FormClient formClient = new FormClient("http://localhost:8080/loginForm.jsp", new SimpleTestUsernamePasswordAuthenticator()); final IndirectBasicAuthClient indirectBasicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); final DirectBasicAuthClient directBasicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
@Test public void testMissingProfileCreator() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(NAME, new SimpleTestUsernamePasswordAuthenticator()); basicAuthClient.setCallbackUrl(CALLBACK_URL); basicAuthClient.setProfileCreator(null); TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }