use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method assumePowerOfAttorney.
@Override
public MidPointPrincipal assumePowerOfAttorney(PrismObject<? extends FocusType> donor, Task task, OperationResult result) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException {
MidPointPrincipal attorneyPrincipal = securityContextManager.getPrincipal();
MidPointPrincipal donorPrincipal = securityEnforcer.createDonorPrincipal(attorneyPrincipal, ModelAuthorizationAction.ATTORNEY.getUrl(), donor, task, result);
// TODO: audit switch
Authentication authentication = securityContextManager.getAuthentication();
if (authentication instanceof MidpointAuthentication) {
((MidpointAuthentication) authentication).setPrincipal(donorPrincipal);
((MidpointAuthentication) authentication).setCredential(null);
((MidpointAuthentication) authentication).setAuthorities(donorPrincipal.getAuthorities());
} else {
securityContextManager.setupPreAuthenticatedSecurityContext(donorPrincipal);
}
return donorPrincipal;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAnonymousAuthenticationFilter method createAuthentication.
protected Authentication createAuthentication(HttpServletRequest request) {
Authentication auth = createBasicAuthentication(request);
MidpointAuthentication authentication = new MidpointAuthentication(SecurityPolicyUtil.createDefaultSequence());
AuthenticationsPolicyType authenticationsPolicy;
try {
authenticationsPolicy = SecurityPolicyUtil.createDefaultAuthenticationPolicy(NO_CUSTOM_IGNORED_LOCAL_PATH, prismContext.getSchemaRegistry());
} catch (SchemaException e) {
LOGGER.error("Couldn't get default authentication policy");
throw new IllegalArgumentException("Couldn't get default authentication policy", e);
}
AuthenticationSequenceType sequence = SecurityPolicyUtil.createDefaultSequence();
AuthenticationChannel authenticationChannel = AuthSequenceUtil.buildAuthChannel(authChannelRegistry, sequence);
List<AuthModule> authModules = AuthSequenceUtil.buildModuleFilters(authRegistry, sequence, request, authenticationsPolicy.getModules(), null, new HashMap<>(), authenticationChannel);
authentication.setAuthModules(authModules);
if (authModules != null) {
ModuleAuthenticationImpl module = (ModuleAuthenticationImpl) authModules.get(0).getBaseModuleAuthentication();
module.setAuthentication(auth);
authentication.addAuthentications(module);
}
authentication.setPrincipal(auth.getPrincipal());
return authentication;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAnonymousAuthenticationFilter method processAuthentication.
protected void processAuthentication(ServletRequest req) {
if (SecurityContextHolder.getContext().getAuthentication() instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication != null && moduleAuthentication.getAuthentication() == null) {
Authentication authentication = createBasicAuthentication((HttpServletRequest) req);
moduleAuthentication.setAuthentication(authentication);
mpAuthentication.setPrincipal(authentication.getPrincipal());
}
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointExceptionTranslationFilter method sendStartAuthentication.
@Override
protected void sendStartAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, AuthenticationException reason) throws ServletException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!AuthSequenceUtil.isRecordSessionLessAccessChannel(request)) {
requestCache.saveRequest(request, response);
}
LOGGER.debug("Calling Authentication entry point.");
getAuthenticationEntryPoint().commence(request, response, reason);
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication != null && moduleAuthentication.getAuthentication() instanceof AnonymousAuthenticationToken) {
moduleAuthentication.setAuthentication(createNewAuthentication((AnonymousAuthenticationToken) moduleAuthentication.getAuthentication()));
mpAuthentication.setPrincipal(null);
}
SecurityContextHolder.getContext().setAuthentication(mpAuthentication);
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class RemoteAuthenticationFilter method remoteUnsuccessfulAuthentication.
default void remoteUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed, ModelAuditRecorder auditProvider, RememberMeServices rememberMeService, AuthenticationFailureHandler failureHandler, String moduleName) throws IOException, ServletException {
String channel;
Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
if (actualAuthentication instanceof MidpointAuthentication && ((MidpointAuthentication) actualAuthentication).getAuthenticationChannel() != null) {
channel = ((MidpointAuthentication) actualAuthentication).getAuthenticationChannel().getChannelId();
} else {
channel = SchemaConstants.CHANNEL_USER_URI;
}
auditProvider.auditLoginFailure("unknown user", null, ConnectionEnvironment.create(channel), moduleName + " authentication module: " + failed.getMessage());
rememberMeService.loginFail(request, response);
failureHandler.onAuthenticationFailure(request, response, failed);
}
Aggregations