use of org.apereo.cas.authentication.principal.Principal in project cas by apereo.
the class DuoAuthenticationHandler method authenticateDuoApiCredential.
private AuthenticationHandlerExecutionResult authenticateDuoApiCredential(final Credential credential) throws FailedLoginException {
try {
final DuoSecurityAuthenticationService duoAuthenticationService = getDuoAuthenticationService();
final DuoDirectCredential c = DuoDirectCredential.class.cast(credential);
if (duoAuthenticationService.authenticate(c).getKey()) {
final Principal principal = c.getAuthentication().getPrincipal();
LOGGER.debug("Duo has successfully authenticated [{}]", principal.getId());
return createHandlerResult(credential, principal, new ArrayList<>());
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
throw new FailedLoginException("Duo authentication has failed");
}
use of org.apereo.cas.authentication.principal.Principal in project cas by apereo.
the class OAuth20UserAuthenticator method validate.
@Override
public void validate(final UsernamePasswordCredentials credentials, final WebContext context) throws CredentialsException {
final UsernamePasswordCredential casCredential = new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
try {
final String clientId = context.getRequestParameter(OAuth20Constants.CLIENT_ID);
final Service service = this.webApplicationServiceFactory.createService(clientId);
final RegisteredService registeredService = OAuth20Utils.getRegisteredOAuthServiceByClientId(this.servicesManager, clientId);
RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(registeredService);
final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(null, casCredential);
final Authentication authentication = authenticationResult.getAuthentication();
final Principal principal = authentication.getPrincipal();
final OAuthUserProfile profile = new OAuthUserProfile();
final String id = registeredService.getUsernameAttributeProvider().resolveUsername(principal, service, registeredService);
LOGGER.debug("Created profile id [{}]", id);
profile.setId(id);
final Map<String, Object> attributes = registeredService.getAttributeReleasePolicy().getAttributes(principal, service, registeredService);
profile.addAttributes(attributes);
LOGGER.debug("Authenticated user profile [{}]", profile);
credentials.setUserProfile(profile);
} catch (final Exception e) {
throw new CredentialsException("Cannot login user using CAS internal authentication", e);
}
}
use of org.apereo.cas.authentication.principal.Principal in project cas by apereo.
the class DefaultOAuth2UserProfileDataCreator method createFrom.
@Override
@Audit(action = "OAUTH2_USER_PROFILE_DATA", actionResolverName = "OAUTH2_USER_PROFILE_DATA_ACTION_RESOLVER", resourceResolverName = "OAUTH2_USER_PROFILE_DATA_RESOURCE_RESOLVER")
public Map<String, Object> createFrom(final AccessToken accessToken, final J2EContext context) {
final Principal principal = getAccessTokenAuthenticationPrincipal(accessToken, context);
final Map<String, Object> map = new HashMap<>();
map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ID, principal.getId());
map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ATTRIBUTES, principal.getAttributes());
finalizeProfileResponse(accessToken, map, principal);
return map;
}
use of org.apereo.cas.authentication.principal.Principal in project cas by apereo.
the class AbstractOAuth20Tests method internalVerifyRefreshTokenOk.
protected Pair<AccessToken, RefreshToken> internalVerifyRefreshTokenOk(final OAuthRegisteredService service, final boolean json) throws Exception {
final Principal principal = createPrincipal();
final RefreshToken refreshToken = addRefreshToken(principal, service);
return internalVerifyRefreshTokenOk(service, json, refreshToken, principal);
}
use of org.apereo.cas.authentication.principal.Principal in project cas by apereo.
the class OAuth20AccessTokenControllerMemcachedTests method verifyOAuthCodeIsAddedToMemcached.
@Test
public void verifyOAuthCodeIsAddedToMemcached() {
final Principal p = createPrincipal();
final OAuthCode code = addCode(p, addRegisteredService());
final Ticket ticket = this.ticketRegistry.getTicket(code.getId(), OAuthCode.class);
assertNotNull(ticket);
}
Aggregations