Search in sources :

Example 1 with URLPatternMatcher

use of org.securityfilter.filter.URLPatternMatcher 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.");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) URLPatternMatcher(org.securityfilter.filter.URLPatternMatcher) XWikiUser(com.xpn.xwiki.user.api.XWikiUser) SecurityRequestWrapper(org.securityfilter.filter.SecurityRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) XWikiException(com.xpn.xwiki.XWikiException) IOException(java.io.IOException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)1 XWikiUser (com.xpn.xwiki.user.api.XWikiUser)1 IOException (java.io.IOException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SecurityRequestWrapper (org.securityfilter.filter.SecurityRequestWrapper)1 URLPatternMatcher (org.securityfilter.filter.URLPatternMatcher)1