use of org.codelibs.fess.app.web.base.login.SpnegoCredential 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);
}
Aggregations