Search in sources :

Example 6 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DefaultAuthorizationCheckerTests method testTwoExistingAuthorizerProfileMatch.

@Test
public void testTwoExistingAuthorizerProfileMatch() {
    profile.setId(VALUE);
    profile.addRole(ROLE);
    final Map<String, Authorizer> authorizers = new HashMap<>();
    authorizers.put(NAME, new IdAuthorizer());
    authorizers.put(VALUE, new RequireAnyRoleAuthorizer(ROLE));
    assertTrue(checker.isAuthorized(null, new MockSessionStore(), profiles, NAME + Pac4jConstants.ELEMENT_SEPARATOR + VALUE, authorizers, new ArrayList<>()));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Authorizer(org.pac4j.core.authorization.authorizer.Authorizer) RequireAnyRoleAuthorizer(org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer) RequireAnyRoleAuthorizer(org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer) Test(org.junit.Test)

Example 7 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DefaultAuthorizationCheckerTests method testBlankAuthorizerNameAProfilePostRequestIndirectClient.

@Test
public void testBlankAuthorizerNameAProfilePostRequestIndirectClient() {
    final var context = MockWebContext.create().setRequestMethod("POST");
    final List<Client> clients = new ArrayList<>();
    clients.add(new MockIndirectClient("test"));
    assertFalse(checker.isAuthorized(context, new MockSessionStore(), profiles, " ", new HashMap<>(), clients));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Client(org.pac4j.core.client.Client) AnonymousClient(org.pac4j.core.client.direct.AnonymousClient) MockDirectClient(org.pac4j.core.client.MockDirectClient) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Test(org.junit.Test)

Example 8 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DefaultAuthorizationCheckerTests method testNullAuthorizerNameAProfilePostRequestIndirectClient.

@Test
public void testNullAuthorizerNameAProfilePostRequestIndirectClient() {
    final var context = MockWebContext.create().setRequestMethod("POST");
    final List<Client> clients = new ArrayList<>();
    clients.add(new MockIndirectClient("test"));
    assertFalse(checker.isAuthorized(context, new MockSessionStore(), profiles, null, new HashMap<>(), clients));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Client(org.pac4j.core.client.Client) AnonymousClient(org.pac4j.core.client.direct.AnonymousClient) MockDirectClient(org.pac4j.core.client.MockDirectClient) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Test(org.junit.Test)

Example 9 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DefaultAuthorizationCheckerTests method testNullAuthorizers.

@Test(expected = TechnicalException.class)
public void testNullAuthorizers() {
    assertTrue(checker.isAuthorized(null, new MockSessionStore(), profiles, null));
    checker.isAuthorized(null, new MockSessionStore(), profiles, "auth1", null, new ArrayList<>());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 10 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DefaultAuthorizationCheckerTests method testTwoExistingAuthorizerProfileDoesNotMatch.

@Test
public void testTwoExistingAuthorizerProfileDoesNotMatch() {
    profile.addRole(ROLE);
    final Map<String, Authorizer> authorizers = new HashMap<>();
    authorizers.put(NAME, new IdAuthorizer());
    authorizers.put(VALUE, new RequireAnyRoleAuthorizer(ROLE));
    assertFalse(checker.isAuthorized(null, new MockSessionStore(), profiles, NAME + Pac4jConstants.ELEMENT_SEPARATOR + VALUE, authorizers, new ArrayList<>()));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Authorizer(org.pac4j.core.authorization.authorizer.Authorizer) RequireAnyRoleAuthorizer(org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer) RequireAnyRoleAuthorizer(org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4