use of org.securityfilter.filter.SecurityRequestWrapper in project xwiki-platform by xwiki.
the class XWikiAuthServiceImpl method checkAuth.
/**
* Method to authenticate and set the cookie from a username and password passed as parameters
*
* @return null if the user is not authenticated properly
*/
@Override
public XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context) throws XWikiException {
HttpServletRequest request = null;
HttpServletResponse response = context.getResponse();
if (context.getRequest() != null) {
request = context.getRequest().getHttpServletRequest();
}
if (request == null) {
return null;
}
XWikiAuthenticator auth = getAuthenticator(context);
SecurityRequestWrapper wrappedRequest = new SecurityRequestWrapper(request, null, null, auth.getAuthMethod());
try {
if (!auth.processLogin(username, password, rememberme, wrappedRequest, response, context)) {
return null;
}
Principal principal = wrappedRequest.getUserPrincipal();
if (LOGGER.isInfoEnabled()) {
if (principal != null) {
LOGGER.info("User " + principal.getName() + " is authentified");
}
}
if (principal == null) {
return null;
}
return new XWikiUser(getContextUserName(principal, context));
} catch (Exception e) {
LOGGER.error("Failed to authenticate", e);
return null;
}
}
use of org.securityfilter.filter.SecurityRequestWrapper in project xwiki-platform by xwiki.
the class XWikiAuthServiceImpl method checkAuth.
@Override
public XWikiUser checkAuth(XWikiContext context) throws XWikiException {
// Debug time taken.
long time = System.currentTimeMillis();
HttpServletRequest request = null;
HttpServletResponse response = context.getResponse();
if (context.getRequest() != null) {
request = context.getRequest().getHttpServletRequest();
}
if (request == null) {
return null;
}
XWikiAuthenticator auth = getAuthenticator(context);
SecurityRequestWrapper wrappedRequest = new SecurityRequestWrapper(request, null, null, auth.getAuthMethod());
try {
if (auth.processLogin(wrappedRequest, response, context)) {
return null;
}
// Process logout (this only works with Forms)
if (auth.processLogout(wrappedRequest, response, new URLPatternMatcher())) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("User " + context.getUser() + " has been logged-out");
}
wrappedRequest.setUserPrincipal(null);
return null;
}
final String userName = getContextUserName(wrappedRequest.getUserPrincipal(), context);
if (LOGGER.isInfoEnabled()) {
if (userName != null) {
LOGGER.info("User " + userName + " is authentified");
}
}
if (userName == null) {
return null;
}
return new XWikiUser(userName);
} catch (Exception e) {
LOGGER.error("Failed to authenticate", e);
return null;
} finally {
LOGGER.debug("XWikiAuthServiceImpl.checkAuth(XWikiContext) took " + (System.currentTimeMillis() - time) + " milliseconds to run.");
}
}
Aggregations