Merge branch 'development' of git@git.bfh.ch:/staff/due1/sed-hs15-srs-purple.git...
authorMichael <Michael@Michael-LT.bfh.ch>
Tue, 8 Dec 2015 11:10:08 +0000 (12:10 +0100)
committerMichael <Michael@Michael-LT.bfh.ch>
Tue, 8 Dec 2015 11:10:08 +0000 (12:10 +0100)
src/main/java/ch/bfh/ti/srs/controller/SessionController.java
src/main/java/ch/bfh/ti/srs/controller/UserController.java
src/main/java/ch/bfh/ti/srs/dataschema/Role.java [copied from src/main/java/ch/bfh/ti/srs/dataschema/package-info.java with 75% similarity]
src/main/java/ch/bfh/ti/srs/dataschema/User.java
src/test/java/ch/bfh/ti/srs/dataschema/UserTest.java

index fe456b0..5c3099b 100644 (file)
@@ -9,6 +9,7 @@ package ch.bfh.ti.srs.controller;
 \r
 import java.rmi.AlreadyBoundException;\r
 import java.util.HashSet;\r
+import java.util.Map;\r
 import java.util.Set;\r
 \r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
@@ -64,6 +65,9 @@ public class SessionController {
                if (currentUser == null)\r
                        throw new Exception("No user is logged in");\r
                currentUser = null;\r
+               for (Controller controller : controllers) {\r
+                       \r
+               }\r
                controllers.clear();\r
        }\r
 \r
index 1cd60df..65d8820 100644 (file)
@@ -7,10 +7,14 @@
  */\r
 package ch.bfh.ti.srs.controller;\r
 \r
+import java.util.List;\r
 import java.util.Map;\r
+import java.util.Set;\r
 \r
+import ch.bfh.ti.daterange.DateRange;\r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
 import ch.bfh.ti.srs.dataschema.Reservation;\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
 import ch.bfh.ti.srs.dataschema.User;\r
 \r
 /**\r
@@ -102,4 +106,12 @@ public class UserController extends Controller{
                return super.deleteReservation_Super(reservation);\r
        }\r
 \r
+       /**\r
+        * {@inheritDoc}\r
+        */\r
+       public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark) throws Exception {\r
+               if (user == null) user = sc.getLoggedUser();\r
+               if (!user.equals(sc.getLoggedUser())) throw new Exception("You are not authorized to make this reservation");\r
+               return super.makeReservation(user, resource, dateRangeList, remark);\r
+       }\r
 }\r
@@ -6,3 +6,9 @@
  * Distributable under GPL license. See terms of license at gnu.org.\r
  */\r
 package ch.bfh.ti.srs.dataschema;\r
+\r
+public enum Role {\r
+       User,\r
+       ResourceManager,\r
+       Admin\r
+}\r
index 5bcd68b..2409875 100644 (file)
@@ -7,6 +7,9 @@
  */
 package ch.bfh.ti.srs.dataschema;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import ch.bfh.ti.srs.extern.Password;
 
 public class User implements Cloneable {
@@ -16,6 +19,7 @@ public class User implements Cloneable {
        private String mail;
        private String name;
        private String lastname;
+       private Set<Role> roles = new HashSet<Role>();
 
        /**
         * Constructor for already existing <code>User</code> in the Datacontext.
@@ -62,6 +66,7 @@ public class User implements Cloneable {
 
                this.userName = userName;
                this.hashedPassword = Password.getSaltedHash(password);
+               this.roles.add(Role.User);
        }
 
        public String getUserName() {
@@ -157,4 +162,16 @@ public class User implements Cloneable {
        public User clone() throws CloneNotSupportedException {
                return (User) super.clone();
        }
+       
+       public void addRole(Role role){
+               roles.add(role);
+       }
+       
+       public void removeRole(Role role){
+               if(roles.contains(role)) roles.remove(role);
+       }
+       
+       public Set<Role> getRoles(){
+               return roles;
+       }
 }
index 51696d3..13715cf 100644 (file)
@@ -11,9 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 \r
+import java.util.Set;\r
+\r
 import org.junit.Test;\r
 \r
-import ch.bfh.ti.srs.dataschema.User;\r
 import ch.bfh.ti.srs.extern.Password;\r
 \r
 /**\r
@@ -160,4 +161,38 @@ public class UserTest {
                testUser.setLastname(null);\r
                assertEquals(null, testUser.getLastname());\r
        }\r
+       \r
+       @Test\r
+       public void RoleTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               Set<Role> roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertFalse(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.addRole(Role.ResourceManager);\r
+               roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.removeRole(Role.User);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.removeRole(Role.Admin);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+       }\r
+       \r
+       @Test\r
+       public void cloneTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               User clonedUser = testUser.clone();\r
+               assertEquals(testUser.getUserName(), clonedUser.getUserName());\r
+       }\r
 }\r