code: public Principal buildSurrogatePrincipal(final String surrogate, final Principal primaryPrincipal, final Credential credentials,
                                               final RegisteredService registeredService) {
          val repositories = new HashSet<String>(0);
          if (registeredService != null) {
              repositories.addAll(registeredService.getAttributeReleasePolicy().getPrincipalAttributesRepository().getAttributeRepositoryIds());
          }
          val attributes = (Map) CoreAuthenticationUtils.retrieveAttributesFromAttributeRepository(attributeRepository, surrogate, repositories);
          val principal = principalFactory.createPrincipal(surrogate, attributes);
          return new SurrogatePrincipal(primaryPrincipal, principal);
      }
docs: Build principal.
  
  @param surrogate         the surrogate
  @param primaryPrincipal  the primary principal
  @param credentials       the credentials
  @param registeredService the registered service
  @return the principal