code: static void ensurePrincipalAccessIsAllowedForService(final Service service,
                                                           final RegisteredService registeredService,
                                                           final Authentication authentication,
                                                           final boolean retrievePrincipalAttributesFromReleasePolicy)
          throws UnauthorizedServiceException, PrincipalException {
          ensureServiceAccessIsAllowed(service, registeredService);
  
          val principal = authentication.getPrincipal();
          val principalAttrs =
              retrievePrincipalAttributesFromReleasePolicy && registeredService != null && registeredService.getAttributeReleasePolicy() != null
                  ? registeredService.getAttributeReleasePolicy().getAttributes(principal, service, registeredService)
                  : authentication.getPrincipal().getAttributes();
          val attributes = new HashMap<String, Object>(principalAttrs);
          attributes.putAll(authentication.getAttributes());
          ensurePrincipalAccessIsAllowedForService(service, registeredService, principal.getId(), attributes);
      }
docs: Ensure service access is allowed.
  
  @param service                                      the service
  @param registeredService                            the registered service
  @param authentication                               the authentication
  @param retrievePrincipalAttributesFromReleasePolicy retrieve attributes from release policy or simply rely on the principal attributes
  already collected. Setting this value to false bears the assumption that the policy
  has run already.
  @throws UnauthorizedServiceException the unauthorized service exception
  @throws PrincipalException           the principal exception