Search in sources :

Example 1 with ModuleAuthentication

use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.

the class PageLogin method getUrlProcessingLogin.

private String getUrlProcessingLogin() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication != null && (AuthenticationModuleNameConstants.LOGIN_FORM.equals(moduleAuthentication.getNameOfModuleType()) || AuthenticationModuleNameConstants.LDAP.equals(moduleAuthentication.getNameOfModuleType()))) {
            String prefix = moduleAuthentication.getPrefix();
            return AuthUtil.stripSlashes(prefix) + "/spring_security_login";
        }
    }
    return "./spring_security_login";
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 2 with ModuleAuthentication

use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.

the class AbstractPageRemoteAuthenticationSelect method initCustomLayer.

@Override
protected void initCustomLayer() {
    List<IdentityProvider> providers = getProviders();
    add(new ListView<IdentityProvider>(ID_PROVIDERS, providers) {

        @Override
        protected void populateItem(ListItem<IdentityProvider> item) {
            item.add(new ExternalLink(ID_PROVIDER, item.getModelObject().getRedirectLink(), item.getModelObject().getLinkText()));
        }
    });
    MidpointForm<?> form = new MidpointForm<>(ID_LOGOUT_FORM);
    ModuleAuthentication actualModule = AuthUtil.getProcessingModuleIfExist();
    if (actualModule != null) {
        Authentication actualAuthentication = actualModule.getAuthentication();
        String authName = actualModule.getNameOfModuleType();
        form.add(new VisibleBehaviour(() -> existRemoteAuthentication(actualAuthentication, authName)));
        String prefix = actualModule.getPrefix();
        form.add(AttributeModifier.replace("action", (IModel<String>) () -> existRemoteAuthentication(actualAuthentication, authName) ? SecurityUtils.getPathForLogoutWithContextPath(getRequest().getContextPath(), prefix) : ""));
    } else {
        form.add(new VisibleBehaviour(() -> false));
    }
    add(form);
    WebMarkupContainer csrfField = SecurityUtils.createHiddenInputForCsrf(ID_CSRF_FIELD);
    form.add(csrfField);
}
Also used : IModel(org.apache.wicket.model.IModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) Authentication(org.springframework.security.core.Authentication)

Example 3 with ModuleAuthentication

use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method createMpAuthentication.

protected Authentication createMpAuthentication(Authentication authentication) {
    MidpointAuthentication mpAuthentication = new MidpointAuthentication(SecurityPolicyUtil.createDefaultSequence());
    ModuleAuthentication moduleAuthentication = new ModuleAuthentication() {

        @Override
        public String getNameOfModule() {
            return SecurityPolicyUtil.DEFAULT_MODULE_NAME;
        }

        @Override
        public String getNameOfModuleType() {
            return AuthenticationModuleNameConstants.LOGIN_FORM;
        }

        @Override
        public AuthenticationModuleState getState() {
            return AuthenticationModuleState.SUCCESSFULLY;
        }

        @Override
        public void setState(AuthenticationModuleState state) {
        }

        @Override
        public Authentication getAuthentication() {
            return authentication;
        }

        @Override
        public void setAuthentication(Authentication authentication) {
        }

        @Override
        public String getPrefix() {
            return ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH + ModuleWebSecurityConfiguration.DEFAULT_PREFIX_FOR_DEFAULT_MODULE + SecurityPolicyUtil.DEFAULT_MODULE_NAME + "/";
        }

        @Override
        public QName getFocusType() {
            return null;
        }
    };
    mpAuthentication.addAuthentications(moduleAuthentication);
    mpAuthentication.setPrincipal(authentication.getPrincipal());
    return mpAuthentication;
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) AuthenticationModuleState(com.evolveum.midpoint.authentication.api.AuthenticationModuleState) Authentication(org.springframework.security.core.Authentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 4 with ModuleAuthentication

use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.

the class MidpointAuthFilter method processingOfAuthenticatedRequest.

private void processingOfAuthenticatedRequest(MidpointAuthentication mpAuthentication, ServletRequest httpRequest, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    for (ModuleAuthentication moduleAuthentication : mpAuthentication.getAuthentications()) {
        if (AuthenticationModuleState.SUCCESSFULLY.equals(moduleAuthentication.getState())) {
            int i = mpAuthentication.getIndexOfModule(moduleAuthentication);
            VirtualFilterChain vfc = new VirtualFilterChain(chain, ((AuthModuleImpl) mpAuthentication.getAuthModules().get(i)).getSecurityFilterChain().getFilters());
            vfc.doFilter(httpRequest, response);
        }
    }
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) AuthModuleImpl(com.evolveum.midpoint.authentication.impl.util.AuthModuleImpl)

Example 5 with ModuleAuthentication

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

Aggregations

ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)32 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)29 Authentication (org.springframework.security.core.Authentication)21 HttpModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.HttpModuleAuthentication)6 RemoteModuleAuthentication (com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication)5 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)4 IdentityProvider (com.evolveum.midpoint.authentication.api.IdentityProvider)3 CredentialModuleAuthentication (com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication)2 MailNonceModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.MailNonceModuleAuthenticationImpl)2 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)2 ArrayList (java.util.ArrayList)2 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)2 OAuth2LoginAuthenticationToken (org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken)2 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)2 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)2 AuthenticationModuleState (com.evolveum.midpoint.authentication.api.AuthenticationModuleState)1 MidpointAnonymousAuthenticationFilter (com.evolveum.midpoint.authentication.impl.filter.MidpointAnonymousAuthenticationFilter)1 OidcClientModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl)1 RemoteModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.RemoteModuleAuthenticationImpl)1 Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)1