Search in sources :

Example 1 with ActionResponseCredential

use of org.codelibs.fess.app.web.base.login.ActionResponseCredential in project fess by codelibs.

the class SpnegoAuthenticator method getLoginCredential.

/* (non-Javadoc)
     * @see org.codelibs.fess.sso.spnego.SsoAuthenticator#getLoginCredential()
     */
@Override
public LoginCredential getLoginCredential() {
    return LaRequestUtil.getOptionalRequest().map(request -> {
        final HttpServletResponse response = LaResponseUtil.getResponse();
        final SpnegoHttpServletResponse spnegoResponse = new SpnegoHttpServletResponse(response);
        final SpnegoPrincipal principal;
        try {
            principal = authenticator.authenticate(request, spnegoResponse);
        } catch (final Exception e) {
            final String msg = "HTTP Authorization Header=" + request.getHeader(Constants.AUTHZ_HEADER);
            logger.error(msg);
            throw new SsoLoginException(msg, e);
        }
        if (spnegoResponse.isStatusSet()) {
            return new ActionResponseCredential(() -> {
                throw new RequestLoggingFilter.RequestClientErrorException("Your request is not authorized.", "401 Unauthorized", HttpServletResponse.SC_UNAUTHORIZED);
            });
        }
        if (null == principal) {
            final String msg = "Principal was null.";
            logger.error(msg);
            throw new SsoLoginException(msg);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("principal=" + principal);
        }
        final String[] username = principal.getName().split("@", 2);
        return new SpnegoCredential(username[0]);
    }).orElseGet(() -> null);
}
Also used : SpnegoFilterConfig(org.codelibs.spnego.SpnegoFilterConfig) Enumeration(java.util.Enumeration) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) FessSystemException(org.codelibs.fess.exception.FessSystemException) LoggerFactory(org.slf4j.LoggerFactory) LoginCredential(org.lastaflute.web.login.credential.LoginCredential) SpnegoPrincipal(org.codelibs.spnego.SpnegoPrincipal) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) LaResponseUtil(org.lastaflute.web.util.LaResponseUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) RequestLoggingFilter(org.lastaflute.web.servlet.filter.RequestLoggingFilter) SpnegoHttpServletResponse(org.codelibs.spnego.SpnegoHttpServletResponse) SsoAuthenticator(org.codelibs.fess.sso.SsoAuthenticator) SpnegoCredential(org.codelibs.fess.app.web.base.login.SpnegoCredential) Logger(org.slf4j.Logger) Constants(org.codelibs.spnego.SpnegoHttpFilter.Constants) ResourceUtil(org.codelibs.core.io.ResourceUtil) SsoLoginException(org.codelibs.fess.exception.SsoLoginException) HttpServletResponse(javax.servlet.http.HttpServletResponse) File(java.io.File) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FilterConfig(javax.servlet.FilterConfig) PostConstruct(javax.annotation.PostConstruct) ServletContext(javax.servlet.ServletContext) SpnegoHttpFilter(org.codelibs.spnego.SpnegoHttpFilter) SpnegoCredential(org.codelibs.fess.app.web.base.login.SpnegoCredential) SpnegoHttpServletResponse(org.codelibs.spnego.SpnegoHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) SpnegoPrincipal(org.codelibs.spnego.SpnegoPrincipal) SpnegoHttpServletResponse(org.codelibs.spnego.SpnegoHttpServletResponse) RequestLoggingFilter(org.lastaflute.web.servlet.filter.RequestLoggingFilter) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) FessSystemException(org.codelibs.fess.exception.FessSystemException) SsoLoginException(org.codelibs.fess.exception.SsoLoginException) SsoLoginException(org.codelibs.fess.exception.SsoLoginException)

Example 2 with ActionResponseCredential

use of org.codelibs.fess.app.web.base.login.ActionResponseCredential in project fess by codelibs.

the class SsoAction method index.

// ===================================================================================
//                                                                       Login Execute
//                                                                      ==============
@Execute
public ActionResponse index() {
    final SsoManager ssoManager = ComponentUtil.getSsoManager();
    final LoginCredential loginCredential = ssoManager.getLoginCredential();
    if (loginCredential == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("No user in SSO request.");
        }
        if (ssoManager.available()) {
            saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
        }
        return redirect(LoginAction.class);
    } else if (loginCredential instanceof ActionResponseCredential) {
        return ((ActionResponseCredential) loginCredential).execute();
    }
    try {
        return fessLoginAssist.loginRedirect(loginCredential, op -> {
        }, () -> {
            activityHelper.login(getUserBean());
            userInfoHelper.deleteUserCodeFromCookie(request);
            return getHtmlResponse();
        });
    } catch (final LoginFailureException lfe) {
        if (logger.isDebugEnabled()) {
            logger.debug("SSO login failure.", lfe);
        }
        if (ssoManager.available()) {
            saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
        }
        return redirect(LoginAction.class);
    }
}
Also used : FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) ActionResponse(org.lastaflute.web.response.ActionResponse) Logger(org.slf4j.Logger) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SsoManager(org.codelibs.fess.sso.SsoManager) Execute(org.lastaflute.web.Execute) LoggerFactory(org.slf4j.LoggerFactory) LoginCredential(org.lastaflute.web.login.credential.LoginCredential) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) LoginAction(org.codelibs.fess.app.web.login.LoginAction) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) LoginCredential(org.lastaflute.web.login.credential.LoginCredential) FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) LoginAction(org.codelibs.fess.app.web.login.LoginAction) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) SsoManager(org.codelibs.fess.sso.SsoManager) Execute(org.lastaflute.web.Execute)

Aggregations

ActionResponseCredential (org.codelibs.fess.app.web.base.login.ActionResponseCredential)2 ComponentUtil (org.codelibs.fess.util.ComponentUtil)2 LoginCredential (org.lastaflute.web.login.credential.LoginCredential)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 File (java.io.File)1 Enumeration (java.util.Enumeration)1 PostConstruct (javax.annotation.PostConstruct)1 FilterConfig (javax.servlet.FilterConfig)1 ServletContext (javax.servlet.ServletContext)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ResourceUtil (org.codelibs.core.io.ResourceUtil)1 FessLoginAction (org.codelibs.fess.app.web.base.FessLoginAction)1 SpnegoCredential (org.codelibs.fess.app.web.base.login.SpnegoCredential)1 LoginAction (org.codelibs.fess.app.web.login.LoginAction)1 FessSystemException (org.codelibs.fess.exception.FessSystemException)1 SsoLoginException (org.codelibs.fess.exception.SsoLoginException)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 SsoAuthenticator (org.codelibs.fess.sso.SsoAuthenticator)1 SsoManager (org.codelibs.fess.sso.SsoManager)1