Index: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs
===================================================================
--- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs	(revision 13742)
+++ branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs	(revision 13754)
@@ -45,13 +45,10 @@
         /// initializes the connection for the right user. Not constructor because httpcontext is needed.
         /// </summary>
-        private void init()
+        private bool init()
         {
             var u = HttpContext.Session.GetString("UserId");
             if (u == null || u == "" || Guid.Parse(u) == Guid.Empty)
             {
-                userId = Guid.Empty;
-                serviceLocator = new HiveServiceLocatorWeb();
-                serviceClient = serviceLocator.getHiveServiceClient();
-                clientWeb = new HiveClientWeb(serviceLocator, userId);
+                return false;
             }
             else
@@ -61,4 +58,5 @@
                 serviceClient = serviceLocator.getHiveServiceClient();
                 clientWeb = weblog.getClientWeb(userId);
+                return serviceLocator.CheckLogin();
             }
         }
@@ -71,21 +69,17 @@
         public IActionResult Index()
         {
-            try
-            {
-                init();
+            if (init())
+            {
                 clientWeb.Refresh();
                 vm.userJobs = clientWeb.Jobs.ToList();
-            }
-            catch (Exception e)
-            {
-                if (e is MessageSecurityException || e is InvalidOperationException)
-                {
-                    return RedirectToAction("Index", "Home");
-                }
-                throw;
-            }
-            ViewBag.SessionId = HttpContext.Session.GetString("UserId");
-            ViewBag.Title = "Jobs";
-            return View(vm);
+
+                ViewBag.SessionId = HttpContext.Session.GetString("UserId");
+                ViewBag.Title = "Jobs";
+                return View(vm);
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
         }
         /// <summary>
@@ -96,6 +90,5 @@
         public IActionResult Selected(Guid id)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 clientWeb.Refresh();
@@ -129,6 +122,5 @@
         public IActionResult Delete(Guid id)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
 
@@ -155,6 +147,5 @@
         public IActionResult Uploads()
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 UploadedJobViewModel upper = new UploadedJobViewModel();
@@ -176,10 +167,9 @@
         public IActionResult UploadDir(int index)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 UploadedJobViewModel upper = new UploadedJobViewModel();
                 fillUploadsPaths(upper, index);
-                if(index != -1)
+                if (index != -1)
                     ViewBag.Title = upper.DisplayDatePaths[index] + " - Uploads";
                 else
@@ -209,5 +199,6 @@
                     tempdex = -1;
                 }
-                else {
+                else
+                {
                     vm.FullDatePaths.Add(dir);
                     var temp = dir.Split('\\');
@@ -235,6 +226,5 @@
         public IActionResult DeleteFile(int index, int filedex)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 UploadedJobViewModel upper = new UploadedJobViewModel();
@@ -263,6 +253,5 @@
         public IActionResult OpenFile(int index, int filedex)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 UploadedJobViewModel upper = new UploadedJobViewModel();
@@ -305,6 +294,5 @@
         public IActionResult AddToHive()
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 var job = weblog.getFileOpener(userId).AddCurrentModelToHive();
@@ -364,23 +352,28 @@
         public async Task<IActionResult> Uploader(ICollection<IFormFile> files, string directory)
         {
-            init();
-            UploadedJobViewModel upper = new UploadedJobViewModel();
-            var uploads = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName,
-                directory);
-            Directory.CreateDirectory(uploads);
-            foreach (var file in files)
-            {
-                if (file.Length > 0)
-                {
-                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
-                    await file.SaveAsAsync(Path.Combine(uploads, fileName));
-                    // var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName));
-                    //OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer);
-                    //upper.Tasks.Add(task);
-                }
-            }
-            ViewBag.Title = "Upload complete - Uploads";
-            return RedirectToAction("Uploads", "Job");
-
+            if (init())
+            {
+                UploadedJobViewModel upper = new UploadedJobViewModel();
+                var uploads = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName,
+                    directory);
+                Directory.CreateDirectory(uploads);
+                foreach (var file in files)
+                {
+                    if (file.Length > 0)
+                    {
+                        var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
+                        await file.SaveAsAsync(Path.Combine(uploads, fileName));
+                        // var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName));
+                        //OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer);
+                        //upper.Tasks.Add(task);
+                    }
+                }
+                ViewBag.Title = "Upload complete - Uploads";
+                return RedirectToAction("Uploads", "Job");
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
         }
         #endregion
Index: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs
===================================================================
--- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs	(revision 13742)
+++ branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs	(revision 13754)
@@ -1,3 +1,4 @@
-﻿using HeuristicLab.Clients.Hive.WebJobManager.Services;
+﻿using HeuristicLab.Clients.Access.Administration;
+using HeuristicLab.Clients.Hive.WebJobManager.Services;
 using Microsoft.AspNet.Hosting;
 using Microsoft.AspNet.Http;
@@ -15,6 +16,5 @@
         private WebLoginService weblog;
         private HiveServiceLocatorWeb serviceLocator;
-        private HiveServiceClient serviceClient;
-        private HiveClientWeb clientWeb;
+        private AccessAdministrationClient accessClient;
         private Guid userId;
 
@@ -26,13 +26,10 @@
             _environment = env;
         }
-        private void init()
+        private bool init()
         {
             var u = HttpContext.Session.GetString("UserId");
             if (u == null || u == "" || Guid.Parse(u) == Guid.Empty)
             {
-                userId = Guid.Empty;
-                serviceLocator = new HiveServiceLocatorWeb();
-                serviceClient = serviceLocator.getHiveServiceClient();
-                clientWeb = new HiveClientWeb(serviceLocator, userId);
+                return false;
             }
             else
@@ -40,14 +37,15 @@
                 userId = Guid.Parse(u);
                 serviceLocator = weblog.getServiceLocator(userId);
-                serviceClient = serviceLocator.getHiveServiceClient();
-                clientWeb = weblog.getClientWeb(userId);
+                accessClient = weblog.getAccessAdminClient(userId);
+                return serviceLocator.CheckLogin();
+
             }
         }
         public IActionResult Index()
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            
+            if (init())
             {
-
+                ViewBag.SessionId = HttpContext.Session.GetString("UserId");
                 ViewBag.Title = "Resources";
                 return View("Index");
Index: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs
===================================================================
--- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs	(revision 13742)
+++ branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs	(revision 13754)
@@ -27,11 +27,10 @@
             _environment = env;
         }
-        private void init()
+        private bool init()
         {
             var u = HttpContext.Session.GetString("UserId");
             if (u == null || u == "" || Guid.Parse(u) == Guid.Empty)
             {
-                userId = Guid.Empty;
-                serviceLocator = new HiveServiceLocatorWeb();
+                return false;
             }
             else
@@ -40,4 +39,6 @@
                 serviceLocator = weblog.getServiceLocator(userId);
                 accessClient = weblog.getAccessAdminClient(userId);
+                return serviceLocator.CheckLogin();
+                 
             }
         }
@@ -46,10 +47,8 @@
         public IActionResult Index()
         {
-            init();
-            if (serviceLocator.CheckLogin())
-            {
-
+            if (init())
+            {
                 ViewBag.Title = "Users";
-                UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
+                UserViewModel vm = new UserViewModel(accessClient).refreshAll() ;
                 ViewBag.SessionId = HttpContext.Session.GetString("UserId");
                 return View("Index", vm);
@@ -63,10 +62,10 @@
         public IActionResult SelectUser(string id)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            ;
+            if (init())
             {
                 Guid curr = Guid.Parse(id);
-                
-                UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
+
+                UserViewModel vm = new UserViewModel(accessClient).refreshAll();
                 if (curr == Guid.Empty)
                 {
@@ -77,4 +76,5 @@
                     vm.SelectedUser = vm.getUserById(curr);
                     vm.SelectedUserSubscriptions = accessClient.getSubscribedGroups(curr);
+                    vm.SelectedUserRoles = accessClient.getRoles(vm.SelectedUser);
                     ViewBag.title = vm.SelectedUser.UserName;
                 }
@@ -89,56 +89,120 @@
         }
         [HttpPost]
-        public IActionResult saveUser(string inpusername, string inpfullname, string inpemail, string u)
-        {
-            init();
-            var uid = Guid.Parse(u);
-            Access.User user;
-            if (uid == Guid.Empty)
-                user = new Access.User();
-            else
+        public IActionResult saveUser(string inpusername, string inpfullname, string inpemail, string u, string[] rolestoadd, string[] groupstoadd)
+        {
+
+            if (init())
+            {
+                var uid = Guid.Parse(u);
+                Access.User user;
+                if (uid == Guid.Empty)
+                    user = new Access.User();
+                else
+                    user = accessClient.Users.Find(x => x.Id == uid);
+
+
+                user.FullName = inpfullname;
+                user.Email = inpemail;
+
+
+                if (uid == Guid.Empty)
+                {
+                    user.UserName = inpusername;
+                    uid = accessClient.addUser(user);
+                    ViewBag.Title = user.UserName + " added - User";
+                }
+                else
+                {
+                    accessClient.updateUser(user);
+                    ViewBag.Title = user.UserName + " updated - User";
+                }
+                accessClient.RefreshUsers();
                 user = accessClient.Users.Find(x => x.Id == uid);
-
-            
-            user.FullName = inpfullname;
-            user.Email = inpemail;
-
-
-            if (uid == Guid.Empty)
-            {
-                user.UserName = inpusername;
-                uid = accessClient.addUser(user);
-                ViewBag.Title = user.UserName + " added - User";
-            }
-            else
-            {
-                accessClient.updateUser(user);
-                ViewBag.Title = user.UserName + " updated - User";
-            }
-
-            return RedirectToAction( "SelectUser", new {  id =  uid.ToString()});
+                foreach (var s in rolestoadd)
+                {
+                    var role = accessClient.Roles.Find(x => x.Name == s);
+
+                    accessClient.addRoleToUser(user, role);
+                }
+                accessClient.RefreshUserGroups();
+                foreach(var g in groupstoadd)
+                {
+                    var gid = Guid.Parse(g);
+                    var group = accessClient.Groups.Find(x => x.Id == gid);
+                    accessClient.addMember(user, group);
+                }
+                return RedirectToAction("SelectUser", new { id = uid.ToString() });
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
 
         }
         public IActionResult deleteUser(string id)
         {
-            init();
-            var uid = Guid.Parse(id);
-            UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
-            
-            if (uid == Guid.Empty)
-            {
-                vm.message = "Something went wrong, user is not deleted";
-                return View("Index", vm);
-            }
-            else
-            {
+            if (init())
+            {
+                var uid = Guid.Parse(id);
+                UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
+
+                if (uid == Guid.Empty)
+                {
+                    vm.message = "Something went wrong, user is not deleted";
+                    return View("Index", vm);
+                }
+                else
+                {
+                    var user = vm.getUserById(uid);
+                    vm.message = user.UserName + " (" + user.FullName + ") has been deleted";
+                    accessClient.DeleteUser(user);
+                    vm.refreshAll();
+                    ViewBag.Title = "Users";
+                    return View("Index", vm);
+                }
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+
+        }
+
+        public IActionResult deleteUserRole(string id, string role)
+        {
+            if (init())
+            {
+                var uid = Guid.Parse(id);
+                UserViewModel vm = new UserViewModel(accessClient).refreshAll();
+
                 var user = vm.getUserById(uid);
-                vm.message = user.UserName + " ("+user.FullName+") has been deleted";
-                accessClient.DeleteUser(user);
-                vm.refreshUsers();
-                return View("Index", vm);
-            }
-
-        }
-
+                var r = vm.getRoleByName(role);
+                accessClient.deleteUserRole(user, r);
+                return RedirectToAction("SelectUser", new { id = id });
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        public IActionResult deleteUserGroup(string id, string group)
+        {
+            if (init())
+            {
+                var gid = Guid.Parse(group);
+                var mid = Guid.Parse(id);
+                UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
+
+                var user = vm.getUserById(mid);
+                var gr = vm.getGroupById(gid);
+                accessClient.deleteMember(user, gr);
+                return RedirectToAction("SelectUser", new { id = id});
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+
+        }
         #endregion
 
@@ -146,6 +210,5 @@
         public IActionResult Groups()
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
 
@@ -161,6 +224,5 @@
         public IActionResult SelectGroup(string id)
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
                 Guid curr = Guid.Parse(id);
@@ -190,63 +252,74 @@
         public IActionResult saveGroup(string inpgroupname, string u, string[] userstoadd, string[] groupstoadd)
         {
-            init();
-            var uid = Guid.Parse(u);
-            var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
-
-            Access.UserGroup group;
-            
-            if (uid == Guid.Empty)
-                group = new Access.UserGroup();
-            else
-                group = accessClient.Groups.Find(x => x.Id == uid);
-
-            group.Name = inpgroupname;
-
-            if (uid == Guid.Empty)
-            {
-                uid = accessClient.addGroup(group);
-                ViewBag.Title = group.Name + " added - Group";
-            }
-            else
-            {
-                accessClient.updateGroup(group);
-                ViewBag.Title = group.Name + " updated - Group";
-            }
-            vm.refreshGroups();
-            group = vm.getGroupById(uid);
-            foreach(var s in userstoadd)
-            {
-                var tempid = Guid.Parse(s);
-                var member = vm.getUserById(tempid);
-                accessClient.addMember(member, group);
-            }
-            foreach (var g in groupstoadd)
-            {
-                var tempid = Guid.Parse(g);
-                var member = vm.getGroupById(tempid);
-                accessClient.addMember(member, group);
-            }
-
-            return RedirectToAction("SelectGroup", new { id = uid.ToString() });
-
+            if (init())
+            {
+                var uid = Guid.Parse(u);
+                var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
+
+                Access.UserGroup group;
+
+                if (uid == Guid.Empty)
+                    group = new Access.UserGroup();
+                else
+                    group = accessClient.Groups.Find(x => x.Id == uid);
+
+                group.Name = inpgroupname;
+
+                if (uid == Guid.Empty)
+                {
+                    uid = accessClient.addGroup(group);
+                    ViewBag.Title = group.Name + " added - Group";
+                }
+                else
+                {
+                    accessClient.updateGroup(group);
+                    ViewBag.Title = group.Name + " updated - Group";
+                }
+                vm.refreshGroups();
+                group = vm.getGroupById(uid);
+                foreach (var s in userstoadd)
+                {
+                    var tempid = Guid.Parse(s);
+                    var member = vm.getUserById(tempid);
+                    accessClient.addMember(member, group);
+                }
+                foreach (var g in groupstoadd)
+                {
+                    var tempid = Guid.Parse(g);
+                    var member = vm.getGroupById(tempid);
+                    accessClient.addMember(member, group);
+                }
+
+                return RedirectToAction("SelectGroup", new { id = uid.ToString() });
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
         }
         public IActionResult deleteGroup(string id)
         {
-            init();
-            var uid = Guid.Parse(id);
-            UserViewModel vm = new UserViewModel(accessClient).refreshGroups();
-
-            if (uid == Guid.Empty)
-            {
-                vm.message = "Something went wrong, group is not deleted";
-                return View("Groups", vm);
-            }
-            else
-            {
-                var group = vm.getGroupById(uid);
-                vm.message = group.Name + " has been deleted";
-                accessClient.deleteUserGroup(group);
-                vm.refreshGroups();
-                return View("Groups", vm);
+            if (init())
+            {
+                var uid = Guid.Parse(id);
+                UserViewModel vm = new UserViewModel(accessClient).refreshGroups();
+
+                if (uid == Guid.Empty)
+                {
+                    vm.message = "Something went wrong, group is not deleted";
+                    return View("Groups", vm);
+                }
+                else
+                {
+                    var group = vm.getGroupById(uid);
+                    vm.message = group.Name + " has been deleted";
+                    accessClient.deleteUserGroup(group);
+                    vm.refreshGroups();
+                    return View("Groups", vm);
+                }
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
             }
 
@@ -254,26 +327,32 @@
         public IActionResult deleteMember(string g, string m)
         {
-            init();
-            var gid = Guid.Parse(g);
-            var mid = Guid.Parse(m);
-            UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers() ;
-
-            if (gid == Guid.Empty || mid == Guid.Empty)
-            {
-                vm.message = "Something went wrong, member is not deleted";
-                return View("Groups", vm);
-            }
-            else
-            {
-                var group = vm.getGroupById(gid);
-                Access.UserGroupBase member = vm.getUserById(mid);
-                if(member == null)
-                {
-                    member = vm.getGroupById(mid);
-                }
-                vm.message = " Member deleted";
-                accessClient.deleteMember(member,group);
-                vm.refreshGroups();
-                return RedirectToAction("SelectGroup", new { id = g });
+            if (init())
+            {
+                var gid = Guid.Parse(g);
+                var mid = Guid.Parse(m);
+                UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
+
+                if (gid == Guid.Empty || mid == Guid.Empty)
+                {
+                    vm.message = "Something went wrong, member is not deleted";
+                    return View("Groups", vm);
+                }
+                else
+                {
+                    var group = vm.getGroupById(gid);
+                    Access.UserGroupBase member = vm.getUserById(mid);
+                    if (member == null)
+                    {
+                        member = vm.getGroupById(mid);
+                    }
+                    vm.message = " Member deleted";
+                    accessClient.deleteMember(member, group);
+                    vm.refreshGroups();
+                    return RedirectToAction("SelectGroup", new { id = g });
+                }
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
             }
 
@@ -284,12 +363,87 @@
         public IActionResult Roles()
         {
-            init();
-            if (serviceLocator.CheckLogin())
+            if (init())
             {
 
                 ViewBag.Title = "Roles";
-                // accessClient.RefreshUsers();
-
-                return View("Roles");
+                UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
+
+                return View("Roles", vm);
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        public IActionResult SelectRole(string name)
+        {
+            if (init())
+            {
+
+                UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
+                if (name == "" || name == null)
+                {
+                    ViewBag.Title = "Add Role";
+                }
+                else
+                {
+                    vm.SelectedRole = vm.getRoleByName(name);
+                    vm.SelectedRoleEnrolled = accessClient.getEnrolled(vm.SelectedRole);
+
+                    ViewBag.title = vm.SelectedRole.Name;
+                }
+                ViewBag.Title += " - Roles";
+                return View("Roles", vm);
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        [HttpPost]
+        public IActionResult saveRole(string inprolename)
+        {
+            if (init())
+            {
+                Access.Role role = accessClient.Roles.Find(x => x.Name == inprolename);
+                if (role == null)
+                {
+                    role = new Access.Role();
+                    role.Name = inprolename;
+                    accessClient.addRole(role);
+                }
+
+                accessClient.RefreshRoles();
+                return RedirectToAction("SelectRole", new { name = inprolename });
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        public IActionResult deleteRole(string name)
+        {
+            if (init())
+            {
+                accessClient.deleteRole(name);
+                return RedirectToAction("Roles");
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        public IActionResult deleteRoleUser(string id, string role)
+        {
+            if (init())
+            {
+                var uid = Guid.Parse(id);
+                UserViewModel vm = new UserViewModel(accessClient).refreshAll();
+
+                var user = vm.getUserById(uid);
+                var r = vm.getRoleByName(role);
+                vm.message = role + " role has been deleted from " + user.FullName;
+                accessClient.deleteUserRole(user, r);
+                return RedirectToAction("SelectRole", new { name = role });
             }
             else
