use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAuthFilter method createMpAuthentication.
private void createMpAuthentication(HttpServletRequest httpRequest, AuthenticationWrapper authWrapper) {
MidpointAuthentication mpAuthentication = new MidpointAuthentication(authWrapper.sequence);
mpAuthentication.setAuthModules(authWrapper.authModules);
mpAuthentication.setSessionId(httpRequest.getSession(false) != null ? httpRequest.getSession(false).getId() : RandomStringUtils.random(30, true, true).toUpperCase());
mpAuthentication.addAuthentications(authWrapper.authModules.get(0).getBaseModuleAuthentication());
SecurityContextHolder.getContext().setAuthentication(null);
SecurityContextHolder.getContext().setAuthentication(mpAuthentication);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class AuditedAccessDeniedHandler method auditEvent.
private void auditEvent(HttpServletRequest request, Authentication authentication, AccessDeniedException accessDeniedException) {
// Eventually we should get this from the caller
OperationResult result = new OperationResult(OP_AUDIT_EVENT);
MidPointPrincipal principal = AuthUtil.getPrincipalUser(authentication);
PrismObject<? extends FocusType> user = principal != null ? principal.getFocus().asPrismObject() : null;
String channel = SchemaConstants.CHANNEL_USER_URI;
if (authentication instanceof MidpointAuthentication && ((MidpointAuthentication) authentication).getAuthenticationChannel() != null) {
channel = ((MidpointAuthentication) authentication).getAuthenticationChannel().getChannelId();
}
Task task = taskManager.createTaskInstance();
task.setOwner(user);
task.setChannel(channel);
AuditEventRecord record = new AuditEventRecord(AuditEventType.CREATE_SESSION, AuditEventStage.REQUEST);
record.setInitiator(user);
record.setParameter(AuthSequenceUtil.getName(user));
record.setChannel(channel);
record.setTimestamp(System.currentTimeMillis());
record.setOutcome(OperationResultStatus.FATAL_ERROR);
// probably not needed, as audit service would take care of it; but it doesn't hurt so let's keep it here
record.setHostIdentifier(request.getLocalName());
record.setRemoteHostAddress(request.getLocalAddr());
record.setNodeIdentifier(taskManager.getNodeId());
record.setSessionIdentifier(request.getRequestedSessionId());
record.setMessage(accessDeniedException.getMessage());
auditService.audit(record, task, result);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidPointAuthenticationSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
String urlSuffix = AuthConstants.DEFAULT_PATH_AFTER_LOGIN;
String authenticatedChannel = null;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
moduleAuthentication.setState(AuthenticationModuleState.SUCCESSFULLY);
if (mpAuthentication.getAuthenticationChannel() != null) {
authenticatedChannel = mpAuthentication.getAuthenticationChannel().getChannelId();
if (mpAuthentication.isAuthenticated()) {
urlSuffix = mpAuthentication.getAuthenticationChannel().getPathAfterSuccessfulAuthentication();
mpAuthentication.getAuthenticationChannel().postSuccessAuthenticationProcessing();
if (mpAuthentication.getAuthenticationChannel().isPostAuthenticationEnabled()) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
} else {
urlSuffix = mpAuthentication.getAuthenticationChannel().getPathDuringProccessing();
}
}
}
SavedRequest savedRequest = requestCache.getRequest(request, response);
if (savedRequest != null && savedRequest.getRedirectUrl().contains(ModuleWebSecurityConfigurationImpl.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH + "/")) {
String target = savedRequest.getRedirectUrl().substring(0, savedRequest.getRedirectUrl().indexOf(ModuleWebSecurityConfigurationImpl.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH + "/")) + urlSuffix;
getRedirectStrategy().sendRedirect(request, response, target);
return;
}
if (savedRequest != null && authenticatedChannel != null) {
int startIndex = savedRequest.getRedirectUrl().indexOf(request.getContextPath()) + request.getContextPath().length();
int endIndex = savedRequest.getRedirectUrl().length() - 1;
String channelSavedRequest = null;
if ((startIndex < endIndex)) {
String localePath = savedRequest.getRedirectUrl().substring(startIndex, endIndex);
channelSavedRequest = AuthSequenceUtil.searchChannelByPath(localePath);
}
if (channelSavedRequest == null) {
channelSavedRequest = SecurityPolicyUtil.DEFAULT_CHANNEL;
}
if (!(channelSavedRequest.equals(authenticatedChannel))) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
} else {
setDefaultTargetUrl(urlSuffix);
}
super.onAuthenticationSuccess(request, response, authentication);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAuthenticationFailureHandler method onAuthenticationFailure.
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String urlSuffix = AuthConstants.DEFAULT_PATH_AFTER_LOGIN;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
if (mpAuthentication.isAuthenticated()) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (mpAuthentication.getAuthenticationChannel() != null) {
if (mpAuthentication.isLast(moduleAuthentication) && mpAuthentication.getAuthenticationChannel().isDefault()) {
urlSuffix = getPathAfterUnsuccessfulAuthentication(mpAuthentication.getAuthenticationChannel());
} else {
urlSuffix = mpAuthentication.getAuthenticationChannel().getPathDuringProccessing();
}
}
moduleAuthentication.setState(AuthenticationModuleState.FAILURE);
}
saveException(request, exception);
SavedRequest savedRequest = getRequestCache().getRequest(request, response);
if (savedRequest == null || StringUtils.isBlank(savedRequest.getRedirectUrl()) || ((DefaultSavedRequest) savedRequest).getServletPath().startsWith(ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH)) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
getRedirectStrategy().sendRedirect(request, response, savedRequest.getRedirectUrl());
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication 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;
}
Aggregations