diff options
author | Michael Dürre <michael.duerre@highstreet-technologies.com> | 2022-08-31 08:46:55 +0200 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2022-08-31 21:04:07 +0000 |
commit | 34f89faa64f815d5cf33d0905046eaf392017b39 (patch) | |
tree | 7bd6295609feb87b3fa187602985b58e34965fe4 /sdnr/wt/oauth-provider/provider-jar | |
parent | 63d92319b01b54d72bde494f923f80eb6c242cfe (diff) |
add fixes for wt sulfur
fix devmgrs and db access
Issue-ID: CCSDK-3749
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Change-Id: I41018d2daa55b200a9ba89e784f8adf4200d32c3
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/oauth-provider/provider-jar')
-rw-r--r-- | sdnr/wt/oauth-provider/provider-jar/src/main/java/org/onap/ccsdk/features/sdnr/wt/oauthprovider/providers/TokenCreator.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sdnr/wt/oauth-provider/provider-jar/src/main/java/org/onap/ccsdk/features/sdnr/wt/oauthprovider/providers/TokenCreator.java b/sdnr/wt/oauth-provider/provider-jar/src/main/java/org/onap/ccsdk/features/sdnr/wt/oauthprovider/providers/TokenCreator.java index 47d5fee01..d8720e823 100644 --- a/sdnr/wt/oauth-provider/provider-jar/src/main/java/org/onap/ccsdk/features/sdnr/wt/oauthprovider/providers/TokenCreator.java +++ b/sdnr/wt/oauth-provider/provider-jar/src/main/java/org/onap/ccsdk/features/sdnr/wt/oauthprovider/providers/TokenCreator.java @@ -95,7 +95,7 @@ public class TokenCreator { private Algorithm createAlgorithm(String alg, String secret, String pubkey) throws IllegalArgumentException, IOException { - if(alg==null) { + if (alg == null) { alg = Config.TOKENALG_HS256; } switch (alg) { @@ -153,24 +153,31 @@ public class TokenCreator { public String getBearerToken(HttpServletRequest req) { return this.getBearerToken(req, false); } + public String getBearerToken(HttpServletRequest req, boolean checkCookie) { final String authHeader = req.getHeader("Authorization"); if ((authHeader == null || !authHeader.startsWith("Bearer")) && checkCookie) { - Optional<Cookie> ocookie = - Arrays.stream(req.getCookies()).filter(c -> COOKIE_NAME_AUTH.equals(c.getName())).findFirst(); - if(ocookie.isEmpty()) { + Cookie[] cookies = req.getCookies(); + Optional<Cookie> ocookie = Optional.empty(); + if (cookies != null) { + ocookie = Arrays.stream(cookies).filter(c -> c != null && COOKIE_NAME_AUTH.equals(c.getName())) + .findFirst(); + } + if (ocookie.isEmpty()) { return null; } return ocookie.get().getValue(); } return authHeader.substring(7); } + public UserTokenPayload decode(HttpServletRequest req) throws JWTDecodeException { final String token = this.getBearerToken(req); - return token!=null?this.decode(token):null; + return token != null ? this.decode(token) : null; } - public UserTokenPayload decode(String token){ - if(token == null){ + + public UserTokenPayload decode(String token) { + if (token == null) { return null; } DecodedJWT jwt = JWT.decode(token); @@ -185,8 +192,8 @@ public class TokenCreator { } public Cookie createAuthCookie(BearerToken data) { - Cookie cookie = new Cookie(COOKIE_NAME_AUTH, data.getToken()); - cookie.setMaxAge((int)this.tokenLifetimeSeconds); + Cookie cookie = new Cookie(COOKIE_NAME_AUTH, data.getToken()); + cookie.setMaxAge((int) this.tokenLifetimeSeconds); cookie.setPath("/"); cookie.setHttpOnly(true); cookie.setSecure(true); |