use of com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration in project midpoint by Evolveum.
the class Saml2ModuleFactory method createEmptyModuleAuthentication.
public ModuleAuthenticationImpl createEmptyModuleAuthentication(SamlModuleWebSecurityConfiguration configuration, ServletRequest request) {
Saml2ModuleAuthenticationImpl moduleAuthentication = new Saml2ModuleAuthenticationImpl();
List<IdentityProvider> providers = new ArrayList<>();
configuration.getRelyingPartyRegistrationRepository().forEach(p -> {
String authRequestPrefixUrl = request.getServletContext().getContextPath() + configuration.getPrefixOfModule() + RemoteModuleAuthenticationImpl.AUTHENTICATION_REQUEST_PROCESSING_URL_SUFFIX_WITH_REG_ID;
SamlAdditionalConfiguration config = configuration.getAdditionalConfiguration().get(p.getRegistrationId());
IdentityProvider mp = new IdentityProvider().setLinkText(config.getLinkText()).setRedirectLink(authRequestPrefixUrl.replace("{registrationId}", p.getRegistrationId()));
providers.add(mp);
});
moduleAuthentication.setProviders(providers);
moduleAuthentication.setAdditionalConfiguration(configuration.getAdditionalConfiguration());
moduleAuthentication.setNameOfModule(configuration.getNameOfModule());
moduleAuthentication.setPrefix(configuration.getPrefixOfModule());
return moduleAuthentication;
}
use of com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration in project midpoint by Evolveum.
the class Saml2Provider method internalAuthentication.
@Override
protected Authentication internalAuthentication(Authentication authentication, List requireAssignment, AuthenticationChannel channel, Class focusType) throws AuthenticationException {
Authentication token;
if (authentication instanceof Saml2AuthenticationToken) {
Saml2AuthenticationToken samlAuthenticationToken = (Saml2AuthenticationToken) authentication;
Saml2Authentication samlAuthentication;
try {
samlAuthentication = (Saml2Authentication) openSamlProvider.authenticate(samlAuthenticationToken);
} catch (AuthenticationException e) {
getAuditProvider().auditLoginFailure(null, null, createConnectEnvironment(getChannel()), e.getMessage());
throw e;
}
Saml2ModuleAuthenticationImpl samlModule = (Saml2ModuleAuthenticationImpl) AuthUtil.getProcessingModule();
try {
DefaultSaml2AuthenticatedPrincipal principal = (DefaultSaml2AuthenticatedPrincipal) samlAuthentication.getPrincipal();
samlAuthenticationToken.setDetails(principal);
Map<String, List<Object>> attributes = principal.getAttributes();
String enteredUsername;
SamlAdditionalConfiguration config = samlModule.getAdditionalConfiguration().get(samlAuthenticationToken.getRelyingPartyRegistration().getRegistrationId());
String nameOfSamlAttribute = config.getNameOfUsernameAttribute();
enteredUsername = defineEnteredUsername(attributes, nameOfSamlAttribute);
token = getPreAuthenticationToken(enteredUsername, focusType, requireAssignment, channel);
} catch (AuthenticationException e) {
samlModule.setAuthentication(samlAuthenticationToken);
LOGGER.info("Authentication with saml module failed: {}", e.getMessage());
throw e;
}
} else {
LOGGER.error("Unsupported authentication {}", authentication);
throw new AuthenticationServiceException("web.security.provider.unavailable");
}
MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
LOGGER.debug("User '{}' authenticated ({}), authorities: {}", authentication.getPrincipal(), authentication.getClass().getSimpleName(), principal.getAuthorities());
return token;
}
Aggregations