|
| 1 | +package it.eng.spagobi.commons.services; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import javax.servlet.http.HttpServletRequest; |
| 9 | +import javax.servlet.http.HttpServletResponse; |
| 10 | +import javax.ws.rs.POST; |
| 11 | +import javax.ws.rs.Path; |
| 12 | +import javax.ws.rs.core.Context; |
| 13 | +import javax.ws.rs.core.Response; |
| 14 | + |
| 15 | +import org.apache.log4j.Logger; |
| 16 | + |
| 17 | +import it.eng.knowage.commons.security.KnowageSystemConfiguration; |
| 18 | +import it.eng.knowage.pm.dto.PrivacyDTO; |
| 19 | +import it.eng.knowage.privacymanager.LoginEventBuilder; |
| 20 | +import it.eng.knowage.privacymanager.PrivacyManagerClient; |
| 21 | +import it.eng.spagobi.api.AbstractSpagoBIResource; |
| 22 | +import it.eng.spagobi.commons.SingletonConfig; |
| 23 | +import it.eng.spagobi.commons.bo.UserProfile; |
| 24 | +import it.eng.spagobi.commons.constants.SpagoBIConstants; |
| 25 | +import it.eng.spagobi.commons.utilities.AuditLogUtilities; |
| 26 | + |
| 27 | +@Path("/logout") |
| 28 | +public class LogoutResource extends AbstractSpagoBIResource { |
| 29 | + |
| 30 | + private static Logger logger = Logger.getLogger(LogoutResource.class); |
| 31 | + |
| 32 | + private static String INVALIDATE_JSP = "/invalidateSession.jsp"; |
| 33 | + |
| 34 | + @POST |
| 35 | + @Path("/") |
| 36 | + public Response logout(@Context HttpServletRequest request, @Context HttpServletResponse response) { |
| 37 | + logger.debug("IN"); |
| 38 | + |
| 39 | + // Recupero profilo utente |
| 40 | + UserProfile up = getUserProfile(); |
| 41 | + |
| 42 | + HashMap<String, String> logParam = new HashMap<>(); |
| 43 | + logParam.put("USER", up.toString()); |
| 44 | + AuditLogUtilities.updateAudit(request, up, "SPAGOBI.Logout", logParam, "OK"); |
| 45 | + |
| 46 | + // Costruzione evento Privacy |
| 47 | + LoginEventBuilder eventBuilder = new LoginEventBuilder(); |
| 48 | + eventBuilder.appendSession("knowage", up.getSourceIpAddress(), up.getSessionId(), up.getSessionStart(), up.getUserId().toString()); |
| 49 | + eventBuilder.appendUserAgent(up.getOs(), up.getSourceIpAddress(), up.getSourceSocketEnabled(), up.getUserAgent()); |
| 50 | + PrivacyDTO dto = eventBuilder.getDTO(); |
| 51 | + dto.setDescription("Logout"); |
| 52 | + PrivacyManagerClient.getInstance().sendMessage(dto); |
| 53 | + |
| 54 | + String redirectUrl = null; |
| 55 | + |
| 56 | + String active = SingletonConfig.getInstance().getConfigValue("SPAGOBI_SSO.ACTIVE"); |
| 57 | + String strUsePublicUser = SingletonConfig.getInstance().getConfigValue(SpagoBIConstants.USE_PUBLIC_USER); |
| 58 | + Boolean usePublicUser = (strUsePublicUser == null) ? false : Boolean.valueOf(strUsePublicUser); |
| 59 | + |
| 60 | + |
| 61 | + if ((active == null || active.equalsIgnoreCase("false"))) { |
| 62 | + String context = request.getContextPath(); |
| 63 | + if (Boolean.TRUE.equals(usePublicUser)) { |
| 64 | + context += "/servlet/AdapterHTTP?PAGE=LoginPage&NEW_SESSION=TRUE"; |
| 65 | + redirectUrl = context; |
| 66 | + } else { |
| 67 | + redirectUrl = context; |
| 68 | + } |
| 69 | + } else if (active != null && active.equalsIgnoreCase("true")) { |
| 70 | + |
| 71 | + redirectUrl = SingletonConfig.getInstance().getConfigValue("SPAGOBI_SSO.SECURITY_LOGOUT_URL"); |
| 72 | + } |
| 73 | + request.getSession().invalidate(); |
| 74 | + |
| 75 | + Map<String, Object> responseBody = new HashMap<>(); |
| 76 | + responseBody.put("redirectUrl", redirectUrl); |
| 77 | + responseBody.put("urlEnginesInvalidate", getUrlEnginesInvalidate()); |
| 78 | + |
| 79 | + logger.debug("OUT"); |
| 80 | + return Response.ok(responseBody).build(); |
| 81 | + } |
| 82 | + |
| 83 | + private List<String> getUrlEnginesInvalidate() { |
| 84 | + List<String> urlEnginesInvalidate = new ArrayList<>(); |
| 85 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageBirtReportEngineContext() + INVALIDATE_JSP); |
| 86 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageCockpitEngineContext() + INVALIDATE_JSP); |
| 87 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageDossierEngineContext() + INVALIDATE_JSP); |
| 88 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageJasperReportEngineContext() + INVALIDATE_JSP); |
| 89 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageKpiEngineContext() + INVALIDATE_JSP); |
| 90 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageMetaContext() + INVALIDATE_JSP); |
| 91 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageQbeEngineContext() + INVALIDATE_JSP); |
| 92 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageTalendEngineContext() + INVALIDATE_JSP); |
| 93 | + urlEnginesInvalidate.add(KnowageSystemConfiguration.getKnowageWhatifEngineContext() + INVALIDATE_JSP); |
| 94 | + return urlEnginesInvalidate; |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments