Search in sources :

Example 1 with AnonymousProfile

use of org.pac4j.core.profile.AnonymousProfile in project pac4j by pac4j.

the class IsAuthenticatedAuthorizerTests method testAnonymousProfile.

@Test
public void testAnonymousProfile() {
    profiles.add(new AnonymousProfile());
    assertFalse(authorizer.isAuthorized(null, new MockSessionStore(), profiles));
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 2 with AnonymousProfile

use of org.pac4j.core.profile.AnonymousProfile in project pac4j by pac4j.

the class IsRememberedAuthorizerTests method testAnonymousProfileRedirectionUrl.

@Override
@Test
public void testAnonymousProfileRedirectionUrl() {
    profiles.add(new AnonymousProfile());
    ((IsRememberedAuthorizer) authorizer).setRedirectionUrl(PAC4J_URL);
    TestsHelper.expectException(() -> authorizer.isAuthorized(MockWebContext.create(), new MockSessionStore(), profiles), HttpAction.class, "Performing a 302 HTTP action");
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 3 with AnonymousProfile

use of org.pac4j.core.profile.AnonymousProfile in project pac4j by pac4j.

the class IsAnonymousAuthorizerTests method testAnonymousProfile.

@Test
public void testAnonymousProfile() {
    profiles.add(new AnonymousProfile());
    assertTrue(authorizer.isAuthorized(null, new MockSessionStore(), profiles));
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 4 with AnonymousProfile

use of org.pac4j.core.profile.AnonymousProfile in project pac4j by pac4j.

the class IsAnonymousAuthorizerTests method testAnonProfileTwoProfiles.

@Test
public void testAnonProfileTwoProfiles() {
    profiles.add(new AnonymousProfile());
    profiles.add(new CommonProfile());
    assertFalse(authorizer.isAuthorized(null, new MockSessionStore(), profiles));
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 5 with AnonymousProfile

use of org.pac4j.core.profile.AnonymousProfile in project cas by apereo.

the class AccessTokenDeviceCodeResponseRequestExtractor method extract.

@Override
public AccessTokenRequestContext extract(final WebContext context) {
    val clientId = OAuth20Utils.getRequestParameter(context, OAuth20Constants.CLIENT_ID).orElse(StringUtils.EMPTY);
    LOGGER.debug("Locating OAuth registered service by client id [{}]", clientId);
    val registeredService = OAuth20Utils.getRegisteredOAuthServiceByClientId(getOAuthConfigurationContext().getServicesManager(), clientId);
    LOGGER.debug("Located OAuth registered service [{}]", registeredService);
    val deviceCode = OAuth20Utils.getRequestParameter(context, OAuth20Constants.CODE).orElse(StringUtils.EMPTY);
    val service = getOAuthConfigurationContext().getAuthenticationBuilder().buildService(registeredService, context, false);
    LOGGER.debug("Authenticating the OAuth request indicated by [{}]", service);
    val authentication = getOAuthConfigurationContext().getAuthenticationBuilder().build(new AnonymousProfile(), registeredService, context, service);
    val audit = AuditableContext.builder().service(service).registeredService(registeredService).authentication(authentication).build();
    val accessResult = getOAuthConfigurationContext().getRegisteredServiceAccessStrategyEnforcer().execute(audit);
    accessResult.throwExceptionIfNeeded();
    return AccessTokenRequestContext.builder().service(service).authentication(authentication).registeredService(registeredService).responseType(getResponseType()).grantType(getGrantType()).generateRefreshToken(registeredService != null && registeredService.isGenerateRefreshToken()).deviceCode(deviceCode).build();
}
Also used : lombok.val(lombok.val) AnonymousProfile(org.pac4j.core.profile.AnonymousProfile)

Aggregations

AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)10 Test (org.junit.Test)9 MockSessionStore (org.pac4j.core.context.session.MockSessionStore)9 lombok.val (lombok.val)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1