static HttpWrapper[] assembleWrappers(FastHttp http, RouteOptions options) { List<HttpWrapper> wrappers = U.list(); wrappers.add(new HttpAuthWrapper(options.roles())); TransactionMode txMode = U.or(options.transaction(), TransactionMode.NONE); if (txMode != TransactionMode.NONE) { wrappers.add(new HttpTxWrapper(txMode)); } Collections.addAll(wrappers, getConfiguredWrappers(http, options)); return U.arrayOf(HttpWrapper.class, wrappers); }
@Override public Object wrap(final Req req, final HandlerInvocation invocation) throws Exception { TokenAuthData auth = HttpUtils.getAuth(req); String username = auth != null ? auth.user : null; if (U.isEmpty(username)) { HttpUtils.clearUserData(req); } Set<String> roles = userRoles(req, username); Set<String> scope = auth != null ? auth.scope : null; if (U.notEmpty(requiredRoles) && !Secure.hasAnyRole(username, roles, requiredRoles)) { throw new SecurityException("The user doesn't have the required roles!"); } Ctx ctx = Ctxs.required(); ctx.setUser(new UserInfo(username, roles, scope)); return invocation.invoke(); }
static HttpWrapper[] assembleWrappers(FastHttp http, RouteOptions options) { List<HttpWrapper> wrappers = U.list(); wrappers.add(new HttpAuthWrapper(options.roles())); TransactionMode txMode = U.or(options.transaction(), TransactionMode.NONE); if (txMode != TransactionMode.NONE) { wrappers.add(new HttpTxWrapper(txMode)); } Collections.addAll(wrappers, getConfiguredWrappers(http, options)); return U.arrayOf(HttpWrapper.class, wrappers); }
@Override public Object wrap(final Req req, final HandlerInvocation invocation) throws Exception { TokenAuthData auth = HttpUtils.getAuth(req); String username = auth != null ? auth.user : null; if (U.isEmpty(username)) { HttpUtils.clearUserData(req); } Set<String> roles = userRoles(req, username); Set<String> scope = auth != null ? auth.scope : null; if (U.notEmpty(requiredRoles) && !Secure.hasAnyRole(username, roles, requiredRoles)) { throw new SecurityException("The user doesn't have the required roles!"); } Ctx ctx = Ctxs.required(); ctx.setUser(new UserInfo(username, roles, scope)); return invocation.invoke(); }