diff options
author | Krishnajinka <kris.jinka@samsung.com> | 2018-07-06 17:28:54 +0900 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-07-10 14:40:24 +0000 |
commit | ec248ffb74f1c038fdd6c7a77411f628ef51366f (patch) | |
tree | a790240451325798417300472b31a86993987160 /appc-adapters/appc-iaas-adapter | |
parent | 72dbb19dd424ef559422bd0243d6a3179e01c382 (diff) |
null ptr check
rework based on review comments
Issue-ID: APPC-1047
Change-Id: Ia87707535dc5825d18a6c35fdae416064dcb8c14
Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter')
2 files changed, 23 insertions, 14 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java index b22b6843a..73872040b 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java @@ -161,6 +161,12 @@ public class ServiceCatalogV2 extends ServiceCatalog { try {
access = authenticate.execute();
+ //Ensure that access or the access token is not null before
+ //checking local expiration or accessing the tenant information
+ if (access == null || access.getToken() == null) {
+ throw new NullPointerException("The access key used to access the provider or access token is null." +
+ "Failed to init ServiceCatalogV2");
+ }
expiresLocal = getLocalExpiration(access);
tenant = access.getToken().getTenant();
tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());
@@ -370,13 +376,11 @@ public class ServiceCatalogV2 extends ServiceCatalog { */
private static long getLocalExpiration(Access accessKey) {
Date now = Time.getCurrentUTCDate();
- if (accessKey != null && accessKey.getToken() != null) {
- Calendar issued = accessKey.getToken().getIssued_at();
- Calendar expires = accessKey.getToken().getExpires();
- if (issued != null && expires != null) {
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
- return now.getTime() + tokenLife;
- }
+ Calendar issued = accessKey.getToken().getIssued_at();
+ Calendar expires = accessKey.getToken().getExpires();
+ if (issued != null && expires != null) {
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
+ return now.getTime() + tokenLife;
}
return now.getTime();
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java index 4773603c3..02e73c10c 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java @@ -55,6 +55,8 @@ import com.woorea.openstack.keystone.v3.model.Token.Project; import com.woorea.openstack.keystone.v3.model.Token.Service;
import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
+import javax.validation.constraints.Null;
+
/**
* This class is used to capture and cache the service catalog for a specific OpenStack provider.
* <p>
@@ -171,6 +173,11 @@ public class ServiceCatalogV3 extends ServiceCatalog { try {
token = authenticate.execute();
+ // Ensure that token is not null before accessing
+ // local expiration or the internal details of token
+ if (token == null) {
+ throw new NullPointerException("Access token is null. Failed to init ServiceCatalogV3");
+ }
expiresLocal = getLocalExpiration(token);
project = token.getProject();
tokenProvider = new OpenStackSimpleTokenProvider(token.getId());
@@ -386,13 +393,11 @@ public class ServiceCatalogV3 extends ServiceCatalog { */
private static long getLocalExpiration(Token accessToken) {
Date now = Time.getCurrentUTCDate();
- if (accessToken != null) {
- Calendar issued = accessToken.getIssuedAt();
- Calendar expires = accessToken.getExpiresAt();
- if (issued != null && expires != null) {
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
- return now.getTime() + tokenLife;
- }
+ Calendar issued = accessToken.getIssuedAt();
+ Calendar expires = accessToken.getExpiresAt();
+ if (issued != null && expires != null) {
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
+ return now.getTime() + tokenLife;
}
return now.getTime();
}
|