CLOUDSTACK-7455: Fix possible case for NPE

NPE can happen if Spring fails to inject api authenticator, so better check
and set list of commands if the authenticator is not null or returning null cmds

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2014-08-31 14:42:18 +02:00
parent 550762a0dc
commit 33a249e77a
4 changed files with 9 additions and 4 deletions

View File

@ -191,7 +191,7 @@ public class GetServiceProviderMetaDataCmd extends BaseCmd implements APIAuthent
@Override
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
for (PluggableAPIAuthenticator authManager: authenticators) {
if (authManager instanceof SAML2AuthManager) {
if (authManager != null && authManager instanceof SAML2AuthManager) {
_samlAuthManager = (SAML2AuthManager) authManager;
}
}

View File

@ -292,7 +292,7 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
@Override
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
for (PluggableAPIAuthenticator authManager: authenticators) {
if (authManager instanceof SAML2AuthManager) {
if (authManager != null && authManager instanceof SAML2AuthManager) {
_samlAuthManager = (SAML2AuthManager) authManager;
}
}

View File

@ -158,7 +158,7 @@ public class SAML2LogoutAPIAuthenticatorCmd extends BaseCmd implements APIAuthen
@Override
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
for (PluggableAPIAuthenticator authManager: authenticators) {
if (authManager instanceof SAML2AuthManager) {
if (authManager != null && authManager instanceof SAML2AuthManager) {
_samlAuthManager = (SAML2AuthManager) authManager;
}
}

View File

@ -69,7 +69,12 @@ public class APIAuthenticationManagerImpl extends ManagerBase implements APIAuth
cmdList.add(DefaultLoginAPIAuthenticatorCmd.class);
cmdList.add(DefaultLogoutAPIAuthenticatorCmd.class);
for (PluggableAPIAuthenticator apiAuthenticator: _apiAuthenticators) {
cmdList.addAll(apiAuthenticator.getAuthCommands());
List<Class<?>> commands = apiAuthenticator.getAuthCommands();
if (commands != null) {
cmdList.addAll(commands);
} else {
s_logger.warn("API Authenticator returned null api commands:" + apiAuthenticator.getName());
}
}
return cmdList;
}