Search in sources :

Example 1 with DefaultSecurityLogic

use of org.pac4j.core.engine.DefaultSecurityLogic in project cas by apereo.

the class OAuth20AccessTokenSecurityLogicTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    request.addParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
    val logic = new DefaultSecurityLogic();
    logic.setLoadProfilesFromSession(false);
    val mockClient = mock(DirectClient.class);
    when(mockClient.getName()).thenReturn("MockIndirectClient");
    when(mockClient.isInitialized()).thenReturn(true);
    when(mockClient.getCredentials(any(), any())).thenReturn(Optional.of(new UsernamePasswordCredentials("casuser", "Mellon")));
    val profile = new CommonProfile();
    profile.setId(UUID.randomUUID().toString());
    when(mockClient.getUserProfile(any(), any(), any())).thenReturn(Optional.of(profile));
    val context = new JEEContext(request, response);
    val profileManager = new ProfileManager(context, JEESessionStore.INSTANCE);
    profileManager.save(true, profile, false);
    val result = (UserProfile) logic.perform(context, JEESessionStore.INSTANCE, new Config(mockClient), (webContext, sessionStore, collection, objects) -> collection.iterator().next(), JEEHttpActionAdapter.INSTANCE, "MockIndirectClient", DefaultAuthorizers.IS_FULLY_AUTHENTICATED, DefaultMatchers.SECURITYHEADERS);
    assertNotNull(result);
    assertEquals(1, profileManager.getProfiles().size());
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) DefaultAuthorizers(org.pac4j.core.authorization.authorizer.DefaultAuthorizers) OAuth20Constants(org.apereo.cas.support.oauth.OAuth20Constants) CommonProfile(org.pac4j.core.profile.CommonProfile) DirectClient(org.pac4j.core.client.DirectClient) lombok.val(lombok.val) DefaultSecurityLogic(org.pac4j.core.engine.DefaultSecurityLogic) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UUID(java.util.UUID) ProfileManager(org.pac4j.core.profile.ProfileManager) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) JEEHttpActionAdapter(org.pac4j.core.http.adapter.JEEHttpActionAdapter) Assertions(org.junit.jupiter.api.Assertions) Config(org.pac4j.core.config.Config) Optional(java.util.Optional) Tag(org.junit.jupiter.api.Tag) DefaultMatchers(org.pac4j.core.matching.matcher.DefaultMatchers) UserProfile(org.pac4j.core.profile.UserProfile) AbstractOAuth20Tests(org.apereo.cas.AbstractOAuth20Tests) JEEContext(org.pac4j.core.context.JEEContext) JEESessionStore(org.pac4j.core.context.session.JEESessionStore) UserProfile(org.pac4j.core.profile.UserProfile) CommonProfile(org.pac4j.core.profile.CommonProfile) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Config(org.pac4j.core.config.Config) DefaultSecurityLogic(org.pac4j.core.engine.DefaultSecurityLogic) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.jupiter.api.Test)

Aggregations

Optional (java.util.Optional)1 UUID (java.util.UUID)1 lombok.val (lombok.val)1 AbstractOAuth20Tests (org.apereo.cas.AbstractOAuth20Tests)1 OAuth20Constants (org.apereo.cas.support.oauth.OAuth20Constants)1 Assertions (org.junit.jupiter.api.Assertions)1 Tag (org.junit.jupiter.api.Tag)1 Test (org.junit.jupiter.api.Test)1 Mockito (org.mockito.Mockito)1 DefaultAuthorizers (org.pac4j.core.authorization.authorizer.DefaultAuthorizers)1 DirectClient (org.pac4j.core.client.DirectClient)1 Config (org.pac4j.core.config.Config)1 JEEContext (org.pac4j.core.context.JEEContext)1 JEESessionStore (org.pac4j.core.context.session.JEESessionStore)1 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)1 DefaultSecurityLogic (org.pac4j.core.engine.DefaultSecurityLogic)1 JEEHttpActionAdapter (org.pac4j.core.http.adapter.JEEHttpActionAdapter)1 DefaultMatchers (org.pac4j.core.matching.matcher.DefaultMatchers)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 ProfileManager (org.pac4j.core.profile.ProfileManager)1