Add explicit storage for authentication methods
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / shiro / keystone / domain / KeystoneAuth.java
1 /*
2  * Copyright (c) 2017 Ericsson 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.keystone.domain;
9
10 /**
11  * This class is a representation of a Keystone API v3 Auth object.
12  */
13 public class KeystoneAuth {
14     private final Auth auth;
15
16     public KeystoneAuth(String username, String password, String domain) {
17         this.auth = new Auth(username, password, domain);
18     }
19
20     public Auth getAuth() {
21         return auth;
22     }
23
24     public static final class Auth {
25         private final Identity identity;
26         private final Scope scope;
27
28         private Auth(String username, String password, String domain) {
29             this.identity = new Identity(username, password, domain);
30             this.scope = new Scope(domain);
31         }
32
33         public Identity getIdentity() {
34             return identity;
35         }
36
37         public Scope getScope() {
38             return scope;
39         }
40
41         public static final class Identity {
42             private static final String METHOD_PASSWORD = "password";
43
44             private final String[] methods;
45             private final Password password;
46
47             private Identity(String username, String password, String domain) {
48                 this.password = new Password(username, password, domain);
49                 this.methods = new String[]{ METHOD_PASSWORD };
50             }
51
52             public String[] getMethods() {
53                 return methods == null ? null : methods.clone();
54             }
55
56             public Password getPassword() {
57                 return password;
58             }
59
60             public static final class Password {
61                 private final User user;
62
63                 private Password(String username, String password, String domain) {
64                     this.user = new User(username, password, domain);
65                 }
66
67                 public User getUser() {
68                     return user;
69                 }
70
71                 public static final class User {
72                     private final String name;
73                     private final String password;
74                     private final Domain domain;
75
76                     private User(String name, String password, String domain) {
77                         this.name = name;
78                         this.password = password;
79                         this.domain = new Domain(domain);
80                     }
81
82                     public String getName() {
83                         return name;
84                     }
85
86                     public String getPassword() {
87                         return password;
88                     }
89
90                     public Domain getDomain() {
91                         return domain;
92                     }
93
94                     public static final class Domain {
95                         private final String name;
96
97                         private Domain(String name) {
98                             this.name = name;
99                         }
100
101                         public String getName() {
102                             return name;
103                         }
104                     }
105                 }
106
107             }
108         }
109
110         public static final class Scope {
111             private final Domain domain;
112
113             public Scope(String domainId) {
114                 domain = new Domain(domainId);
115             }
116
117             public Domain getDomain() {
118                 return domain;
119             }
120
121             public static final class Domain {
122                 private final String name;
123
124                 public Domain(String theDomain) {
125                     name = theDomain;
126                 }
127
128                 public String getName() {
129                     return name;
130                 }
131             }
132         }
133     }
134 }