Merge "Fix the package name"
[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  * @author Ryan Goulding (ryandgoulding@gmail.com)
20  */
21 public class ODLPrincipalImpl implements ODLPrincipal {
22
23     private final String username;
24     private final String domain;
25     private final String userId;
26     private final Set<String> roles;
27
28     private ODLPrincipalImpl(final String username, final String domain, final String userId, final Set<String> roles) {
29         this.username = username;
30         this.domain = domain;
31         this.userId = userId;
32         this.roles = roles;
33     }
34
35     /**
36      * A static factory method to create <code>ODLPrincipal</code> instances.
37      *
38      * @param auth Contains identifying information for the particular request.
39      * @return A Principal for the given session;  essentially a DTO.
40      */
41     public static ODLPrincipal createODLPrincipal(Authentication auth) {
42         return createODLPrincipal(auth.user(), auth.domain(), auth.userId(), auth.roles());
43     }
44
45     /**
46      * A static factory method to create <code>ODLPrincipal</code> instances.
47      *
48      * @param username The authenticated user
49      * @param domain The domain <code>username</code> belongs to.
50      * @param userId The unique key for <code>username</code>
51      * @param roles The roles associated with <code>username</code>@<code>domain</code>
52      * @return A Principal for the given session;  essentially a DTO.
53      */
54     public static ODLPrincipal createODLPrincipal(String username, String domain,
55                                            String userId, Set<String> roles) {
56
57         return new ODLPrincipalImpl(username, domain, userId, roles);
58     }
59
60     @Override
61     public String getUsername() {
62         return this.username;
63     }
64
65     @Override
66     public String getDomain() {
67         return this.domain;
68     }
69
70     @Override
71     public String getUserId() {
72         return this.userId;
73     }
74
75     @Override
76     public Set<String> getRoles() {
77         return this.roles;
78     }
79 }