use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class MidpointRequestHeaderAuthenticationFilter method requiresAuthentication.
private boolean requiresAuthentication() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication != null && moduleAuthentication.getAuthentication() == null) {
return true;
}
}
return false;
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class OidcClientModuleAuthenticationImpl method clone.
@Override
public ModuleAuthenticationImpl clone() {
OidcClientModuleAuthenticationImpl module = new OidcClientModuleAuthenticationImpl();
module.setClientsRepository(this.getClientsRepository());
module.setProviders(this.getProviders());
Authentication actualAuth = SecurityContextHolder.getContext().getAuthentication();
Authentication newAuthentication = this.getAuthentication();
if (actualAuth instanceof MidpointAuthentication && ((MidpointAuthentication) actualAuth).getAuthentications() != null && !((MidpointAuthentication) actualAuth).getAuthentications().isEmpty()) {
ModuleAuthentication actualModule = ((MidpointAuthentication) actualAuth).getAuthentications().get(0);
if (actualModule instanceof OidcClientModuleAuthenticationImpl && actualModule.getAuthentication() instanceof OAuth2LoginAuthenticationToken) {
newAuthentication = actualModule.getAuthentication();
}
}
module.setAuthentication(newAuthentication);
super.clone(module);
return module;
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class OidcClientLogoutSuccessHandler method determineTargetUrl.
protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
String targetUrl = null;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mPAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mPAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication instanceof OidcClientModuleAuthenticationImpl) {
Authentication internalAuthentication = moduleAuthentication.getAuthentication();
if (internalAuthentication instanceof PreAuthenticatedAuthenticationToken || internalAuthentication instanceof AnonymousAuthenticationToken) {
Object details = internalAuthentication.getDetails();
if (details instanceof OAuth2LoginAuthenticationToken && ((OAuth2LoginAuthenticationToken) details).getDetails() instanceof OidcUser) {
OAuth2LoginAuthenticationToken oidcAuthentication = (OAuth2LoginAuthenticationToken) details;
String registrationId = oidcAuthentication.getClientRegistration().getRegistrationId();
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
URI endSessionEndpoint = this.endSessionEndpoint(clientRegistration);
if (endSessionEndpoint != null) {
String idToken = this.idToken(oidcAuthentication);
String postLogoutRedirectUri = this.postLogoutRedirectUri(request);
targetUrl = this.endpointUri(endSessionEndpoint, idToken, postLogoutRedirectUri);
}
}
}
}
}
return targetUrl != null ? targetUrl : super.determineTargetUrl(request, response);
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class MidPointAbstractAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication originalAuthentication) throws AuthenticationException {
AuthenticationRequirements authRequirements = new AuthenticationRequirements();
try {
Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
Authentication processingAuthentication = originalAuthentication;
if (isAnonymous(originalAuthentication)) {
// hack for specific situation when user is anonymous, but accessDecisionManager resolve it
return originalAuthentication;
}
processingAuthentication = initAuthRequirements(processingAuthentication, originalAuthentication, actualAuthentication, authRequirements);
Authentication token = internalAuthentication(processingAuthentication, authRequirements.requireAssignment, authRequirements.channel, authRequirements.focusType);
if (actualAuthentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) getProcessingModule(mpAuthentication);
if (token.getPrincipal() instanceof MidPointPrincipal) {
MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
token = createNewAuthenticationToken(token, mpAuthentication.getAuthenticationChannel().resolveAuthorities(principal.getAuthorities()));
} else {
token = createNewAuthenticationToken(token, token.getAuthorities());
}
writeAuthentication(processingAuthentication, mpAuthentication, moduleAuthentication, token);
return mpAuthentication;
}
return token;
} catch (RuntimeException | Error e) {
// Make sure to explicitly log all runtime errors here. Spring security is doing very poor job and does not log this properly.
LOGGER.error("Authentication (runtime) error: {}", e.getMessage(), e);
throw e;
}
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class MidPointAbstractAuthenticationProvider method isAnonymous.
private boolean isAnonymous(Authentication originalAuthentication) {
if (originalAuthentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) originalAuthentication;
ModuleAuthentication moduleAuthentication = getProcessingModule(mpAuthentication);
return moduleAuthentication.getAuthentication() instanceof AnonymousAuthenticationToken;
}
return false;
}
Aggregations