Skip to content

Commit b84e40e

Browse files
committed
feat(auth): endpoint and old PUC menu item to invalidate authorization cache [PPUC-318]
- depends on i18n added to pentaho-commons-gwt
1 parent 75dbc53 commit b84e40e

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

assemblies/pentaho-solutions/src/main/resources/pentaho-solutions/system/applicationContext-spring-security-csrf.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
GET /api/system/refresh/reportingDataCache
5757
GET /api/system/refresh/mondrianSingleSchemaCache
5858
GET /api/system/refresh/mondrianSchemaCache
59+
GET /api/system/refresh/authorizationDecisionCache
5960
-->
60-
<swm:regex-request-matcher pattern="^/api/system/refresh/(globalActions|metadata|systemSettings|reportingDataCache|mondrianSingleSchemaCache|mondrianSchemaCache)\b.*" methods="GET" />
61+
<swm:regex-request-matcher pattern="^/api/system/refresh/(globalActions|metadata|systemSettings|reportingDataCache|mondrianSingleSchemaCache|mondrianSchemaCache|authorizationDecisionCache)\b.*" methods="GET" />
6162

6263
<!--
6364
POST /api/licenseManager/addLicense

extensions/src/main/java/org/pentaho/platform/web/http/api/resources/SystemRefreshResource.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.codehaus.enunciate.Facet;
1717
import org.pentaho.platform.api.engine.ICacheManager;
1818
import org.pentaho.platform.api.engine.IPentahoSession;
19+
import org.pentaho.platform.api.engine.security.authorization.caching.IAuthorizationDecisionCache;
1920
import org.pentaho.platform.engine.core.system.PentahoSessionHolder;
2021
import org.pentaho.platform.engine.core.system.PentahoSystem;
2122
import org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService;
@@ -155,6 +156,22 @@ public Response purgeReportingDataCache() {
155156
}
156157
}
157158

159+
@GET
160+
@Path( "/authorizationDecisionCache" )
161+
@Produces( { MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON } )
162+
@Facet ( name = "Unsupported" )
163+
public Response flushAuthorizationDecisionCache() {
164+
if ( canAdminister() ) {
165+
IAuthorizationDecisionCache decisionCache = PentahoSystem.get( IAuthorizationDecisionCache.class );
166+
if ( decisionCache != null ) {
167+
decisionCache.invalidateAll();
168+
}
169+
return Response.ok().type( MediaType.TEXT_PLAIN ).build();
170+
} else {
171+
return Response.status( UNAUTHORIZED ).build();
172+
}
173+
}
174+
158175
private boolean canAdminister() {
159176
return SystemUtils.canAdminister();
160177
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*! ******************************************************************************
2+
*
3+
* Pentaho
4+
*
5+
* Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com
6+
*
7+
* Use of this software is governed by the Business Source License included
8+
* in the LICENSE.TXT file.
9+
*
10+
* Change Date: 2029-07-20
11+
******************************************************************************/
12+
13+
14+
package org.pentaho.mantle.client.commands;
15+
16+
import com.google.gwt.core.client.GWT;
17+
import com.google.gwt.http.client.Request;
18+
import com.google.gwt.http.client.RequestBuilder;
19+
import com.google.gwt.http.client.RequestCallback;
20+
import com.google.gwt.http.client.RequestException;
21+
import com.google.gwt.http.client.Response;
22+
import com.google.gwt.user.client.Window;
23+
import org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox;
24+
import org.pentaho.mantle.client.csrf.CsrfRequestBuilder;
25+
import org.pentaho.mantle.client.messages.Messages;
26+
27+
public class PurgeAuthorizationDecisionCacheCommand extends AbstractCommand {
28+
29+
@Override
30+
protected void performOperation() {
31+
performOperation( true );
32+
}
33+
34+
@Override
35+
protected void performOperation( final boolean feedback ) {
36+
String url = GWT.getHostPageBaseURL() + "api/system/refresh/authorizationDecisionCache";
37+
RequestBuilder requestBuilder = new CsrfRequestBuilder( RequestBuilder.GET, url );
38+
requestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" );
39+
requestBuilder.setHeader( "accept", "text/plain" );
40+
try {
41+
requestBuilder.sendRequest( null, new RequestCallback() {
42+
43+
public void onError( Request request, Throwable exception ) {
44+
// Do nothing.
45+
}
46+
47+
public void onResponseReceived( Request request, Response response ) {
48+
MessageDialogBox dialogBox =
49+
new MessageDialogBox(
50+
Messages.getString( "info" ),
51+
Messages.getString( "authorizationDecisionCacheFlushedSuccessfully" ),
52+
false,
53+
false,
54+
true );
55+
dialogBox.center();
56+
}
57+
} );
58+
} catch ( RequestException e ) {
59+
Window.alert( e.getMessage() );
60+
}
61+
}
62+
}

user-console/src/main/resources/org/pentaho/mantle/public/xul/mantle.xul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
command="mantleXulHandler.executeMantleCommand('PurgeMondrianSchemaCacheCommand')"/>
4949
<menuitem id="purgeReportingDataCacheMenuItem" label="${purgeReportingDataCache}"
5050
command="mantleXulHandler.executeMantleCommand('PurgeReportingDataCacheCommand')"/>
51+
<menuitem id="purgeAuthorizationDecisionCacheMenuItem" label="${purgeAuthorizationDecisionCache}"
52+
command="mantleXulHandler.executeMantleCommand('PurgeAuthorizationDecisionCacheCommand')"/>
5153
</menubar>
5254

5355
<!-- Uncomment line below to enable 'PDI Status page' menu item -->

0 commit comments

Comments
 (0)