Drop explicit jetty-servlets dependency
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / shiro / principal / ODLPrincipalImpl.java
1 /*
2  * Copyright (c) 2017 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.shiro.principal;
9
10 import java.util.Set;
11
12 import org.opendaylight.aaa.api.Authentication;
13 import org.opendaylight.aaa.api.shiro.principal.ODLPrincipal;
14
15 /**
16  * An ODL specific principal which stores some critical information about the user
17  * making the auth request.
18  */
19 public class ODLPrincipalImpl implements ODLPrincipal {
20
21     private final String username;
22     private final String domain;
23     private final String userId;
24     private final Set<String> roles;
25
26     private ODLPrincipalImpl(final String username, final String domain, final String userId, final Set<String> roles) {
27         this.username = username;
28         this.domain = domain;
29         this.userId = userId;
30         this.roles = roles;
31     }
32
33     /**
34      * A static factory method to create <code>ODLPrincipal</code> instances.
35      *
36      * @param auth Contains identifying information for the particular request.
37      * @return A Principal for the given session;  essentially a DTO.
38      */
39     public static ODLPrincipal createODLPrincipal(Authentication auth) {
40         return createODLPrincipal(auth.user(), auth.domain(), auth.userId(), auth.roles());
41     }
42
43     /**
44      * A static factory method to create <code>ODLPrincipal</code> instances.
45      *
46      * @param username The authenticated user
47      * @param domain The domain <code>username</code> belongs to.
48      * @param userId The unique key for <code>username</code>
49      * @param roles The roles associated with <code>username</code>@<code>domain</code>
50      * @return A Principal for the given session;  essentially a DTO.
51      */
52     public static ODLPrincipal createODLPrincipal(String username, String domain,
53                                            String userId, Set<String> roles) {
54
55         return new ODLPrincipalImpl(username, domain, userId, roles);
56     }
57
58     /**
59      * A static factory method to create <code>ODLPrincipal</code> instances w/o roles.
60      *
61      * @param username The authenticated user
62      * @param domain The domain <code>username</code> belongs to.
63      * @param userId The unique key for <code>username</code>
64      * @return A Principal for the given session;  essentially a DTO.
65      */
66     public static ODLPrincipal createODLPrincipal(String username, String domain,
67                                                   String userId) {
68         return ODLPrincipalImpl.createODLPrincipal(username, domain, userId, null);
69     }
70
71     @Override
72     public String getUsername() {
73         return this.username;
74     }
75
76     @Override
77     public String getDomain() {
78         return this.domain;
79     }
80
81     @Override
82     public String getUserId() {
83         return this.userId;
84     }
85
86     @Override
87     public Set<String> getRoles() {
88         return this.roles;
89     }
90 }