Skip to content

Commit 33a249e

Browse files
committed
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>
1 parent 550762a commit 33a249e

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public APIAuthenticationType getAPIType() {
191191
@Override
192192
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
193193
for (PluggableAPIAuthenticator authManager: authenticators) {
194-
if (authManager instanceof SAML2AuthManager) {
194+
if (authManager != null && authManager instanceof SAML2AuthManager) {
195195
_samlAuthManager = (SAML2AuthManager) authManager;
196196
}
197197
}

plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public APIAuthenticationType getAPIType() {
292292
@Override
293293
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
294294
for (PluggableAPIAuthenticator authManager: authenticators) {
295-
if (authManager instanceof SAML2AuthManager) {
295+
if (authManager != null && authManager instanceof SAML2AuthManager) {
296296
_samlAuthManager = (SAML2AuthManager) authManager;
297297
}
298298
}

plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public APIAuthenticationType getAPIType() {
158158
@Override
159159
public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
160160
for (PluggableAPIAuthenticator authManager: authenticators) {
161-
if (authManager instanceof SAML2AuthManager) {
161+
if (authManager != null && authManager instanceof SAML2AuthManager) {
162162
_samlAuthManager = (SAML2AuthManager) authManager;
163163
}
164164
}

server/src/com/cloud/api/auth/APIAuthenticationManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ public List<Class<?>> getCommands() {
6969
cmdList.add(DefaultLoginAPIAuthenticatorCmd.class);
7070
cmdList.add(DefaultLogoutAPIAuthenticatorCmd.class);
7171
for (PluggableAPIAuthenticator apiAuthenticator: _apiAuthenticators) {
72-
cmdList.addAll(apiAuthenticator.getAuthCommands());
72+
List<Class<?>> commands = apiAuthenticator.getAuthCommands();
73+
if (commands != null) {
74+
cmdList.addAll(commands);
75+
} else {
76+
s_logger.warn("API Authenticator returned null api commands:" + apiAuthenticator.getName());
77+
}
7378
}
7479
return cmdList;
7580
}

0 commit comments

Comments
 (0)