Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Models/HiveWebUser.cs @ 13860

Last change on this file since 13860 was 13860, checked in by jlodewyc, 8 years ago

#2582 RC2 migration fixed. OKB query implemented. Preparing for OKB manager

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Clients.Access;
23using HeuristicLab.Clients.Hive.WebJobManager.Services;
24using System;
25using System.Collections.Generic;
26using System.ServiceModel.Security;
27
28namespace HeuristicLab.Clients.Hive.WebJobManager.Models
29{
30    public class HiveWebUser
31    {
32        private WebLoginService weblog;
33        private string username;
34        public bool OKBOnly { get; set; }
35        public Guid webIdToken { get; set; }
36        public User currentUser { get; set; }
37        public List<UserGroup> subscribedGroups { get; set; }
38        public List<Role> accessRoles { get; set; }
39
40        public HiveWebUser(Guid token, string username, bool okb)
41        {
42            webIdToken = token;
43            this.username = username;
44            this.weblog = WebLoginService.Instance;
45            OKBOnly = okb;
46            updateUserInfo();
47        }
48        public HiveWebUser updateUserInfo()
49        {
50           
51            try
52            {
53                if (OKBOnly)
54                    throw new SecurityAccessDeniedException();
55                var access = weblog.getAccessAdminClient(webIdToken);
56                access.RefreshUsers();
57                access.RefreshUserGroups();
58                access.RefreshRoles();
59           
60                currentUser = access.Users.Find(x => x.UserName == username);
61                subscribedGroups = access.CallAccessService(x => x.GetUserGroupsOfUser(currentUser.Id));
62                accessRoles = access.CallAccessService(x => x.GetRolesOfCurrentUser());
63            }
64            catch(SecurityAccessDeniedException e)
65            {
66                currentUser = new User();
67                currentUser.FullName = username;
68                subscribedGroups = new List<UserGroup>();
69                accessRoles = new List<Role>();
70            }
71           
72            return this;
73
74        }
75        public bool HasUserAdminAccess()
76        {
77            if(accessRoles.Find(x => x.Name == "AccessService Administrator") != null)
78            {
79                return true;
80            }
81            return false;
82        }
83        public bool hasResourceAdminAccess()
84        {
85            if(accessRoles.Find(x =>x.Name == "Hive Administrator" ) != null
86                && accessRoles.Find(x => x.Name == "AccessService Administrator") != null)
87            {
88                return true;
89            }
90            return false;
91        }
92        public bool hasOKBAccess()
93        {
94            if (OKBOnly || accessRoles.Find(x => x.Name == "OKB User") != null || accessRoles.Find(x => x.Name == "OKB Administrator") != null)
95            {
96                return true;
97            }
98            return false;
99        }
100    }
101}
Note: See TracBrowser for help on using the repository browser.