Repository: usergrid Updated Branches: refs/heads/token-service-to-dstax bea9a4180 -> 996344900
Add try/catch around fetching and casting of token info from serialization map. Also, throw exceptions early. Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/99634490 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/99634490 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/99634490 Branch: refs/heads/token-service-to-dstax Commit: 9963449003b1559277780ab193fb529ddfdf3b4b Parents: bea9a41 Author: Michael Russo <russomich...@google.com> Authored: Mon Jun 19 08:31:31 2017 -0700 Committer: Michael Russo <russomich...@google.com> Committed: Mon Jun 19 08:31:31 2017 -0700 ---------------------------------------------------------------------- .../security/tokens/impl/TokenServiceImpl.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/99634490/stack/services/src/main/java/org/apache/usergrid/security/tokens/impl/TokenServiceImpl.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/security/tokens/impl/TokenServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/security/tokens/impl/TokenServiceImpl.java index 21bd0db..f149a1f 100644 --- a/stack/services/src/main/java/org/apache/usergrid/security/tokens/impl/TokenServiceImpl.java +++ b/stack/services/src/main/java/org/apache/usergrid/security/tokens/impl/TokenServiceImpl.java @@ -417,11 +417,21 @@ public class TokenServiceImpl implements TokenService { throw new InvalidTokenException( "Token not found in database" ); } - String type = (String) tokenDetails.get(TOKEN_TYPE); - long created = (long) tokenDetails.get(TOKEN_CREATED); - long accessed = (long) tokenDetails.get(TOKEN_ACCESSED); - long inactive = (long) tokenDetails.get(TOKEN_INACTIVE); - long duration = (long) tokenDetails.get(TOKEN_DURATION); + String type; + long created, accessed, inactive, duration; + try { + type = (String) tokenDetails.get(TOKEN_TYPE); + created = (long) tokenDetails.get(TOKEN_CREATED); + accessed = (long) tokenDetails.get(TOKEN_ACCESSED); + inactive = (long) tokenDetails.get(TOKEN_INACTIVE); + duration = (long) tokenDetails.get(TOKEN_DURATION); + } catch (ClassCastException cce){ + logger.error("Unable to cast token info to primitive type: {}", cce); + throw new RuntimeException("Unable to cast token info to primitive type"); + } catch (NullPointerException npe){ + logger.error("Unable to obtain token info from serialization layer, on or more missing properties: {}", npe); + throw new RuntimeException("Unable to obtain token info from serialization layer, on or more missing properties"); + } String principalTypeStr = (String) tokenDetails.get(TOKEN_PRINCIPAL_TYPE);