use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication 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.MidpointAuthentication in project midpoint by Evolveum.
the class MidPointAbstractAuthenticationProvider method createEnvironment.
protected ConnectionEnvironment createEnvironment(AuthenticationChannel channel) {
if (channel != null) {
ConnectionEnvironment connEnv = ConnectionEnvironment.create(channel.getChannelId());
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
connEnv.setSessionIdOverride(((MidpointAuthentication) authentication).getSessionId());
}
return connEnv;
} else {
return ConnectionEnvironment.create(SchemaConstants.CHANNEL_USER_URI);
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication 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;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class AuthSequenceUtil method doRemoteFilter.
public static void doRemoteFilter(ServletRequest req, ServletResponse res, FilterChain chain, RemoteAuthenticationFilter remoteFilter) throws IOException, ServletException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
boolean sendedRequest = false;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
RemoteModuleAuthenticationImpl moduleAuthentication = (RemoteModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication != null && RequestState.SENDED.equals(moduleAuthentication.getRequestState())) {
sendedRequest = true;
}
boolean requiresAuthentication = remoteFilter.requiresAuth((HttpServletRequest) req, (HttpServletResponse) res);
if (!requiresAuthentication && sendedRequest) {
AuthenticationServiceException exception = new AuthenticationServiceException("web.security.flexAuth.oidc.not.response");
remoteFilter.unsuccessfulAuth((HttpServletRequest) req, (HttpServletResponse) res, exception);
} else {
if (moduleAuthentication != null && requiresAuthentication && sendedRequest) {
moduleAuthentication.setRequestState(RequestState.RECEIVED);
}
remoteFilter.doAuth(req, res, chain);
}
} else {
throw new AuthenticationServiceException("Unsupported type of Authentication");
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointHttpServletRequest method getServletPath.
@Override
public String getServletPath() {
if (needChangePath()) {
MidpointAuthentication mpAuth = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
String path = AuthSequenceUtil.searchPathByChannel(mpAuth.getAuthenticationChannel().getChannelId());
if (StringUtils.isNotEmpty(path) && path.contains("/")) {
return "/" + path.split("/")[0];
}
return "/" + path;
}
return super.getServletPath();
}
Aggregations