/** * @param token permanent user token * @param classKeys class keys * @return permission */ public ApiPermission getPermission(PermanentToken token, Map<String, List<FieldDescriptor>> classKeys) { if (token.getUserProfile() == null) { // Remove it, as it is clearly invalid. removePermanentToken(token); throw new IllegalStateException("All permanent tokens should have users"); } Profile profile = getProfile(token.getUserProfile().getUsername(), classKeys); if (profile == null) { removePermanentToken(token); throw new AuthenticationException("This token is not a valid access key: " + token); } ApiPermission.Level level; try { level = ApiPermission.Level.valueOf(token.getLevel()); } catch (IllegalArgumentException e) { String badLevel = token.getLevel(); removePermanentToken(token); throw new IllegalStateException("Token has illegal level: " + badLevel); } return new ApiPermission(profile, level); }
/** * @param token permanent user token * @param classKeys class keys * @return permission */ public ApiPermission getPermission(PermanentToken token, Map<String, List<FieldDescriptor>> classKeys) { if (token.getUserProfile() == null) { // Remove it, as it is clearly invalid. removePermanentToken(token); throw new IllegalStateException("All permanent tokens should have users"); } Profile profile = getProfile(token.getUserProfile().getUsername(), classKeys); if (profile == null) { removePermanentToken(token); throw new AuthenticationException("This token is not a valid access key: " + token); } ApiPermission.Level level; try { level = ApiPermission.Level.valueOf(token.getLevel()); } catch (IllegalArgumentException e) { String badLevel = token.getLevel(); removePermanentToken(token); throw new IllegalStateException("Token has illegal level: " + badLevel); } return new ApiPermission(profile, level); }