ARTEMIS-4293 add mngmnt ops to clear authn/z caches

This commit is contained in:
Justin Bertram 2023-05-25 18:07:33 -05:00 committed by Bruscino Domenico Francesco
parent ff4c697e25
commit 15aafe0b70
6 changed files with 72 additions and 2 deletions

View File

@ -2653,4 +2653,18 @@ public interface AuditLogger {
@LogMessage(id = 601768, value = "{} connection {} for user {} destroyed", level = LogMessage.Level.INFO)
void destroyedConnection(String protocol, String connectionID, String user);
static void clearAuthenticationCache(Object source) {
BASE_LOGGER.clearAuthenticationCache(getCaller(), source);
}
@LogMessage(id = 601769, value = "User {} is clearing authentication cache on target resource: {}", level = LogMessage.Level.INFO)
void clearAuthenticationCache(String user, Object source);
static void clearAuthorizationCache(Object source) {
BASE_LOGGER.clearAuthorizationCache(getCaller(), source);
}
@LogMessage(id = 601770, value = "User {} is clearing authorization cache on target resource: {}", level = LogMessage.Level.INFO)
void clearAuthorizationCache(String user, Object source);
}

View File

@ -2006,5 +2006,11 @@ public interface ActiveMQServerControl {
@Attribute(desc = "Scan all paged destinations to rebuild the page counters")
void rebuildPageCounters() throws Exception;
@Operation(desc = "Clear the authentication cache", impact = MBeanOperationInfo.ACTION)
void clearAuthenticationCache() throws Exception;
@Operation(desc = "Clear the authorization cache", impact = MBeanOperationInfo.ACTION)
void clearAuthorizationCache() throws Exception;
}

View File

@ -4664,5 +4664,21 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
}
throw ActiveMQMessageBundle.BUNDLE.embeddedWebServerNotFound();
}
@Override
public void clearAuthenticationCache() {
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.clearAuthenticationCache(this.server);
}
((SecurityStoreImpl)server.getSecurityStore()).invalidateAuthenticationCache();
}
@Override
public void clearAuthorizationCache() {
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.clearAuthorizationCache(this.server);
}
((SecurityStoreImpl)server.getSecurityStore()).invalidateAuthorizationCache();
}
}

View File

@ -424,12 +424,10 @@ public class SecurityStoreImpl implements SecurityStore, HierarchicalRepositoryC
logger.debug("Skipping authentication cache due to exception: {}", e.getMessage());
}
// public for testing purposes
public void invalidateAuthorizationCache() {
authorizationCache.invalidateAll();
}
// public for testing purposes
public void invalidateAuthenticationCache() {
authenticationCache.invalidateAll();
}

View File

@ -257,6 +257,32 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
Wait.assertEquals(usingCore() ? 8 : 1, () -> serverControl.getAuthorizationCacheSize());
}
@Test
public void testClearingSecurityCaches() throws Exception {
ActiveMQServerControl serverControl = createManagementControl();
ServerLocator loc = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(loc);
ClientSession session = csf.createSession("myUser", "myPass", false, true, false, false, 0);
session.start();
final String address = "ADDRESS";
serverControl.createAddress(address, "MULTICAST");
ClientProducer producer = session.createProducer(address);
ClientMessage m = session.createMessage(true);
m.putStringProperty("hello", "world");
producer.send(m);
Assert.assertTrue(serverControl.getAuthenticationCacheSize() > 0);
Wait.assertTrue(() -> serverControl.getAuthorizationCacheSize() > 0);
serverControl.clearAuthenticationCache();
serverControl.clearAuthorizationCache();
Assert.assertEquals(usingCore() ? 1 : 0, serverControl.getAuthenticationCacheSize());
Assert.assertEquals(usingCore() ? 7 : 0, serverControl.getAuthorizationCacheSize());
}
@Test
public void testGetConnectors() throws Exception {
ActiveMQServerControl serverControl = createManagementControl();

View File

@ -1754,6 +1754,16 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
public void rebuildPageCounters() throws Exception {
proxy.invokeOperation("rebuildPageCounters");
}
@Override
public void clearAuthenticationCache() throws Exception {
proxy.invokeOperation("clearAuthenticationCache");
}
@Override
public void clearAuthorizationCache() throws Exception {
proxy.invokeOperation("clearAuthorizationCache");
}
};
}