java-doc
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / dataschema / User.java
index 805b9cd..859938f 100644 (file)
@@ -8,24 +8,27 @@
 package ch.bfh.ti.srs.dataschema;
 
 import ch.bfh.ti.srs.extern.Password;
+import java.util.HashSet;
+import java.util.Set;
 
-public class User {
+public class User implements Cloneable{
 
        private final String userName;
        private String hashedPassword;
        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 {
                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");
@@ -126,4 +130,41 @@ public class User {
                java.util.regex.Matcher m = p.matcher(mail);
                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