001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.security; 029 030import org.opencms.util.CmsUUID; 031 032import java.io.Serializable; 033import java.security.Principal; 034import java.util.Locale; 035 036/** 037 * Representation of an identity in the cms (currently user or group), 038 * used to define permissions on a resource.<p> 039 * 040 * @since 6.0.0 041 */ 042public interface I_CmsPrincipal extends Principal, Serializable { 043 044 /** Upper limit for core flags, any principal object with flags greater than this value will be filtered out. */ 045 int FLAG_CORE_LIMIT = 65536; // 2^16 046 047 /** This flag is set for disabled principals in the database. */ 048 int FLAG_DISABLED = 1; 049 050 /** This flag is set for enabled principals in the database. */ 051 int FLAG_ENABLED = 0; 052 053 /** Flag to indicate a role group. */ 054 int FLAG_GROUP_ROLE = 1048576; // 2^20 >> FLAG_CORE_LIMIT 055 056 /** 057 * Flag to indicate a virtual group role, after this bit we need to encode a number between 0 and 058 * <code>{@link CmsRole#getSystemRoles()}.size()-1</code> so we will need up to 4 more bits. 059 */ 060 int FLAG_GROUP_VIRTUAL = 1024; // 2^10 << FLAG_CORE_LIMIT 061 062 /** Flag to indicate a user is not able to manage himself. */ 063 int FLAG_USER_MANAGED = 2; 064 065 /** Flag to indicate a user is a webuser. */ 066 int FLAG_USER_WEBUSER = 32768; //2^15 067 068 /** Identifier for group principals. */ 069 String PRINCIPAL_GROUP = "GROUP"; 070 071 /** Identifier for user principals. */ 072 String PRINCIPAL_USER = "USER"; 073 074 /** 075 * Checks if the provided principal name is valid and can be used as an argument value 076 * for {@link #setName(String)}.<p> 077 * 078 * @param name the principal name to check 079 */ 080 void checkName(String name); 081 082 /** 083 * Compares the given object with this principal.<p> 084 * 085 * @param obj object to compare 086 * @return true if the object is equal 087 */ 088 boolean equals(Object obj); 089 090 /** 091 * Returns the description of this principal.<p> 092 * 093 * @return the description of this principal 094 */ 095 String getDescription(); 096 097 /** 098 * Returns the description of this principal.<p> 099 * @param locale locale of the description 100 * 101 * @return the description of this principal 102 */ 103 String getDescription(Locale locale); 104 105 /** 106 * Returns the flags of this principal.<p> 107 * 108 * The principal flags are used to store special information about the 109 * principals state encoded bitwise. Usually the flags int value should not 110 * be directly accessed. Utility methods like <code>{@link #isEnabled()}</code> 111 * provide a much easier way to access the information contained in the flags.<p> 112 * 113 * @return the flags of this principal 114 */ 115 int getFlags(); 116 117 /** 118 * Returns the unique id of this principal.<p> 119 * 120 * @return the unique id of this principal 121 */ 122 CmsUUID getId(); 123 124 /** 125 * Returns the unique name of this principal.<p> 126 * 127 * @return the unique name of this principal 128 */ 129 String getName(); 130 131 /** 132 * Returns the fully qualified name of the associated organizational unit.<p> 133 * 134 * @return the fully qualified name of the associated organizational unit 135 */ 136 String getOuFqn(); 137 138 /** 139 * Returns this principals unique name prefixed with it's type.<p> 140 * 141 * The type prefix can either be <code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}.</code> 142 * (for groups) or <code>{@link I_CmsPrincipal#PRINCIPAL_USER}.</code> (for users).<p> 143 * 144 * @return this principals unique name prefixed with this principals type 145 */ 146 String getPrefixedName(); 147 148 /** 149 * Returns the simple name of this organizational unit. 150 * 151 * @return the simple name of this organizational unit. 152 */ 153 String getSimpleName(); 154 155 /** 156 * Returns the hash code of this object.<p> 157 * 158 * @return the hash code 159 */ 160 int hashCode(); 161 162 /** 163 * Returns <code>true</code> if this principal is enabled.<p> 164 * 165 * A principal may be disabled in order to disable it, for example to prevent 166 * logins of a user. If a principal is just disabled but not deleted, 167 * the credentials of the principal in the VFS are still valid.<p> 168 * 169 * @return <code>true</code> if this principal is enabled 170 */ 171 boolean isEnabled(); 172 173 /** 174 * Returns <code>true</code> if this principal is of type <code>{@link org.opencms.file.CmsGroup}</code>.<p> 175 * 176 * @return <code>true</code> if this principal is of type <code>{@link org.opencms.file.CmsGroup}</code> 177 */ 178 boolean isGroup(); 179 180 /** 181 * Returns <code>true</code> if this principal is of type <code>{@link org.opencms.file.CmsUser}</code>.<p> 182 * 183 * @return <code>true</code> if this principal is of type <code>{@link org.opencms.file.CmsUser}</code> 184 */ 185 boolean isUser(); 186 187 /** 188 * Sets the description of this principal.<p> 189 * 190 * @param description the principal description to set 191 */ 192 void setDescription(String description); 193 194 /** 195 * Enables (or disables) this principal, depending on the given status.<p> 196 * 197 * @param enabled the principal status to set 198 */ 199 void setEnabled(boolean enabled); 200 201 /** 202 * Sets this principals flags to the specified value.<p> 203 * 204 * The principal flags are used to store special information about the 205 * principals state encoded bitwise. Usually the flags integer value should not 206 * be directly accessed. Utility methods like <code>{@link #setEnabled(boolean)}</code> 207 * provide a much easier way to manipulate the information contained in the flags.<p> 208 * 209 * @param value the value to set this principals flags to 210 */ 211 void setFlags(int value); 212 213 /** 214 * Sets the unique name of this principal.<p> 215 * 216 * @param name the unique name of this principal to set 217 */ 218 void setName(String name); 219}