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

org.lable.rfc3881.auditlogger.api.Principal Maven / Gradle / Ivy

package org.lable.rfc3881.auditlogger.api;


import org.lable.codesystem.codereference.Identifiable;
import org.lable.codesystem.codereference.Referenceable;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.lable.rfc3881.auditlogger.api.util.ParameterValidation.collectionMayNotBeNullOrEmpty;
import static org.lable.rfc3881.auditlogger.api.util.ParameterValidation.parameterMayNotBeNull;

/**
 * Security identity of a user or automated process. This includes the relevant security roles for the action that
 * was performed.
 */
public class Principal implements Identifiable, Serializable {
    private static final long serialVersionUID = -7367595173448586271L;

    /* Required fields. */

    /**
     * Unique identifier for the user actively participating in the event.
     * 

* IETF/RFC 3881 §5.2.1. User ID. */ final String userId; /* Optional fields. */ /** * Alternative unique identifiers for the user. *

* IETF/RFC 3881 §5.2.2. Alternative User ID. */ final String alternateUserId; /** * The human-meaningful name for the user. *

* IETF/RFC 3881 §5.2.3. User Name. */ final String name; /** * Specification of the role(s) the user plays when performing the event, as assigned in role-based access * control security. *

* IETF/RFC 3881 §5.2.5. Role ID Code. */ final List relevantRoles; /** * Define a principal. * * @param userId Unique user ID. * @param relevantRoles List of roles relevant for the action performed. */ public Principal(String userId, Referenceable... relevantRoles) { this(userId, null, null, relevantRoles); } /** * Define a principal. * * @param userId Unique user ID. * @param alternateUserId Synonymous user ID. * @param name Human readable name. * @param relevantRoles List of roles relevant for the action performed. */ public Principal(String userId, String alternateUserId, String name, Referenceable... relevantRoles) { parameterMayNotBeNull("userId", userId); this.userId = userId; this.alternateUserId = alternateUserId; this.name = name; this.relevantRoles = Arrays.asList(relevantRoles); } public String getUserId() { return userId; } public List getRelevantRoles() { return relevantRoles; } public String getName() { return name; } public String getAlternateUserId() { return alternateUserId; } /** * {@inheritDoc} */ @Override public List identifyingStack() { return Collections.singletonList(getUserId()); } @Override public String toString() { return "ID: " + getUserId() + (getName() == null || getName().isEmpty() ? "" : "\nName: " + getName()) + (getAlternateUserId() == null ? "" : "\nAlt ID: " + getAlternateUserId()) + "\nRoles: " + (getRelevantRoles() == null ? "[]" : getRelevantRoles()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy