Drop explicit jetty-servlets dependency
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / impl / shiro / tokenauthrealm / ServiceLocator.java
1 /*
2  * Copyright (c) 2014 - 2017 Hewlett-Packard Development Company, L.P. 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
9 package org.opendaylight.aaa.impl.shiro.tokenauthrealm;
10
11 import java.util.List;
12 import java.util.Vector;
13 import org.opendaylight.aaa.api.AuthenticationService;
14 import org.opendaylight.aaa.api.CredentialAuth;
15 import org.opendaylight.aaa.api.IdMService;
16 import org.opendaylight.aaa.api.PasswordCredentials;
17 import org.opendaylight.aaa.api.TokenAuth;
18 import org.opendaylight.aaa.api.TokenStore;
19
20 /**
21  * A service locator to bridge between the web world and OSGi world.
22  *
23  * @author liemmn
24  */
25 public class ServiceLocator {
26
27     private static final ServiceLocator INSTANCE = new ServiceLocator();
28
29     protected volatile List<TokenAuth> tokenAuthCollection = new Vector<>();
30
31     protected volatile CredentialAuth<PasswordCredentials> credentialAuth;
32
33     protected volatile TokenStore tokenStore;
34
35     protected volatile AuthenticationService authenticationService;
36
37     protected volatile IdMService idmService;
38
39     private ServiceLocator() {
40     }
41
42     public static ServiceLocator getInstance() {
43         return INSTANCE;
44     }
45
46     /**
47      * Called through reflection by the oauth2 activator.
48      *
49      * @param tokenAuth tokenAuth service.
50      */
51     protected void tokenAuthAdded(TokenAuth tokenAuth) {
52         this.tokenAuthCollection.add(tokenAuth);
53     }
54
55     /**
56      * Called through reflection by the oauth2 activator.
57      *
58      * @param tokenAuth token auth service.
59      */
60     protected void tokenAuthRemoved(TokenAuth tokenAuth) {
61         this.tokenAuthCollection.remove(tokenAuth);
62     }
63
64     protected void tokenStoreAdded(TokenStore ts) {
65         this.tokenStore = ts;
66     }
67
68     protected void tokenStoreRemoved(TokenStore ts) {
69         this.tokenStore = null;
70     }
71
72     protected void authenticationServiceAdded(AuthenticationService as) {
73         this.authenticationService = as;
74     }
75
76     protected void authenticationServiceRemoved(AuthenticationService as) {
77         this.authenticationService = null;
78     }
79
80     protected void credentialAuthAdded(CredentialAuth<PasswordCredentials> da) {
81         this.credentialAuth = da;
82     }
83
84     protected void credentialAuthAddedRemoved(CredentialAuth<PasswordCredentials> da) {
85         this.credentialAuth = null;
86     }
87
88     public List<TokenAuth> getTokenAuthCollection() {
89         return tokenAuthCollection;
90     }
91
92     public void setTokenAuthCollection(List<TokenAuth> tokenAuthCollection) {
93         this.tokenAuthCollection = tokenAuthCollection;
94     }
95
96     public CredentialAuth<PasswordCredentials> getCredentialAuth() {
97         return credentialAuth;
98     }
99
100     public synchronized void setCredentialAuth(CredentialAuth<PasswordCredentials> credentialAuth) {
101         this.credentialAuth = credentialAuth;
102     }
103
104     public TokenStore getTokenStore() {
105         return tokenStore;
106     }
107
108     public void setTokenStore(TokenStore tokenStore) {
109         this.tokenStore = tokenStore;
110     }
111
112     public AuthenticationService getAuthenticationService() {
113         return authenticationService;
114     }
115
116     public void setAuthenticationService(AuthenticationService authenticationService) {
117         this.authenticationService = authenticationService;
118     }
119
120     public IdMService getIdmService() {
121         return idmService;
122     }
123
124     public void setIdmService(IdMService idmService) {
125         this.idmService = idmService;
126     }
127 }