/** * 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(); }
@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()); } }
@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"); }
@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"); }
@Test public void testMissingProfileCreator() { final FormClient formClient = new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator()); formClient.setCallbackUrl(CALLBACK_URL); formClient.setProfileCreator(null); TestsHelper.expectException(() -> formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
default Config getConfig() { // login not used because the ajax resolver always answer true Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator(); FormClient client = new FormClient("notUsedLoginUrl", auth); DirectFormClient client2 = new DirectFormClient(auth); DirectFormClient client3 = new DirectFormClient(auth); client3.setName(DEFAULT_CLIENT); Clients clients = new Clients("notUsedCallbackUrl", client, client2, client3); // in case of invalid credentials, we simply want the error, not a redirect to the login url clients.setAjaxRequestResolver(new JaxRsAjaxRequestResolver()); // so that callback url have the correct prefix w.r.t. the container's context clients.setUrlResolver(new JaxRsUrlResolver()); clients.setDefaultSecurityClients(DEFAULT_CLIENT); return new Config(clients); } }
final TwitterClient twitterClient = new TwitterClient("CoxUiYwQOSFDReZYdjigBA", "2kAzunH5Btc4gRSaMr7D7MkyoJ5u1VzbOOzE8rBofs"); final FormClient formClient = new FormClient("http://localhost:8080/loginForm", new SimpleTestUsernamePasswordAuthenticator()); final IndirectBasicAuthClient indirectBasicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); final DirectBasicAuthClient directBasicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());