base.security.PersonRole Maven / Gradle / Ivy
/**
* Creative commons Attribution-NonCommercial license.
*
* http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB
*
* NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
*/
package base.security;
import java.util.UUID;
import base.QueryResult;
import base.json.Json;
/**
* Role information. getPerson() may or may
* not be set depending on the Command that is returning
* the role object.
*/
public class PersonRole implements QueryResult {
private Person person;
private UUID personUuid;
private String resource;
private String uid;
private String role;
public PersonRole(Person person, String resource, String uid, String role) {
this.personUuid = person.getUuid();
this.resource = resource;
this.uid = uid;
this.person = person;
this.role = role;
if(resource == null && uid != null) {
throw new IllegalArgumentException("If a uid is specified, a resource type must be specified.");
}
if(resource != null && uid == null) {
throw new IllegalArgumentException("If a resource type is specified, a uid must be specified.");
}
}
public PersonRole(UUID personUuid, String role) {
this.personUuid = personUuid;
this.role = role;
}
public PersonRole(UUID personUuid, String resource, String uid, String role) {
this.personUuid = personUuid;
this.resource = resource;
this.uid = uid;
this.role = role;
if(resource == null && uid != null) {
throw new IllegalArgumentException("If a uid is specified, a resource type must be specified.");
}
if(resource != null && uid == null) {
throw new IllegalArgumentException("If a resource type is specified, a uid must be specified.");
}
}
public Person getPerson() {
return person;
}
public UUID getPersonUuid() {
return personUuid;
}
public String getResource() {
return resource;
}
public String getUid() {
return uid;
}
public String getRole() {
return role;
}
public String toString() {
return toJson();
}
@Override
public String toJson() {
return "{" +
"\"person\":\"" + personUuid.toString() + "\"," +
(resource != null?"\"resource\":\"" + resource + "\",":"") +
(uid != null?"\"uid\":\"" + uid + "\",":"") +
"\"role\":\"" + Json.escape(role) + "\"" +
"}";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy