00001 // Role.h 00002 00003 #ifndef ROLE_H 00004 #define ROLE_H 00005 00006 #include <bitset> 00007 00008 #include "Privilege.h" 00009 00010 namespace Yosokumo 00011 { 00012 /** 00013 * A set of privileges granted to a particular user for a particular study. 00014 * One of the privileges granted to a study creator is the authority to 00015 * create new roles on the study for other enrolled users. In this way, 00016 * the study creator can allow others to load data, get predictions, view 00017 * study statistics, or even themselves grant privileges on the study to 00018 * other users. Roles may be severely limited or provide full access and 00019 * may be changed or revoked at any time. 00020 * <p> 00021 * When an enrolled user creates a study, he is authorized automatically to 00022 * perform any action on that study. More precisely, when a study is created, 00023 * the service simultaneously creates a role for the creator on the newly 00024 * created study in which all privileges are set to <code>true</code>. 00025 * <p> 00026 * A single user may have a role on many studies; conversely, many users may 00027 * have a role on a single study. The list of studies on which a particular 00028 * user has a role is called the catalog for that user. The list of users 00029 * that have a role on a particular study is called the roster for that study. 00030 * <p> 00031 * A <code>Role</code> has these attributes: 00032 * <ul> 00033 * <li>a user identifier and a user name 00034 * <li>a study identifier and a study name 00035 * <li>a set of 13 booleans specifying which operations the user may perform 00036 * on the study 00037 * </ul> 00038 * 00039 * @author Roger House 00040 * @version 0.9 00041 */ 00042 class Role 00043 { 00044 std::string userIdentifier; 00045 std::string userName; 00046 00047 std::string studyIdentifier; 00048 std::string studyName; 00049 00050 std::string roleLocation; 00051 00052 std::bitset<Privilege::NUMBER_OF_PRIVILEGES> privilegeSet; 00053 00054 public: 00055 00056 // Constructors 00057 00058 /** 00059 * Initializes a newly created <code>Role</code> object with default 00060 * attributes. 00061 * 00062 */ 00063 Role(); 00064 00065 /** 00066 * Initializes a newly created <code>Role</code> object with attributes 00067 * specified by the input parameters. 00068 * 00069 * @param userIdentifier the user who has the role. 00070 * @param studyIdentifier the study on which the user has the role. 00071 */ 00072 Role( 00073 const std::string &userIdentifier, 00074 const std::string &studyIdentifier); 00075 00076 /** 00077 * Copy constructor - initializes a newly created <code>Role</code> 00078 * object with a copy of another <code>Role</code> object. 00079 * 00080 * @param rhs the <code>Role</code> to make a copy of. 00081 */ 00082 Role(const Role &rhs); 00083 00084 00085 /** 00086 * Destructor - destroy a <code>Role</code> object. 00087 */ 00088 virtual ~Role(); 00089 00090 /** 00091 * Assignment operator - assign one <code>Role</code> to another. 00092 * 00093 * @param rhs the righthand side of the assignment. 00094 * 00095 * @return a reference to <code>this</code> Role. 00096 */ 00097 Role& operator=(const Role& rhs); 00098 00099 /** 00100 * Equality operator - compare two <code>Roles</code> for equality. 00101 * 00102 * @param rhs the righthand side of the equality. 00103 * 00104 * @return <code>true</code> if and only if <code>this</code> 00105 * <code>Roles</code> and the righthand side 00106 * <code>Roles</code> are identically equal. 00107 */ 00108 bool operator==(const Role &rhs) const; 00109 00110 /** 00111 * Inequality operator - compare two <code>Roles</code> for inequality. 00112 * 00113 * @param rhs the righthand side of the inequality. 00114 * 00115 * @return <code>true</code> if and only if <code>this</code> 00116 * <code>Roles</code> and the righthand side 00117 * <code>Roles</code> are not identically equal. 00118 */ 00119 bool operator!=(const Role &rhs) const; 00120 00121 00122 // Setters and getters 00123 00124 /** 00125 * Set the role location. 00126 * 00127 * @param loc the location to assign to this role. May be null. 00128 * 00129 * @return this <code>Role</code>. 00130 */ 00131 Role &setRoleLocation(const std::string &loc); 00132 00133 /** 00134 * Return the role location. 00135 * 00136 * @return the location of this role. May be null. 00137 */ 00138 std::string getRoleLocation() const; 00139 00140 /** 00141 * Set the user identifier. 00142 * 00143 * @param userIdentifier the user identifier to assign to this role. 00144 * 00145 * @return this <code>Role</code>. 00146 */ 00147 Role &setUserIdentifier(const std::string &userIdentifier); 00148 00149 /** 00150 * Return the user identifier. 00151 * 00152 * @return the user identifier of this role. May be null. 00153 */ 00154 std::string getUserIdentifier() const; 00155 00156 00157 /** 00158 * Set the user name. 00159 * 00160 * @param name the user name to assign to this role. May be null. 00161 * 00162 * @return this <code>Role</code>. 00163 */ 00164 Role &setUserName(const std::string &name); 00165 00166 /** 00167 * Return the user name. 00168 * 00169 * @return the name of the user of this role. May be null. 00170 */ 00171 std::string getUserName() const; 00172 00173 00174 /** 00175 * Set the study identifier. 00176 * 00177 * @param studyIdentifier the study identifier to assign to this role. 00178 * 00179 * @return this <code>Role</code>. 00180 */ 00181 Role &setStudyIdentifier(const std::string &studyIdentifier); 00182 00183 /** 00184 * Return the study identifier. 00185 * 00186 * @return the study identifier of this role. May be null. 00187 */ 00188 std::string getStudyIdentifier() const; 00189 00190 00191 /** 00192 * Set the study name. 00193 * 00194 * @param name the name to assign to the study of this role. 00195 * May be null. 00196 * 00197 * @return this <code>Role</code>. 00198 */ 00199 Role &setStudyName(const std::string &name); 00200 00201 /** 00202 * Return the study name. 00203 * 00204 * @return the name of the study of this role. May be null. 00205 */ 00206 std::string getStudyName() const; 00207 00208 00209 // Get and set privileges 00210 00211 /** 00212 * Add a privilege. Grant a specific privilege. 00213 * 00214 * @param privilege is the privilege to grant. 00215 * 00216 * @return this <code>Role</code>. 00217 */ 00218 Role &addPrivilege(Privilege privilege); 00219 00220 /** 00221 * Remove a privilege. A specific privilege is removed. 00222 * 00223 * @param privilege is the privilege to remove. 00224 * 00225 * @return this <code>Role</code>. 00226 */ 00227 Role &removePrivilege(Privilege privilege); 00228 00229 /** 00230 * Add all privileges. All privileges are granted. 00231 * 00232 * @return this <code>Role</code>. 00233 */ 00234 Role &addAllPrivileges(); 00235 00236 /** 00237 * Remove all privileges. 00238 * 00239 * @return this <code>Role</code>. 00240 */ 00241 Role &removeAllPrivileges(); 00242 00243 /** 00244 * Get a specific privilege. 00245 * 00246 * @param privilege is the privilege to check for. 00247 * 00248 * @return <code>true</code> if <code>privilege</code> is granted, 00249 * <code>false</code> otherwise. 00250 */ 00251 bool getPrivilege(Privilege privilege) const; 00252 00253 // Utility 00254 00255 /** 00256 * Return a string representation of this <code>Role</code>. 00257 * 00258 * @return the string representation of this <code>Role</code>. 00259 */ 00260 std::string toString() const; 00261 00262 /** 00263 * Return a string representation of this <code>Role</code>. 00264 * 00265 * @param showAll specifies if internal data members should be shown. 00266 * @return the string representation of this <code>Role</code>. 00267 */ 00268 std::string toStringInternal(bool showAll) const; 00269 00270 }; // end class Role 00271 00272 } // end namespace Yosokumo 00273 00274 #endif // ROLE_H 00275 00276 // end Role.h