Search in sources :

Example 1 with SpnegoHttpServletResponse

use of org.codelibs.spnego.SpnegoHttpServletResponse 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)

Aggregations

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 ActionResponseCredential (org.codelibs.fess.app.web.base.login.ActionResponseCredential)1 SpnegoCredential (org.codelibs.fess.app.web.base.login.SpnegoCredential)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 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 SpnegoFilterConfig (org.codelibs.spnego.SpnegoFilterConfig)1 SpnegoHttpFilter (org.codelibs.spnego.SpnegoHttpFilter)1 Constants (org.codelibs.spnego.SpnegoHttpFilter.Constants)1 SpnegoHttpServletResponse (org.codelibs.spnego.SpnegoHttpServletResponse)1 SpnegoPrincipal (org.codelibs.spnego.SpnegoPrincipal)1 LoginCredential (org.lastaflute.web.login.credential.LoginCredential)1