Scope { public static String forEntity(final AbstractAuthzEntity entity, final Boolean admin) { if (entity instanceof Application) { return admin ? APPLICATION_ADMIN : APPLICATION; } if (entity instanceof Authenticator) { return admin ? AUTHENTICATOR_ADMIN : AUTHENTICATOR; } if (entity instanceof Client) { return admin ? CLIENT_ADMIN : CLIENT; } if (entity instanceof UserIdentity) { return admin ? IDENTITY_ADMIN : IDENTITY; } if (entity instanceof Role) { return admin ? ROLE_ADMIN : ROLE; } if (entity instanceof User) { return admin ? USER_ADMIN : USER; } if (entity instanceof ApplicationScope) { return admin ? SCOPE_ADMIN : SCOPE; } if (entity instanceof OAuthToken) { return admin ? TOKEN_ADMIN : TOKEN; } return "kangaroo:unknown"; } private  Scope(); static List<String> allScopes(); static List<String> adminScopes(); static List<String> userScopes(); static String forEntity(final AbstractAuthzEntity entity,
                                   final Boolean admin); static final String USER; static final String USER_ADMIN; static final String APPLICATION; static final String APPLICATION_ADMIN; static final String AUTHENTICATOR; static final String AUTHENTICATOR_ADMIN; static final String CLIENT; static final String CLIENT_ADMIN; static final String IDENTITY; static final String IDENTITY_ADMIN; static final String TOKEN; static final String TOKEN_ADMIN; static final String ROLE; static final String ROLE_ADMIN; static final String SCOPE; static final String SCOPE_ADMIN; }
@Test public void testGetScopeForEntity() { assertEquals(Scope.APPLICATION, Scope.forEntity(new Application(), false)); assertEquals(Scope.APPLICATION_ADMIN, Scope.forEntity(new Application(), true)); assertEquals(Scope.AUTHENTICATOR, Scope.forEntity(new Authenticator(), false)); assertEquals(Scope.AUTHENTICATOR_ADMIN, Scope.forEntity(new Authenticator(), true)); assertEquals(Scope.CLIENT, Scope.forEntity(new Client(), false)); assertEquals(Scope.CLIENT_ADMIN, Scope.forEntity(new Client(), true)); assertEquals(Scope.USER, Scope.forEntity(new User(), false)); assertEquals(Scope.USER_ADMIN, Scope.forEntity(new User(), true)); assertEquals(Scope.ROLE, Scope.forEntity(new Role(), false)); assertEquals(Scope.ROLE_ADMIN, Scope.forEntity(new Role(), true)); assertEquals(Scope.IDENTITY, Scope.forEntity(new UserIdentity(), false)); assertEquals(Scope.IDENTITY_ADMIN, Scope.forEntity(new UserIdentity(), true)); assertEquals(Scope.SCOPE, Scope.forEntity(new ApplicationScope(), false)); assertEquals(Scope.SCOPE_ADMIN, Scope.forEntity(new ApplicationScope(), true)); assertEquals(Scope.TOKEN, Scope.forEntity(new OAuthToken(), false)); assertEquals(Scope.TOKEN_ADMIN, Scope.forEntity(new OAuthToken(), true)); assertEquals("kangaroo:unknown", Scope.forEntity(null, true)); }