Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17187 was 13862, checked in by jlodewyc, 9 years ago

#2582 Start angular OKB manager, data loaded

File size: 4.2 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 (Exception e)
65            {
66                if (e is SecurityAccessDeniedException || e is NullReferenceException)
67                {
68                    currentUser = new User();
69                    currentUser.FullName = username;
70                    subscribedGroups = new List<UserGroup>();
71                    accessRoles = new List<Role>();
72                }
73                else
74                    throw e;
75            }
76
77            return this;
78
79        }
80        public bool HasUserAdminAccess()
81        {
82            if (accessRoles.Find(x => x.Name == "AccessService Administrator") != null || weblog.getAccessAdminClient(webIdToken) != null)
83            {
84                return true;
85            }
86            return false;
87        }
88        public bool hasResourceAdminAccess()
89        {
90            if ((accessRoles.Find(x => x.Name == "Hive Administrator") != null
91                && accessRoles.Find(x => x.Name == "AccessService Administrator") != null))
92            {
93                return true;
94            }
95            return false;
96        }
97        public bool hasOKBAccess()
98        {
99            if (OKBOnly || accessRoles.Find(x => x.Name == "OKB User") != null || accessRoles.Find(x => x.Name == "OKB Administrator") != null
100                || weblog.getQueryClient(webIdToken) != null)
101            {
102                return true;
103            }
104            return false;
105        }
106        public bool hasOKBAdminAccess()
107        {
108            if (OKBOnly)
109            {
110                if (weblog.getOkbAdminClient(webIdToken) != null)
111                    return true;
112            }
113            else if (accessRoles.Find(x => x.Name == "OKB Administrator") != null || weblog.getOkbAdminClient(webIdToken) != null)
114            {
115                return true;
116            }
117            return false;
118        }
119    }
120}
Note: See TracBrowser for help on using the repository browser.