diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core')
-rw-r--r-- | ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java index 3e23fed8..d04acc8d 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java @@ -37,6 +37,7 @@ */ package org.onap.portalapp.controller.core; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; @@ -50,6 +51,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; +import org.onap.portalapp.model.EPServiceCookie; import org.onap.portalsdk.core.auth.LoginStrategy; import org.onap.portalsdk.core.command.LoginBean; import org.onap.portalsdk.core.controller.UnRestrictedBaseController; @@ -69,9 +71,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.WebUtils; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + @Controller @RequestMapping("/") public class SingleSignOnController extends UnRestrictedBaseController { @@ -86,6 +93,9 @@ public class SingleSignOnController extends UnRestrictedBaseController { @Autowired private RoleService roleService; + + + private RestTemplate restTemplate = new RestTemplate(); private String viewName; private String welcomeView; @@ -233,9 +243,33 @@ public class SingleSignOnController extends UnRestrictedBaseController { PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, AppUtils.getSession(request)); } - public boolean isLoginCookieExist(HttpServletRequest request) { + public boolean isLoginCookieExist(HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException { Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); - return ep != null; + if(ep!=null) { + return validateEPServiceCookie(ep.getValue()); + } + return false; + } + + //This method is validating EPService cookie in portal + public boolean validateEPServiceCookie(String cookieValue) throws JsonParseException, JsonMappingException, IOException{ + Boolean result = false; + try{ + //Create json Request for REST call + final String uri = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + ObjectMapper mapper = new ObjectMapper(); + Map<String,String> valueMap = mapper.readValue(URLDecoder.decode(cookieValue, "UTF-8"),HashMap.class); + + EPServiceCookie epServiceCookie = new EPServiceCookie(); + epServiceCookie.setValue(valueMap); + //Call portal service to validate + result = restTemplate.postForObject( uri+"/v3/validateCookie", epServiceCookie, Boolean.class); + logger.info(EELFLoggerDelegate.applicationLogger,"Epservice cookie validation result:: "+result); + }catch(Exception e){ + logger.error(EELFLoggerDelegate.errorLogger,"Error in calling service :: "+e.getMessage()); + } + + return result; } public String getPortalJSessionId(HttpServletRequest request) { |