From 34f89faa64f815d5cf33d0905046eaf392017b39 Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Wed, 31 Aug 2022 08:46:55 +0200 Subject: add fixes for wt sulfur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix devmgrs and db access Issue-ID: CCSDK-3749 Signed-off-by: Michael Dürre Change-Id: I41018d2daa55b200a9ba89e784f8adf4200d32c3 Signed-off-by: Michael Dürre --- .../wt/oauthprovider/providers/TokenCreator.java | 25 ++++++++++++++-------- sdnr/wt/oauth-provider/provider-osgi/pom.xml | 6 ++++++ 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'sdnr/wt/oauth-provider') 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 ocookie = - Arrays.stream(req.getCookies()).filter(c -> COOKIE_NAME_AUTH.equals(c.getName())).findFirst(); - if(ocookie.isEmpty()) { + Cookie[] cookies = req.getCookies(); + Optional 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); diff --git a/sdnr/wt/oauth-provider/provider-osgi/pom.xml b/sdnr/wt/oauth-provider/provider-osgi/pom.xml index 3d4d138a2..41fe3c599 100644 --- a/sdnr/wt/oauth-provider/provider-osgi/pom.xml +++ b/sdnr/wt/oauth-provider/provider-osgi/pom.xml @@ -119,13 +119,18 @@ org.opendaylight.aaa.api.shiro.principal, org.opendaylight.aaa.shiro.realm, org.opendaylight.aaa.shiro.filters, + org.opendaylight.aaa.shiro.web.env, org.opendaylight.mdsal.binding.api, + org.opendaylight.mdsal.common.api, org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619, org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619.shiro.configuration, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.permission, + org.opendaylight.yangtools.concepts, org.opendaylight.yangtools.yang.binding, + org.opendaylight.yangtools.yang.common, com.fasterxml.jackson.databind, com.fasterxml.jackson.databind.deser.std, com.fasterxml.jackson.databind.ser.std, @@ -134,6 +139,7 @@ com.fasterxml.jackson.core.type, com.fasterxml.jackson.core, org.apache.commons.codec.binary, + com.google.common.base, com.google.common.collect, com.google.common.util.concurrent -- cgit 1.2.3-korg