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());
}
Aggregations