public AccessLevel getAccessLevel ( String token , String applicationId ) throws CloudFoundryAuthorizationException { try { URI uri = getPermissionsUri ( applicationId ) ; RequestEntity < ? > request = RequestEntity . get ( uri ) . header ( "Authorization" , "bearer " + token ) . build ( ) ; Map < ? , ? > body = this . restTemplate . exchange ( request , Map . class ) . getBody ( ) ; if ( Boolean . TRUE . equals ( body . get ( "read_sensitive_data" ) ) ) { return AccessLevel . FULL ; } return AccessLevel . RESTRICTED ; } catch ( HttpClientErrorException ex ) { if ( ex . getStatusCode ( ) . equals ( HttpStatus . FORBIDDEN ) ) { throw new CloudFoundryAuthorizationException ( Reason . ACCESS_DENIED , "Access denied" ) ; } throw new CloudFoundryAuthorizationException ( Reason . INVALID_TOKEN , "Invalid token" , ex ) ; } catch ( HttpServerErrorException ex ) { throw new CloudFoundryAuthorizationException ( Reason . SERVICE_UNAVAILABLE , "Cloud controller not reachable" ) ; } }
Return the access level that should be granted to the given token .