summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/oauth-provider/provider-jar
diff options
context:
space:
mode:
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.java25
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);