aboutsummaryrefslogtreecommitdiffstats
path: root/upstream/odl-aaa-moon/aaa/aaa-shiro/src/main/java/org/opendaylight/aaa/shiro/moon/MoonPrincipal.java
blob: 9dd2fd4f7aefe25fa6de0fe0a7c0265e16f46614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.aaa.shiro.moon;

import com.google.common.collect.ImmutableSet;

import java.io.Serializable;
import java.util.Set;

import org.opendaylight.aaa.api.Claim;

/**
 * MoonPrincipal contains all user's information returned by moon on successful authentication
 * @author Alioune BA alioune.ba@orange.com
 *
 */
public  class MoonPrincipal {

    private final String username;
    private final String domain;
    private final String userId;
    private final Set<String> roles;
    private final String token;


    public MoonPrincipal(String username, String domain, String userId, Set<String> roles, String token) {
        this.username = username;
        this.domain = domain;
        this.userId = userId;
        this.roles = roles;
        this.token = token;
    }

    public MoonPrincipal createODLPrincipal(String username, String domain,
            String userId, Set<String> roles, String token) {

        return new MoonPrincipal(username, domain, userId, roles,token);
    }

    public Claim principalToClaim (){
        return new MoonClaim("", this.getUserId(), this.getUsername(), this.getDomain(), this.getRoles());
    }

    public String getUsername() {
        return this.username;
    }

    public String getDomain() {
        return this.domain;
    }

    public String getUserId() {
        return this.userId;
    }

    public Set<String> getRoles() {
        return this.roles;
    }

    public String getToken(){
        return this.token;
    }

    public class MoonClaim implements Claim, Serializable {
        private static final long serialVersionUID = -8115027645190209125L;
        private int hashCode = 0;
        private String clientId;
        private String userId;
        private String user;
        private String domain;
        private ImmutableSet<String> roles;

        public MoonClaim(String clientId, String userId, String user, String domain, Set<String> roles) {
            this.clientId = clientId;
            this.userId = userId;
            this.user = user;
            this.domain = domain;
            this.roles = ImmutableSet.<String> builder().addAll(roles).build();

            if (userId.isEmpty() || user.isEmpty() || roles.isEmpty() || roles.contains("")) {
                throw new IllegalStateException("The Claim is missing one or more of the required fields.");
            }
        }

        @Override
        public String clientId() {
            return clientId;
        }

        @Override
        public String userId() {
            return userId;
        }

        @Override
        public String user() {
            return user;
        }

        @Override
        public String domain() {
            return domain;
        }

        @Override
        public Set<String> roles() {
            return roles;
        }
        public String getClientId() {
            return clientId;
        }

        public void setClientId(String clientId) {
            this.clientId = clientId;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUser() {
            return user;
        }

        public void setUser(String user) {
            this.user = user;
        }

        public String getDomain() {
            return domain;
        }

        public void setDomain(String domain) {
            this.domain = domain;
        }

        public ImmutableSet<String> getRoles() {
            return roles;
        }

        public void setRoles(ImmutableSet<String> roles) {
            this.roles = roles;
        }

        @Override
        public String toString() {
            return "clientId:" + clientId + "," + "userId:" + userId + "," + "userName:" + user
                    + "," + "domain:" + domain + "," + "roles:" + roles ;
        }
    }
}