2 * Copyright (c) 2014 - 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
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
9 package org.opendaylight.aaa.impl.shiro.tokenauthrealm;
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;
21 * A service locator to bridge between the web world and OSGi world.
25 public class ServiceLocator {
27 private static final ServiceLocator INSTANCE = new ServiceLocator();
29 protected volatile List<TokenAuth> tokenAuthCollection = new Vector<>();
31 protected volatile CredentialAuth<PasswordCredentials> credentialAuth;
33 protected volatile TokenStore tokenStore;
35 protected volatile AuthenticationService authenticationService;
37 protected volatile IdMService idmService;
39 private ServiceLocator() {
42 public static ServiceLocator getInstance() {
47 * Called through reflection by the oauth2 activator.
49 * @param tokenAuth tokenAuth service.
51 protected void tokenAuthAdded(TokenAuth tokenAuth) {
52 this.tokenAuthCollection.add(tokenAuth);
56 * Called through reflection by the oauth2 activator.
58 * @param tokenAuth token auth service.
60 protected void tokenAuthRemoved(TokenAuth tokenAuth) {
61 this.tokenAuthCollection.remove(tokenAuth);
64 protected void tokenStoreAdded(TokenStore ts) {
68 protected void tokenStoreRemoved(TokenStore ts) {
69 this.tokenStore = null;
72 protected void authenticationServiceAdded(AuthenticationService as) {
73 this.authenticationService = as;
76 protected void authenticationServiceRemoved(AuthenticationService as) {
77 this.authenticationService = null;
80 protected void credentialAuthAdded(CredentialAuth<PasswordCredentials> da) {
81 this.credentialAuth = da;
84 protected void credentialAuthAddedRemoved(CredentialAuth<PasswordCredentials> da) {
85 this.credentialAuth = null;
88 public List<TokenAuth> getTokenAuthCollection() {
89 return tokenAuthCollection;
92 public void setTokenAuthCollection(List<TokenAuth> tokenAuthCollection) {
93 this.tokenAuthCollection = tokenAuthCollection;
96 public CredentialAuth<PasswordCredentials> getCredentialAuth() {
97 return credentialAuth;
100 public synchronized void setCredentialAuth(CredentialAuth<PasswordCredentials> credentialAuth) {
101 this.credentialAuth = credentialAuth;
104 public TokenStore getTokenStore() {
108 public void setTokenStore(TokenStore tokenStore) {
109 this.tokenStore = tokenStore;
112 public AuthenticationService getAuthenticationService() {
113 return authenticationService;
116 public void setAuthenticationService(AuthenticationService authenticationService) {
117 this.authenticationService = authenticationService;
120 public IdMService getIdmService() {
124 public void setIdmService(IdMService idmService) {
125 this.idmService = idmService;