java-doc
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / dataschema / User.java
index 644e5bd..859938f 100644 (file)
@@ -8,6 +8,8 @@
 package ch.bfh.ti.srs.dataschema;
 
 import ch.bfh.ti.srs.extern.Password;
+import java.util.HashSet;
+import java.util.Set;
 
 public class User implements Cloneable{
 
@@ -16,16 +18,17 @@ public class User implements Cloneable{
        private String mail;
        private String name;
        private String lastname;
+       private Set<Permissions> permissions;
 
        /**
-        * Constructor for already existing user in the Datacontext
-        * Only to be used by DataHandler implementation!
+        * Constructor for already existing <code>User</code> in the Datacontext.
+        * Only to be used by <code>DataHandler</code> implementation!
         * 
-        * @param userName                      Username
-        * @param hashedPassword        Encrypted password
-        * @param mail                          Mail
-        * @param name                          Name
-        * @param lastname                      Lastname
+        * @param userName                      user name
+        * @param hashedPassword        encrypted password
+        * @param mail                          mail
+        * @param name                          name
+        * @param lastname                      last name
         */
        //TODO: Change constructor to package when DataHandlerForExcel is moved back to this package
        public User(String userName, String hashedPassword, String mail, String name, String lastname){
@@ -34,14 +37,15 @@ public class User implements Cloneable{
                this.mail = mail;
                this.name = name;
                this.lastname = lastname;
+               permissions = new HashSet<>();
        }
 
        /**
         * Normal constructor for new users created in the UserController
         * 
-        * @param userName
-        * @param password
-        * @throws Exception
+        * @param userName                                      user name
+        * @param password                                      password
+        * @throws IllegalArgumentException     user name or password does not meet requirements
         */
        public User(String userName, String password) throws Exception{
                if(userName == null) throw new IllegalArgumentException("Username must not be null");
@@ -127,8 +131,40 @@ public class User implements Cloneable{
                return m.matches();
        }
        
+       /* (non-Javadoc)
+        * @see java.lang.Object#clone()
+        */
        @Override
     public User clone() throws CloneNotSupportedException {
         return (User)super.clone();
     }
+       
+       /**
+        * @param permission
+        */
+       public void addPermission(Permissions permission){
+               permissions.add(permission);
+       }
+       
+       /**
+        * @param permission
+        */
+       public void removePermission(Permissions permission){
+               if(permissions.contains(permission)) permissions.remove(permission);
+       }
+       
+       /**
+        * @return
+        */
+       public Set<Permissions> getPermissions(){
+               return permissions;
+       }
+       
+       /**
+        * @param permission
+        * @return
+        */
+       public boolean hasPermission(Permissions permission){
+               return permissions.contains(permission);
+       }
 }
\ No newline at end of file