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);
}
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);
}
}
Aggregations