Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2582 Start angular OKB manager, data loaded

File size: 4.2 KB
RevLine 
[13860]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;
[13847]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;
[13854]34        public bool OKBOnly { get; set; }
[13847]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
[13854]40        public HiveWebUser(Guid token, string username, bool okb)
[13847]41        {
42            webIdToken = token;
43            this.username = username;
44            this.weblog = WebLoginService.Instance;
[13854]45            OKBOnly = okb;
[13847]46            updateUserInfo();
47        }
48        public HiveWebUser updateUserInfo()
49        {
[13862]50
[13847]51            try
52            {
[13854]53                if (OKBOnly)
54                    throw new SecurityAccessDeniedException();
55                var access = weblog.getAccessAdminClient(webIdToken);
[13847]56                access.RefreshUsers();
[13854]57                access.RefreshUserGroups();
58                access.RefreshRoles();
[13862]59
[13847]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            }
[13862]64            catch (Exception e)
[13847]65            {
[13862]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;
[13847]75            }
[13862]76
[13847]77            return this;
78
79        }
80        public bool HasUserAdminAccess()
81        {
[13862]82            if (accessRoles.Find(x => x.Name == "AccessService Administrator") != null || weblog.getAccessAdminClient(webIdToken) != null)
[13847]83            {
84                return true;
85            }
86            return false;
87        }
88        public bool hasResourceAdminAccess()
89        {
[13862]90            if ((accessRoles.Find(x => x.Name == "Hive Administrator") != null
91                && accessRoles.Find(x => x.Name == "AccessService Administrator") != null))
[13847]92            {
93                return true;
94            }
95            return false;
96        }
[13854]97        public bool hasOKBAccess()
98        {
[13862]99            if (OKBOnly || accessRoles.Find(x => x.Name == "OKB User") != null || accessRoles.Find(x => x.Name == "OKB Administrator") != null
100                || weblog.getQueryClient(webIdToken) != null)
[13854]101            {
102                return true;
103            }
104            return false;
105        }
[13862]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        }
[13847]119    }
120}
Note: See TracBrowser for help on using the repository browser.