001/* 002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Bogdan Stefanescu 011 */ 012package org.nuxeo.ecm.core.api; 013 014import java.io.Serializable; 015import java.security.Principal; 016import java.util.List; 017 018/** 019 * Class to represent a principal in Nuxeo. This class holds the list of roles and groups for this principal. 020 */ 021public interface NuxeoPrincipal extends Principal, Serializable { 022 023 String PREFIX = "user:"; 024 025 /** 026 * Gets the first name of this principal. 027 * 028 * @return the first name of this principal 029 */ 030 String getFirstName(); 031 032 /** 033 * Gets the last name of this principal. 034 * 035 * @return the last name of this principal 036 */ 037 String getLastName(); 038 039 /** 040 * Gets the password of this principal. 041 * <p> 042 * Note: Some APIs that return principals from the database intentionally do not fill this field 043 * 044 * @return the password of this principal 045 */ 046 String getPassword(); 047 048 /** 049 * Gets the company name of this principal. 050 * 051 * @return the company name 052 */ 053 String getCompany(); 054 055 /** 056 * Get the user email if any. Return null if not email was specified 057 * 058 * @return the user email or null if none 059 */ 060 String getEmail(); 061 062 /** 063 * Gets the groups this principal is directly member of. 064 * 065 * @return the list of the groups 066 */ 067 List<String> getGroups(); 068 069 /** 070 * Gets the groups this principal directly or undirectly is member of. 071 * 072 * @return the list of the groups 073 */ 074 List<String> getAllGroups(); 075 076 /** 077 * Recursively test if the user is member of this group. 078 * 079 * @param group The name of the group 080 */ 081 boolean isMemberOf(String group); 082 083 /** 084 * Gets the roles for this principal. 085 * 086 * @return the list of the roles 087 */ 088 List<String> getRoles(); 089 090 void setName(String name); 091 092 void setFirstName(String firstName); 093 094 void setLastName(String lastName); 095 096 void setGroups(List<String> groups); 097 098 void setRoles(List<String> roles); 099 100 void setCompany(String company); 101 102 void setPassword(String password); 103 104 void setEmail(String email); 105 106 /** 107 * Returns a generated id that is unique for each principal instance. 108 * 109 * @return a unique string 110 */ 111 String getPrincipalId(); 112 113 /** 114 * Sets the principalId. 115 * 116 * @param principalId a new principalId for this instance 117 */ 118 void setPrincipalId(String principalId); 119 120 DocumentModel getModel(); 121 122 void setModel(DocumentModel model); 123 124 /** 125 * Returns true if the principal is an administrator. 126 * <p> 127 * Security checks still apply on the repository for administrator user. If user is a system user, this method will 128 * return true. 129 * 130 * @return true if the principal is an administrator. 131 */ 132 boolean isAdministrator(); 133 134 /** 135 * Returns the {@code tenantId} of this {@NuxeoPrincipal}, or {@code null} if there is no 136 * {@code tenantId}. 137 * 138 * @since 5.6 139 */ 140 String getTenantId(); 141 142 /** 143 * Checks if the principal is anonymous (guest user). 144 * 145 * @return true if the principal is anonymous. 146 */ 147 boolean isAnonymous(); 148 149 /** 150 * Gets the base user from which this principal was created, or {@code null} if this principal was not created from 151 * another user. 152 * 153 * @return the originating user, or {@code null} 154 */ 155 String getOriginatingUser(); 156 157 /** 158 * Sets the originating user. 159 * 160 * @param originatingUser the originating user 161 */ 162 void setOriginatingUser(String originatingUser); 163 164 /** 165 * Gets the acting user for this principal. 166 * <p> 167 * This is the originating user (usually when this principal is a system user), or if there is none this principal's 168 * user. 169 * 170 * @return the acting user 171 * @since 6.0 172 */ 173 String getActingUser(); 174 175}