/** * Returns the generated csrf token stored in http request. */ public static CsrfToken getGeneratedToken(RequestBase request) { return (CsrfToken)request.getAttribute(GENERATED_TOKEN_KEY); }
public static void setRequestToken(RequestBase request, String token) { request.setAttribute(REQUEST_TOKEN_KEY, token); }
public void setPrefixes(String prefixes){ this.parsePrefixes(prefixes); }
@Override public boolean matches(RequestBase request) { String path = request.getPath(ignoreCase); if(null != prefixes){ if(matchPrefixes(path)){ return true; } } if(null != suffixes){ if(matchSuffixes(path)){ return true; } } if(null != patterns){ if(matchPatterns(path)){ return true; } } return false; }
onAppConfigReady(config, initParams); beanFactory = new ServletBeanFactory(config, null); sc.setAttribute(AppContext.APP_CONTEXT_ATTRIBUTE, appContext); beanFactory.load(appContext); onBeanFactoryReady(beanFactory); }, (appContext) -> onAppContextReady(appContext),
@Override public boolean matches(RequestBase request) { return pattern.matches(request.getPath()); } }
@Override public boolean resolveCredentials(AuthenticationContext context, RequestBase request, Out<Credentials> out) throws ServletException, IOException { if(request.isMethod(Method.POST) && request.hasParameter(usernameParameter)){ //Validates username String username = request.getParameter(usernameParameter); if(context.validation() .required(usernameParameter, username) .errors().contains(usernameParameter)){ return true; } context.setIdentity(username); //Validates password if necessary String password = request.getParameter(passwordParameter); if(passwordRequired && context.validation().required(passwordParameter, password) .errors().contains(passwordParameter)){ return true; } log.debug("Resolved 'UsernamePasswordCredentials' : [username={}]",username); out.set(new SimpleUsernamePasswordCredentials(username, password)); return true; } return false; } }
/** * Returns <code>true</code> if current is GET request. */ public boolean isGet() { return "GET".equalsIgnoreCase(getMethod()); }
@Override public Authentication getAuthentication(RequestBase request) { Session sc = request.getSession(false); if(null == sc){ return null; } return (Authentication)sc.getAttribute(SESSION_KEY); }
public void setSuffixes(String suffixes){ this.parseSuffixes(suffixes); }
public void setPatterns(String patterns){ this.parsePatterns(patterns); }
protected final void destroyAppContext(){ try{ if(null != beanFactory){ beanFactory.close(); } }finally{ if(null != servletContext){ servletContext.removeAttribute(AppContext.APP_CONTEXT_ATTRIBUTE); } AppContext.removeCurrent(); } }
@Override public boolean matches(RequestBase request) { String path = request.getPath(ignoreCase); return isPattern ? matcher.match(pattern, path) : pattern.equals(path); } }
public static String getRequestToken(RequestBase request) { return (String)request.getAttribute(REQUEST_TOKEN_KEY); }
static void setGeneratedToken(RequestBase request, CsrfToken token) { request.setAttribute(GENERATED_TOKEN_KEY, token); }
/** * Returns <code>true</code> if current is POST request. */ public boolean isPost() { return "POST".equalsIgnoreCase(getMethod()); }
@Override public Authentication removeAuthentication(RequestBase request) { Session sc = request.getSession(false); if(null == sc){ return null; } Authentication us = (Authentication)sc.getAttribute(SESSION_KEY); //TODO : config , invalidate session after logout if(null != us){ sc.removeAttribute(SESSION_KEY); sc.invalidate(); } return us; } }
@Override public OAuth2Configurator ignorePath(String path) { AntPathPattern pattern = new AntPathPattern(path); ignoresList.add((req) -> pattern.matches(req.getPath())); ignoresArray = ignoresList.toArray(new RequestIgnore[ignoresList.size()]); return this; }
/** * Returns true if the path pattern matches the request. */ default boolean matches(RequestBase request) { return getPattern().matches(request.getPath()); }