use of org.pac4j.core.credentials.UsernamePasswordCredentials 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());
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.
the class ClientAuthenticationMetaDataPopulatorTests method verifySupports.
@Test
public void verifySupports() {
val populator = new ClientAuthenticationMetaDataPopulator();
val clintCreds = new ClientCredential(new UsernamePasswordCredentials("casuser", "pa$$"), "FacebookClient");
assertTrue(populator.supports(clintCreds));
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.
the class ClientAuthenticationMetaDataPopulatorTests method verifyAttribute.
@Test
public void verifyAttribute() {
val populator = new ClientAuthenticationMetaDataPopulator();
val credentials = new ClientCredential(new UsernamePasswordCredentials("casuser", "pa$$"), "FacebookClient");
val builder = CoreAuthenticationTestUtils.getAuthenticationBuilder();
populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credentials));
val auth = builder.build();
assertNotNull(auth.getAttributes().get(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME));
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project ArachneCentralAPI by OHDSI.
the class AuthenticationServiceImpl method authenticateAndGetAuthToken.
@Transactional(rollbackFor = Exception.class, readOnly = false)
public String authenticateAndGetAuthToken(CommonAuthenticationRequest authenticationRequest) {
String username = authenticationRequest.getUsername();
String password = authenticationRequest.getPassword();
try {
UserInfo userInfo = authenticator.authenticate(authMethodName, new UsernamePasswordCredentials(username, password));
authenticate(userInfo.getUsername(), password);
return userInfo.getToken();
} catch (Exception e) {
SecurityContextHolder.clearContext();
throw e;
}
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.
the class ECPProfileHandlerController method extractBasicAuthenticationCredential.
private Credential extractBasicAuthenticationCredential(final HttpServletRequest request, final HttpServletResponse response) {
try {
final BasicAuthExtractor extractor = new BasicAuthExtractor(this.getClass().getSimpleName());
final WebContext webContext = WebUtils.getPac4jJ2EContext(request, response);
final UsernamePasswordCredentials credentials = extractor.extract(webContext);
if (credentials != null) {
LOGGER.debug("Received basic authentication ECP request from credentials [{}]", credentials);
return new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return null;
}
Aggregations