Search in sources :

Example 51 with MidpointAuthentication

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;
}
Also used : Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 52 with MidpointAuthentication

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) AuthenticationChannel(com.evolveum.midpoint.authentication.api.AuthenticationChannel) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) AuthenticationSequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationSequenceType) AuthModule(com.evolveum.midpoint.authentication.api.AuthModule) AuthenticationsPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationsPolicyType) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 53 with MidpointAuthentication

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());
        }
    }
}
Also used : ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 54 with MidpointAuthentication

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);
    }
}
Also used : ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 55 with MidpointAuthentication

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);
}
Also used : MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Aggregations

MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)59 Authentication (org.springframework.security.core.Authentication)41 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)30 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)9 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)7 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)6 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)5 RemoteModuleAuthentication (com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication)4 HttpModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.HttpModuleAuthentication)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 LdapModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 OAuth2LoginAuthenticationToken (org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken)3 IdentityProvider (com.evolveum.midpoint.authentication.api.IdentityProvider)2 CredentialModuleAuthentication (com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication)2 MailNonceModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.MailNonceModuleAuthenticationImpl)2 OidcClientModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl)2 RemoteModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.RemoteModuleAuthenticationImpl)2