Search in sources :

Example 1 with IdentityProvider

use of com.evolveum.midpoint.authentication.api.IdentityProvider 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 2 with IdentityProvider

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

the class OidcClientModuleFactory method createEmptyModuleAuthentication.

public ModuleAuthenticationImpl createEmptyModuleAuthentication(OidcClientModuleWebSecurityConfiguration configuration, ServletRequest request) {
    OidcClientModuleAuthenticationImpl moduleAuthentication = new OidcClientModuleAuthenticationImpl();
    List<IdentityProvider> providers = new ArrayList<>();
    configuration.getClientRegistrationRepository().forEach(client -> {
        String authRequestPrefixUrl = request.getServletContext().getContextPath() + configuration.getPrefixOfModule() + OidcClientModuleAuthenticationImpl.AUTHORIZATION_REQUEST_PROCESSING_URL_SUFFIX_WITH_REG_ID;
        IdentityProvider mp = new IdentityProvider().setLinkText(client.getClientName()).setRedirectLink(authRequestPrefixUrl.replace("{registrationId}", client.getRegistrationId()));
        providers.add(mp);
    });
    moduleAuthentication.setClientsRepository(configuration.getClientRegistrationRepository());
    moduleAuthentication.setProviders(providers);
    moduleAuthentication.setNameOfModule(configuration.getNameOfModule());
    moduleAuthentication.setPrefix(configuration.getPrefixOfModule());
    return moduleAuthentication;
}
Also used : OidcClientModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl) ArrayList(java.util.ArrayList) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider)

Example 3 with IdentityProvider

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

the class AbstractPageRemoteAuthenticationSelect method getProviders.

private List<IdentityProvider> getProviders() {
    List<IdentityProvider> providers = new ArrayList<>();
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication instanceof RemoteModuleAuthentication) {
            providers = ((RemoteModuleAuthentication) moduleAuthentication).getProviders();
            if (providers.isEmpty()) {
                String key = getErrorKeyEmptyProviders();
                error(getString(key));
            }
            return providers;
        }
        String key = getErrorKeyUnsupportedType();
        error(getString(key));
        return providers;
    }
    String key = "web.security.flexAuth.unsupported.auth.type";
    error(getString(key));
    return providers;
}
Also used : 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) RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) ArrayList(java.util.ArrayList) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 4 with IdentityProvider

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

the class Saml2ModuleFactory method createEmptyModuleAuthentication.

public ModuleAuthenticationImpl createEmptyModuleAuthentication(SamlModuleWebSecurityConfiguration configuration, ServletRequest request) {
    Saml2ModuleAuthenticationImpl moduleAuthentication = new Saml2ModuleAuthenticationImpl();
    List<IdentityProvider> providers = new ArrayList<>();
    configuration.getRelyingPartyRegistrationRepository().forEach(p -> {
        String authRequestPrefixUrl = request.getServletContext().getContextPath() + configuration.getPrefixOfModule() + RemoteModuleAuthenticationImpl.AUTHENTICATION_REQUEST_PROCESSING_URL_SUFFIX_WITH_REG_ID;
        SamlAdditionalConfiguration config = configuration.getAdditionalConfiguration().get(p.getRegistrationId());
        IdentityProvider mp = new IdentityProvider().setLinkText(config.getLinkText()).setRedirectLink(authRequestPrefixUrl.replace("{registrationId}", p.getRegistrationId()));
        providers.add(mp);
    });
    moduleAuthentication.setProviders(providers);
    moduleAuthentication.setAdditionalConfiguration(configuration.getAdditionalConfiguration());
    moduleAuthentication.setNameOfModule(configuration.getNameOfModule());
    moduleAuthentication.setPrefix(configuration.getPrefixOfModule());
    return moduleAuthentication;
}
Also used : SamlAdditionalConfiguration(com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration) ArrayList(java.util.ArrayList) Saml2ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider)

Example 5 with IdentityProvider

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

the class RemoteAuthenticationEntryPoint method commence.

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication instanceof RemoteModuleAuthentication) {
            List<IdentityProvider> providers = ((RemoteModuleAuthentication) moduleAuthentication).getProviders();
            if (request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION") == null) {
                if (providers.size() == 1) {
                    response.sendRedirect(providers.get(0).getRedirectLink());
                    return;
                }
            } else if (getLoginFormUrl().equals(request.getServletPath()) && AuthenticationModuleState.LOGIN_PROCESSING.equals(moduleAuthentication.getState())) {
                return;
            }
        }
    }
    super.commence(request, response, authException);
}
Also used : 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) RemoteModuleAuthentication(com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication) IdentityProvider(com.evolveum.midpoint.authentication.api.IdentityProvider) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Aggregations

IdentityProvider (com.evolveum.midpoint.authentication.api.IdentityProvider)5 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)3 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)3 RemoteModuleAuthentication (com.evolveum.midpoint.authentication.api.config.RemoteModuleAuthentication)3 ArrayList (java.util.ArrayList)3 Authentication (org.springframework.security.core.Authentication)3 OidcClientModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.OidcClientModuleAuthenticationImpl)1 Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)1 SamlAdditionalConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 IModel (org.apache.wicket.model.IModel)1