X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fportalapi%2FPortalAuthManager.java;h=f4daa5c27f901aa310b1e41e7d169dfbc9629242;hb=592ce20ec359928373de2e7f06214c8f8ad73c20;hp=dc70f7e798c1a15d4f96bfbb0224f489b84897ee;hpb=3b1e23945b9426ad7aaacfc3794e15286d82c816;p=nonrtric.git diff --git a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManager.java b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManager.java index dc70f7e7..f4daa5c2 100644 --- a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManager.java +++ b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManager.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,83 +38,83 @@ import org.slf4j.LoggerFactory; */ public class PortalAuthManager { - private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - final Map credentialsMap; - private final IPortalSdkDecryptor portalSdkDecryptor; - private final String userIdCookieName; + final Map credentialsMap; + private final IPortalSdkDecryptor portalSdkDecryptor; + private final String userIdCookieName; - public PortalAuthManager(final String appName, final String username, final String password, - final String decryptorClassName, final String userCookie) - throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchMethodException, SecurityException { - credentialsMap = new HashMap<>(); - credentialsMap.put(IPortalRestCentralService.CREDENTIALS_APP, appName); - credentialsMap.put(IPortalRestCentralService.CREDENTIALS_USER, username); - credentialsMap.put(IPortalRestCentralService.CREDENTIALS_PASS, password); - this.userIdCookieName = userCookie; - // Instantiate here so configuration errors are detected at app-start time - logger.debug("ctor: using decryptor class {}", decryptorClassName); - Class decryptorClass = Class.forName(decryptorClassName); - portalSdkDecryptor = (IPortalSdkDecryptor) decryptorClass.getDeclaredConstructor().newInstance(); - } + public PortalAuthManager(final String appName, final String username, final String password, + final String decryptorClassName, final String userCookie) + throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException, NoSuchMethodException, SecurityException { + credentialsMap = new HashMap<>(); + credentialsMap.put(IPortalRestCentralService.CREDENTIALS_APP, appName); + credentialsMap.put(IPortalRestCentralService.CREDENTIALS_USER, username); + credentialsMap.put(IPortalRestCentralService.CREDENTIALS_PASS, password); + this.userIdCookieName = userCookie; + // Instantiate here so configuration errors are detected at app-start time + logger.debug("ctor: using decryptor class {}", decryptorClassName); + Class decryptorClass = Class.forName(decryptorClassName); + portalSdkDecryptor = (IPortalSdkDecryptor) decryptorClass.getDeclaredConstructor().newInstance(); + } - /** - * @return A map of key-value pairs with application name, user name and - * password. - */ - public Map getAppCredentials() { - return credentialsMap; - } + /** + * @return A map of key-value pairs with application name, user name and + * password. + */ + public Map getAppCredentials() { + return credentialsMap; + } - /** - * Searches the request for a cookie with the specified name. - * - * @param request - * HttpServletRequest - * @param cookieName - * Cookie name - * @return Cookie, or null if not found. - */ - private Cookie getCookie(HttpServletRequest request, String cookieName) { - Cookie[] cookies = request.getCookies(); - if (cookies != null) - for (Cookie cookie : cookies) - if (cookie.getName().equals(cookieName)) - return cookie; - return null; - } + /** + * Searches the request for a cookie with the specified name. + * + * @param request + * HttpServletRequest + * @param cookieName + * Cookie name + * @return Cookie, or null if not found. + */ + private Cookie getCookie(HttpServletRequest request, String cookieName) { + Cookie[] cookies = request.getCookies(); + if (cookies != null) + for (Cookie cookie : cookies) + if (cookie.getName().equals(cookieName)) + return cookie; + return null; + } - /** - * Validates whether the ECOMP Portal sign-on process has completed. Checks for - * the ECOMP cookie first, then the user cookie. - * - * @param request - * HttpServletRequest - * @return User ID if the ECOMP cookie is present and the sign-on process - * established a user ID; else null. - */ - public String validateEcompSso(HttpServletRequest request) { - // Check ECOMP Portal cookie - Cookie ep = getCookie(request, PortalApiConstants.EP_SERVICE); - if (ep == null) { - logger.debug("validateEcompSso: cookie not found: {}", PortalApiConstants.EP_SERVICE); - return null; - } - logger.trace("validateEcompSso: found cookie {}", PortalApiConstants.EP_SERVICE); - Cookie user = getCookie(request, userIdCookieName); - if (user == null) { - logger.debug("validateEcompSso: cookie not found: {}", userIdCookieName); - return null; - } - logger.trace("validateEcompSso: user cookie {}", userIdCookieName); - String userid = null; - try { - userid = portalSdkDecryptor.decrypt(user.getValue()); - } catch (CipherUtilException e) { - throw new IllegalArgumentException("validateEcompSso failed", e); - } - return userid; - } + /** + * Validates whether the ECOMP Portal sign-on process has completed. Checks for + * the ECOMP cookie first, then the user cookie. + * + * @param request + * HttpServletRequest + * @return User ID if the ECOMP cookie is present and the sign-on process + * established a user ID; else null. + */ + public String validateEcompSso(HttpServletRequest request) { + // Check ECOMP Portal cookie + Cookie ep = getCookie(request, PortalApiConstants.EP_SERVICE); + if (ep == null) { + logger.debug("validateEcompSso: cookie not found: {}", PortalApiConstants.EP_SERVICE); + return null; + } + logger.trace("validateEcompSso: found cookie {}", PortalApiConstants.EP_SERVICE); + Cookie user = getCookie(request, userIdCookieName); + if (user == null) { + logger.debug("validateEcompSso: cookie not found: {}", userIdCookieName); + return null; + } + logger.trace("validateEcompSso: user cookie {}", userIdCookieName); + String userid = null; + try { + userid = portalSdkDecryptor.decrypt(user.getValue()); + } catch (CipherUtilException e) { + throw new IllegalArgumentException("validateEcompSso failed", e); + } + return userid; + } }