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

org.molgenis.data.security.auth.RoleMembershipMetadata Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data.security.auth;

import static java.util.Objects.requireNonNull;
import static org.molgenis.data.meta.AttributeType.DATE_TIME;
import static org.molgenis.data.meta.AttributeType.XREF;
import static org.molgenis.data.meta.model.EntityType.AttributeRole.ROLE_ID;
import static org.molgenis.data.meta.model.Package.PACKAGE_SEPARATOR;
import static org.molgenis.data.security.auth.SecurityPackage.PACKAGE_SECURITY;

import org.molgenis.data.meta.SystemEntityType;
import org.springframework.stereotype.Component;

@Component
public class RoleMembershipMetadata extends SystemEntityType {
  private static final String SIMPLE_NAME = "RoleMembership";
  public static final String ROLE_MEMBERSHIP = PACKAGE_SECURITY + PACKAGE_SEPARATOR + SIMPLE_NAME;

  public static final String ID = "id";
  public static final String USER = "user";
  public static final String FROM = "from";
  public static final String TO = "to";
  public static final String ROLE = "role";

  private final SecurityPackage securityPackage;
  private final UserMetadata userMetadata;
  private final RoleMetadata roleMetadata;

  public RoleMembershipMetadata(
      SecurityPackage securityPackage, UserMetadata userMetadata, RoleMetadata roleMetadata) {
    super(SIMPLE_NAME, PACKAGE_SECURITY);
    this.securityPackage = requireNonNull(securityPackage);
    this.userMetadata = requireNonNull(userMetadata);
    this.roleMetadata = requireNonNull(roleMetadata);
  }

  @Override
  public void init() {
    setPackage(securityPackage);

    setLabel("Role Membership");
    setDescription("Records the fact that a User is a member of a Role during an interval.");

    addAttribute(ID, ROLE_ID).setAuto(true).setLabel("Identifier");
    addAttribute(USER)
        .setLabel("User")
        .setDataType(XREF)
        .setRefEntity(userMetadata)
        .setNillable(false);
    addAttribute(ROLE)
        .setLabel("Role")
        .setDataType(XREF)
        .setRefEntity(roleMetadata)
        .setNillable(false);
    addAttribute(FROM).setLabel("From").setDataType(DATE_TIME).setNillable(false);
    addAttribute(TO).setLabel("To").setDataType(DATE_TIME);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy