/** * Check if subject has the specified scope. * * @param subject subject of a user * @param scope scope the subject should have * @return true if the subject has all the specified scopes */ public static boolean inScope(Subject subject, String scope) { List<String> grants = subject.grantsByType("scope").stream().map(Grant::getName).collect(Collectors.toList()); return grants.contains(scope); }
/** * Check if subject has the specified scopes (must have all of them). * * @param subject subject of a user * @param scopes scopes the subject should have * @return true if the subject has all the specified scopes */ public static boolean inScopes(Subject subject, String... scopes) { List<String> grants = subject.grantsByType("scope").stream().map(Grant::getName).collect(Collectors.toList()); for (String scope : scopes) { if (!grants.contains(scope)) { return false; } } return true; } }
List<Grant> userScopes = subject.grantsByType(SCOPE_GRANT_TYPE);
Subject subject = buildSubject(jwt, signed); Set<String> scopes = subject.grantsByType("scope") .stream() .map(Grant::getName)
/** * Check if subject has the specified scope. * * @param subject subject of a user * @param scope scope the subject should have * @return true if the subject has all the specified scopes */ public static boolean inScope(Subject subject, String scope) { List<String> grants = subject.grantsByType("scope").stream().map(Grant::getName).collect(Collectors.toList()); return grants.contains(scope); }
/** * Check if subject has the specified scopes (must have all of them). * * @param subject subject of a user * @param scopes scopes the subject should have * @return true if the subject has all the specified scopes */ public static boolean inScopes(Subject subject, String... scopes) { List<String> grants = subject.grantsByType("scope").stream().map(Grant::getName).collect(Collectors.toList()); for (String scope : scopes) { if (!grants.contains(scope)) { return false; } } return true; } }
List<Grant> userScopes = subject.grantsByType(SCOPE_GRANT_TYPE);