throw new UnauthenticatedException("Authentication required"); throw new UnauthenticatedException("Guest required"); throw new UnauthenticatedException("User required");
@AroundInvoke public Object aroundInvoke(InvocationContext context) throws Exception { final User user = authenticationService.getUser(); final Collection<RestrictedAccess> annotations = getRestrictedAccessAnnotations(context.getTarget().getClass(), context.getMethod()); final Set<Role> roles = AnnotationUtils.mergeRoles(roleExtractor, annotations); if (User.ANONYMOUS.equals(user)) { throw new UnauthenticatedException(); } else if (!user.getRoles().containsAll(roles)) { throw new UnauthorizedException(); } else { return context.proceed(); } }
private void securityCheck(final Set<Role> requiredRoleNames, final RemoteCallContext callContext) { if (securityContext.isUserCacheValid()) { if (securityContext.hasCachedUser()) { if (securityContext.getCachedUser().getRoles().containsAll(requiredRoleNames)) { callContext.proceed(new RemoteCallback<Object>() { @Override public void callback(final Object response) { callContext.setResult(response); } }, new ErrorCallback<Object>() { @Override public boolean error(Object message, Throwable throwable) { if (throwable instanceof UnauthenticatedException) { securityContext.invalidateCache(); } return true; } }); } else { throw new UnauthorizedException(); } } else { throw new UnauthenticatedException(); } } else { callContext.proceed(); } }
private void securityCheck(final Set<Role> requiredRoleNames, final RemoteCallContext callContext) { if (securityContext.isUserCacheValid()) { if (securityContext.hasCachedUser()) { if (securityContext.getCachedUser().getRoles().containsAll(requiredRoleNames)) { callContext.proceed(new RemoteCallback<Object>() { @Override public void callback(final Object response) { callContext.setResult(response); } }, new ErrorCallback<Object>() { @Override public boolean error(Object message, Throwable throwable) { if (throwable instanceof UnauthenticatedException) { securityContext.invalidateCache(); } return true; } }); } else { throw new UnauthorizedException(); } } else { throw new UnauthenticatedException(); } } else { callContext.proceed(); } }