static SecurityContextHolder current() { SecurityContextHolder context = (SecurityContextHolder)RequestContext.current().getAttribute(CONTEXT_HOLDER_ATTRIBUTE_NAME); if(null == context){ throw new IllegalStateException("Current security context holder does not exists"); } return context; }
/** * Returns the instance of {@link SecurityContext} in current request of returns <code>null</code> if the context not exists. */ public static SecurityContext tryGetCurrent(){ RequestContext rc = RequestContext.tryGetCurrent(); if(null == rc) { return null; }else{ return (SecurityContext)rc.getAttribute(CONTEXT_ATTRIBUTE_NAME); } }
/** * Returns a formatted {@link String} of the given key and current locale. * * @throws ObjectNotFoundException if the given key not exists. * * @see MessageSource#getMessage(String, Object...) */ public static String getMessage(String key,Object... args) throws ObjectNotFoundException { RequestContext current = current(); return current.getMessageSource().getMessage(current.getLocale(),key, args); }
/** * Returns current request's locale or use {@link Locales#DEFAULT_LOCALE} if no current locale. */ public static Locale locale() { RequestContext rc = tryGetCurrent(); if(null != rc && null != rc.getLocale()) { return rc.getLocale(); }else{ return Locales.DEFAULT_LOCALE; } }
@Override public Object require() { RequestContext rc = RequestContext.tryGetCurrent(); if(null == rc) { OAuth2ModuleImpl module = (OAuth2ModuleImpl)rc.getAttribute(OAuth2ModuleImpl.class.getName()); if(null != module) { return module; } } SecurityContext sc = SecurityContext.tryGetCurrent(); if(null == sc) { return EMPTY; } Authentication authc = sc.getAuthentication(); if(!(authc instanceof OAuth2Authentication)) { return EMPTY; } OAuth2ModuleImpl module = new OAuth2ModuleImpl(this, (OAuth2Authentication)authc); rc.setAttribute(OAuth2ModuleImpl.class.getName(), module); return module; }
public static MessageKey getMessageKey(String key, Object...args){ return OAuth2Errors.messageKey(RequestContext.locale(),key,args); } public static MessageKey createRandomKey(){
public static String get(Locale locale, String key,Object... args){ return RequestContext.current().getMessageSource().getMessage(locale, key, args); }
protected Object resolveSessionVariable(VariableDefinition vd){ return resolveScopedVariable(vd, getVariablesScope(RequestContext.current().getSession())); }
public static RequestContext current() { RequestContext c = tryGetCurrent(); if(null == c) { throw new IllegalStateException("Current request context must be initialized"); } return c; }
protected Object resolveRequestVariable(VariableDefinition vd){ return resolveScopedVariable(vd, getVariablesScope(RequestContext.current())); }
RequestContext.setStandalone(new StandaloneRequestContext());
public static MessageKey createRandomKey(){ return OAuth2Errors.messageKey(RequestContext.locale(), UUID.randomUUID().toString()); } }
public static String get(String key,Object... args){ return RequestContext.current().getMessageSource().getMessage(key, args); }
/** * Returns the instance of {@link SecurityContext} in current request. * * @throws IllegalStateException if the context not exists in current request. */ public static SecurityContext current() { SecurityContext context = (SecurityContext)RequestContext.current().getAttribute(CONTEXT_ATTRIBUTE_NAME); if(null == context){ throw new IllegalStateException("Current security context does not exists"); } return context; }
public static MessageKey createRandomKey(){ return OAuth2Errors.messageKey(RequestContext.locale(), UUID.randomUUID().toString()); } }
public static String get(Locale locale, String key){ return RequestContext.current().getMessageSource().getMessage(locale, key); }
/** * Returns a formatted {@link String} of the given key for current {@link Locale}. * * <p> * Returns <code>null</code> if the given key not exists for current {@link Locale}. * * @see MessageSource#tryGetMessage(Locale, String, Object...) */ public static String tryGetMessage(String key,Object... args) { RequestContext current = current(); return current.getMessageSource().tryGetMessage(current.getLocale(),key, args); }
public static MessageKey getMessageKey(String key, Object...args){ return OAuth2Errors.messageKey(RequestContext.locale(),key,args); } public static MessageKey createRandomKey(){
public static String get(String key){ return RequestContext.current().getMessageSource().getMessage(key); }
@Override public Validation createValidation() { return new DefaultValidation(this, new SimpleErrors(RequestContext.locale())); }