mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
APIAuthenticationManagerImpl: add the auth manager and bean entry in spring xmls
- This implements ManageBase, is a pluggable service - Has a mechanism to return commands, useful for apidocs etc. - Has a method to return APIAuthenticator based on API command name Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
f7821ecf09
commit
bd2898e491
@ -32,6 +32,8 @@
|
||||
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
|
||||
>
|
||||
|
||||
<bean id="authenticationManagerImpl" class="com.cloud.api.auth.APIAuthenticationManagerImpl" />
|
||||
|
||||
<bean id="accountManagerImpl" class="com.cloud.user.AccountManagerImpl">
|
||||
<property name="userAuthenticators"
|
||||
value="#{userAuthenticatorsRegistry.registered}" />
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.auth;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Local(value = APIAuthenticationManager.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class APIAuthenticationManagerImpl extends ManagerBase implements APIAuthenticationManager {
|
||||
public static final Logger s_logger = Logger.getLogger(APIAuthenticationManagerImpl.class.getName());
|
||||
|
||||
private static Map<String, Class<?>> s_authenticators = null;
|
||||
private static List<Class<?>> s_commandList = null;
|
||||
|
||||
public APIAuthenticationManagerImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
s_authenticators = new HashMap<String, Class<?>>();
|
||||
for (Class<?> authenticator: getCommands()) {
|
||||
APICommand command = authenticator.getAnnotation(APICommand.class);
|
||||
if (command != null && !command.name().isEmpty()
|
||||
&& APIAuthenticator.class.isAssignableFrom(authenticator)) {
|
||||
s_authenticators.put(command.name(), authenticator);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
if (s_commandList == null) {
|
||||
s_commandList = new ArrayList<Class<?>>();
|
||||
s_commandList.add(DefaultLoginAPIAuthenticatorCmd.class);
|
||||
s_commandList.add(DefaultLogoutAPIAuthenticatorCmd.class);
|
||||
}
|
||||
return s_commandList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APIAuthenticator getAPIAuthenticator(String name) {
|
||||
APIAuthenticator apiAuthenticator = null;
|
||||
if (s_authenticators != null && s_authenticators.containsKey(name)) {
|
||||
try {
|
||||
apiAuthenticator = (APIAuthenticator) s_authenticators.get(name).newInstance();
|
||||
apiAuthenticator = ComponentContext.inject(apiAuthenticator);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("APIAuthenticationManagerImpl::getAPIAuthenticator failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return apiAuthenticator;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user