Skip to content

Commit 31d8166

Browse files
committed
Refactoring ACTION LOGOUT_ACTION in rest resource LogoutResource
1 parent 7366161 commit 31d8166

7 files changed

Lines changed: 97 additions & 236 deletions

File tree

knowage-core/src/main/java/it/eng/spagobi/commons/services/LogoutAction.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
}

knowage/src/main/webapp/WEB-INF/conf/config/security.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<ACTION name="SERVICE_EXCEPTION_ACTION"/>
2929
<ACTION name="EMPTY_ACTION"/>
3030
<ACTION name="SESSION_EXPIRED_ACTION"/>
31-
<ACTION name="LOGOUT_ACTION"/>
3231
<ACTION name="CHANGE_THEME"/>
3332
<ACTION name="RATING_ACTION"/>
3433
<ACTION name="GET_PNG"/>

knowage/src/main/webapp/WEB-INF/conf/webapp/actions.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
<ACTION name="CHANGE_THEME" class="it.eng.spagobi.wapp.services.ChangeTheme" scope="REQUEST">
1616
<CONFIG/>
1717
</ACTION>
18-
<ACTION name="LOGOUT_ACTION" class="it.eng.spagobi.commons.services.LogoutAction" scope="REQUEST">
19-
<CONFIG/>
20-
</ACTION>
2118
<ACTION name="GET_PUBLIC_SUBOBJECTS_INFO" class="it.eng.spagobi.analiticalmodel.document.service.GetPublicSubobjectsInfo" scope="REQUEST">
2219
<CONFIG/>
2320
</ACTION>

knowage/src/main/webapp/WEB-INF/conf/webapp/presentation.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<PRESENTATION>
33

44
<MAPPING business_name="LoginPage" business_type="PAGE" publisher_name="LoginPublisherJava"/>
5-
<MAPPING business_name="LOGOUT_ACTION" business_type="ACTION" publisher_name="LogoutPublisher"/>
65
<MAPPING business_name="ViewBuilderPage" business_type="PAGE" publisher_name="ViewBuilderPublisherJava"/>
76
<MAPPING business_name="DirectExecutionPage" business_type="PAGE" publisher_name="DirectExecutionPublisherJava"/>
87
<MAPPING business_name="MenuPage" business_type="PAGE" publisher_name="MenuPublisherJava"/>

knowage/src/main/webapp/WEB-INF/conf/webapp/publishers.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
</RENDERING>
1818
</PUBLISHER>
1919

20-
<PUBLISHER name="LogoutPublisher">
21-
<RENDERING channel="HTTP" mode="FORWARD" type="JSP">
22-
<RESOURCES>
23-
<ITEM prog="0" resource="/WEB-INF/jsp/wapp/logout.jsp"/>
24-
</RESOURCES>
25-
</RENDERING>
26-
</PUBLISHER>
2720
<!--
2821
<PUBLISHER name="userhome">
2922
<RENDERING channel="HTTP" mode="FORWARD" type="JSP">

knowage/src/main/webapp/WEB-INF/jsp/wapp/logout.jsp

Lines changed: 0 additions & 166 deletions
This file was deleted.

0 commit comments

Comments
 (0)