Search in sources :

Example 1 with AuthenticationProvider

use of fi.otavanopisto.pyramus.plugin.auth.AuthenticationProvider in project pyramus by otavanopisto.

the class LogoutViewController method process.

/**
 * Processes the page request. Simply invalidates the session of the logged in user
 * and redirects back to the index page of the application.
 *
 * @param requestContext Page request context
 */
public void process(PageRequestContext requestContext) {
    HttpSession session = requestContext.getRequest().getSession(true);
    String redirectUrl = null;
    String authenticationProviderName = (String) session.getAttribute("authenticationProvider");
    if (StringUtils.isNotBlank(authenticationProviderName)) {
        AuthenticationProvider authenticationProvider = AuthenticationProviderVault.getInstance().getAuthenticationProvider(authenticationProviderName);
        if (authenticationProvider == null) {
            Logger.getLogger(getClass().getName()).severe(String.format("Could not find authenticationProvider %s", authenticationProviderName));
        } else {
            redirectUrl = authenticationProvider.logout(requestContext);
        }
    }
    if (StringUtils.isNotBlank(redirectUrl)) {
        requestContext.setRedirectURL(redirectUrl);
    } else {
        if (requestContext.getLoggedUserId() != null) {
            session.invalidate();
        }
        redirectUrl = requestContext.getString("redirectUrl");
        if (StringUtils.isBlank(redirectUrl)) {
            redirectUrl = requestContext.getRequest().getContextPath() + "/index.page";
        }
        requestContext.setRedirectURL(redirectUrl);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) AuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.AuthenticationProvider)

Example 2 with AuthenticationProvider

use of fi.otavanopisto.pyramus.plugin.auth.AuthenticationProvider in project pyramus by otavanopisto.

the class LoginViewController method process.

/**
 * Processes the page request. This is a simple case of just including the corresponding login JSP page.
 * Since the login form is submitted via JSON, the actual logic of logging in takes place in
 * {@link fi.otavanopisto.pyramus.json.users.LoginJSONRequestController}.
 *
 * @param requestContext Page request context
 */
public void process(PageRequestContext requestContext) {
    AuthenticationProviderVault authenticationProviders = AuthenticationProviderVault.getInstance();
    boolean hasInternals = authenticationProviders.hasInternalStrategies();
    boolean hasExternals = authenticationProviders.hasExternalStrategies();
    List<InternalAuthenticationProvider> internalAuthenticationProviders = authenticationProviders.getInternalAuthenticationProviders();
    List<ExternalAuthenticationProvider> externalAuthenticationProviders = authenticationProviders.getExternalAuthenticationProviders();
    String external = requestContext.getString("external");
    if (StringUtils.isNotBlank(external)) {
        AuthenticationProvider authenticationProvider = authenticationProviders.getAuthenticationProvider(external);
        if (authenticationProvider instanceof ExternalAuthenticationProvider) {
            ((ExternalAuthenticationProvider) authenticationProvider).performDiscovery(requestContext);
        } else {
            throw new PageNotFoundException(requestContext.getRequest().getLocale());
        }
    } else {
        if (!hasInternals && hasExternals && externalAuthenticationProviders.size() == 1) {
            ExternalAuthenticationProvider authenticationProvider = authenticationProviders.getExternalAuthenticationProviders().get(0);
            authenticationProvider.performDiscovery(requestContext);
        } else {
            // TODO: support for multiple internal providers
            requestContext.getRequest().setAttribute("internalProviders", internalAuthenticationProviders);
            requestContext.getRequest().setAttribute("externalProviders", externalAuthenticationProviders);
            String localUserMissing = requestContext.getString("localUserMissing");
            if (StringUtils.isNotBlank(localUserMissing)) {
                requestContext.addMessage(Severity.WARNING, Messages.getInstance().getText(requestContext.getRequest().getLocale(), "users.login.localUserMissing", new String[] { localUserMissing }));
            }
            String customLoginPage = getCustomLoginPage(requestContext);
            if (StringUtils.isNotBlank(customLoginPage)) {
                requestContext.setIncludeFtl(customLoginPage);
            } else {
                requestContext.setIncludeJSP("/templates/users/login.jsp");
            }
        }
    }
}
Also used : AuthenticationProviderVault(fi.otavanopisto.pyramus.plugin.auth.AuthenticationProviderVault) PageNotFoundException(fi.internetix.smvc.PageNotFoundException) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) ExternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.ExternalAuthenticationProvider) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) AuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.AuthenticationProvider) ExternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.ExternalAuthenticationProvider)

Aggregations

AuthenticationProvider (fi.otavanopisto.pyramus.plugin.auth.AuthenticationProvider)2 PageNotFoundException (fi.internetix.smvc.PageNotFoundException)1 AuthenticationProviderVault (fi.otavanopisto.pyramus.plugin.auth.AuthenticationProviderVault)1 ExternalAuthenticationProvider (fi.otavanopisto.pyramus.plugin.auth.ExternalAuthenticationProvider)1 InternalAuthenticationProvider (fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider)1 HttpSession (javax.servlet.http.HttpSession)1