All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.management.api.auth.HermesSecurityAwareRequestUser Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
package pl.allegro.tech.hermes.management.api.auth;

import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.SecurityContext;
import pl.allegro.tech.hermes.api.OwnerId;
import pl.allegro.tech.hermes.management.api.auth.SecurityProvider.OwnershipResolver;
import pl.allegro.tech.hermes.management.domain.auth.RequestUser;

public class HermesSecurityAwareRequestUser implements RequestUser {
  private final String username;
  private final boolean isAdmin;
  private final OwnershipResolver ownershipResolver;

  public HermesSecurityAwareRequestUser(ContainerRequestContext requestContext) {
    SecurityContext securityContext = requestContext.getSecurityContext();
    username = securityContext.getUserPrincipal().getName();
    isAdmin = securityContext.isUserInRole(Roles.ADMIN);
    ownershipResolver =
        (OwnershipResolver) requestContext.getProperty(AuthorizationFilter.OWNERSHIP_RESOLVER);
  }

  @Override
  public String getUsername() {
    return username;
  }

  @Override
  public boolean isAdmin() {
    return isAdmin;
  }

  @Override
  public boolean isOwner(OwnerId ownerId) {
    return ownershipResolver.isUserAnOwner(ownerId);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy