Search in sources :

Example 11 with SimpleTestUsernamePasswordAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator in project pac4j by pac4j.

the class IndirectBasicAuthClientTests method testMissingProfileCreator.

@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");
}
Also used : SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 12 with SimpleTestUsernamePasswordAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator in project pac4j by pac4j.

the class IndirectBasicAuthClientTests method testMissingCallbackUrl.

@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");
}
Also used : SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) Test(org.junit.Test)

Example 13 with SimpleTestUsernamePasswordAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator in project pac4j by pac4j.

the class DirectBasicAuthClientTests method testHasDefaultProfileCreator.

@Test
public void testHasDefaultProfileCreator() {
    final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
    basicAuthClient.init();
}
Also used : SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) Test(org.junit.Test)

Example 14 with SimpleTestUsernamePasswordAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator in project pac4j by pac4j.

the class DirectBasicAuthClientTests method testMissingProfileCreator.

@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");
}
Also used : SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 15 with SimpleTestUsernamePasswordAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator in project pac4j by pac4j.

the class DirectBasicAuthClientTests method testAuthentication.

@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());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)15 Test (org.junit.Test)12 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)6 HashMap (java.util.HashMap)2 Config (org.pac4j.core.config.Config)2 IndirectBasicAuthClient (org.pac4j.http.client.indirect.IndirectBasicAuthClient)2 KnoxSessionStore (org.apache.knox.gateway.pac4j.session.KnoxSessionStore)1 GatewayServices (org.apache.knox.gateway.services.GatewayServices)1 AliasServiceException (org.apache.knox.gateway.services.security.AliasServiceException)1 CryptoService (org.apache.knox.gateway.services.security.CryptoService)1 CasClient (org.pac4j.cas.client.CasClient)1 PropertiesConfigFactory (org.pac4j.config.client.PropertiesConfigFactory)1 Client (org.pac4j.core.client.Client)1 Clients (org.pac4j.core.client.Clients)1 MockWebContext (org.pac4j.core.context.MockWebContext)1 J2ESessionStore (org.pac4j.core.context.session.J2ESessionStore)1 SessionStore (org.pac4j.core.context.session.SessionStore)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 DirectBasicAuthClient (org.pac4j.http.client.direct.DirectBasicAuthClient)1 FormClient (org.pac4j.http.client.indirect.FormClient)1