Skip to content

Commit 4e33b53

Browse files
This closes #3246
2 parents b85156c + 9085340 commit 4e33b53

25 files changed

Lines changed: 440 additions & 124 deletions

File tree

artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.apache.activemq.artemis.core.config.FileDeploymentManager;
7070
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
7171
import org.apache.activemq.artemis.core.security.CheckType;
72+
import org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl;
7273
import org.apache.activemq.artemis.core.server.ActiveMQServer;
7374
import org.apache.activemq.artemis.core.server.JournalType;
7475
import org.apache.activemq.artemis.core.server.management.ManagementContext;
@@ -621,6 +622,7 @@ public void testProperReloadWhenAddingUserViaManagement() throws Exception {
621622
activeMQServerControl.addSecuritySettings("myAddress", "myRole", "myRole", "myRole", "myRole", "myRole", "myRole", "myRole", "myRole", "myRole", "myRole");
622623
// change properties files which should cause another "reload" event
623624
activeMQServerControl.addUser("foo", "bar", "myRole", true);
625+
((SecurityStoreImpl)activeMQServer.getSecurityStore()).invalidateAuthenticationCache();
624626
ClientSession session = sessionFactory.createSession("foo", "bar", false, false, false, false, 0);
625627
session.createQueue("myAddress", RoutingType.ANYCAST, "myQueue", true);
626628
ClientProducer producer = session.createProducer("myAddress");

artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,4 +2737,20 @@ static void isGroupRebalancePauseDispatch(Object source) {
27372737
@LogMessage(level = Logger.Level.INFO)
27382738
@Message(id = 601735, value = "User {0} is getting group rebalance pause dispatch property on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
27392739
void isGroupRebalancePauseDispatch(String user, Object source, Object... args);
2740+
2741+
static void getAuthenticationCacheSize(Object source) {
2742+
LOGGER.getAuthenticationCacheSize(getCaller(), source);
2743+
}
2744+
2745+
@LogMessage(level = Logger.Level.INFO)
2746+
@Message(id = 601736, value = "User {0} is getting authentication cache size on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
2747+
void getAuthenticationCacheSize(String user, Object source, Object... args);
2748+
2749+
static void getAuthorizationCacheSize(Object source) {
2750+
LOGGER.getAuthorizationCacheSize(getCaller(), source);
2751+
}
2752+
2753+
@LogMessage(level = Logger.Level.INFO)
2754+
@Message(id = 601737, value = "User {0} is getting authorization cache size on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
2755+
void getAuthorizationCacheSize(String user, Object source, Object... args);
27402756
}

artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ public static String getDefaultHapolicyBackupStrategy() {
160160
// how long (in ms) to wait before invalidating the security cache
161161
private static long DEFAULT_SECURITY_INVALIDATION_INTERVAL = 10000;
162162

163+
// how large to make the authentication cache
164+
private static long DEFAULT_AUTHENTICATION_CACHE_SIZE = 1000;
165+
166+
// how large to make the authorization cache
167+
private static long DEFAULT_AUTHORIZATION_CACHE_SIZE = 1000;
168+
163169
// how long (in ms) to wait to acquire a file lock on the journal
164170
private static long DEFAULT_JOURNAL_LOCK_ACQUISITION_TIMEOUT = -1;
165171

@@ -680,6 +686,20 @@ public static long getDefaultSecurityInvalidationInterval() {
680686
return DEFAULT_SECURITY_INVALIDATION_INTERVAL;
681687
}
682688

689+
/**
690+
* how large to make the authentication cache
691+
*/
692+
public static long getDefaultAuthenticationCacheSize() {
693+
return DEFAULT_AUTHENTICATION_CACHE_SIZE;
694+
}
695+
696+
/**
697+
* how large to make the authorization cache
698+
*/
699+
public static long getDefaultAuthorizationCacheSize() {
700+
return DEFAULT_AUTHORIZATION_CACHE_SIZE;
701+
}
702+
683703
/**
684704
* how long (in ms) to wait to acquire a file lock on the journal
685705
*/

artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,18 @@ public interface ActiveMQServerControl {
460460
@Attribute(desc = ADDRESS_MEMORY_USAGE_PERCENTAGE_DESCRIPTION)
461461
int getAddressMemoryUsagePercentage();
462462

463+
/**
464+
* Returns the runtime size of the authentication cache
465+
*/
466+
@Attribute(desc = "The runtime size of the authentication cache")
467+
long getAuthenticationCacheSize();
468+
469+
/**
470+
* Returns the runtime size of the authorization cache
471+
*/
472+
@Attribute(desc = "The runtime size of the authorization cache")
473+
long getAuthorizationCacheSize();
474+
463475
// Operations ----------------------------------------------------
464476
@Operation(desc = "Isolate the broker", impact = MBeanOperationInfo.ACTION)
465477
boolean freezeReplication();

artemis-features/src/main/resources/features.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<bundle dependency="true">mvn:org.apache.commons/commons-text/${commons.text.version}</bundle>
7272
<bundle dependency="true">mvn:org.apache.commons/commons-lang3/${commons.lang.version}</bundle>
7373
<bundle dependency="true">mvn:org.jctools/jctools-core/${jctools.version}</bundle>
74+
<bundle dependency="true">mvn:com.google.guava/guava/${guava.version}</bundle>
7475
<!-- Micrometer can't be included until it supports OSGi. It is currently an "optional" Maven dependency. -->
7576
<!--bundle dependency="true">mvn:io.micrometer/micrometer-core/${version.micrometer}</bundle-->
7677

artemis-server/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@
4545
<optional>true</optional>
4646
</dependency>
4747
<dependency>
48-
<groupId>com.google.errorprone</groupId>
49-
<artifactId>error_prone_core</artifactId>
48+
<groupId>com.google.errorprone</groupId>
49+
<artifactId>error_prone_core</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.google.guava</groupId>
53+
<artifactId>guava</artifactId>
5054
</dependency>
5155
<dependency>
5256
<groupId>org.jboss.logging</groupId>

artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,28 @@ public interface Configuration {
211211
*/
212212
Configuration setSecurityInvalidationInterval(long interval);
213213

214+
/**
215+
* Sets the size of the authentication cache.
216+
*/
217+
Configuration setAuthenticationCacheSize(long size);
218+
219+
/**
220+
* Returns the configured size of the authentication cache. <br>
221+
* Default value is {@link org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration#DEFAULT_AUTHENTICATION_CACHE_SIZE}.
222+
*/
223+
long getAuthenticationCacheSize();
224+
225+
/**
226+
* Sets the size of the authorization cache.
227+
*/
228+
Configuration setAuthorizationCacheSize(long size);
229+
230+
/**
231+
* Returns the configured size of the authorization cache. <br>
232+
* Default value is {@link org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration#DEFAULT_AUTHORIZATION_CACHE_SIZE}.
233+
*/
234+
long getAuthorizationCacheSize();
235+
214236
/**
215237
* Returns whether security is enabled for this server. <br>
216238
* Default value is {@link org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration#DEFAULT_SECURITY_ENABLED}.

artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public class ConfigurationImpl implements Configuration, Serializable {
122122

123123
private long securityInvalidationInterval = ActiveMQDefaultConfiguration.getDefaultSecurityInvalidationInterval();
124124

125+
private long authenticationCacheSize = ActiveMQDefaultConfiguration.getDefaultAuthenticationCacheSize();
126+
127+
private long authorizationCacheSize = ActiveMQDefaultConfiguration.getDefaultAuthorizationCacheSize();
128+
125129
private boolean securityEnabled = ActiveMQDefaultConfiguration.isDefaultSecurityEnabled();
126130

127131
private boolean gracefulShutdownEnabled = ActiveMQDefaultConfiguration.isDefaultGracefulShutdownEnabled();
@@ -506,6 +510,28 @@ public ConfigurationImpl setSecurityInvalidationInterval(final long interval) {
506510
return this;
507511
}
508512

513+
@Override
514+
public long getAuthenticationCacheSize() {
515+
return authenticationCacheSize;
516+
}
517+
518+
@Override
519+
public ConfigurationImpl setAuthenticationCacheSize(final long size) {
520+
authenticationCacheSize = size;
521+
return this;
522+
}
523+
524+
@Override
525+
public long getAuthorizationCacheSize() {
526+
return authorizationCacheSize;
527+
}
528+
529+
@Override
530+
public ConfigurationImpl setAuthorizationCacheSize(final long size) {
531+
authorizationCacheSize = size;
532+
return this;
533+
}
534+
509535
@Override
510536
public long getConnectionTTLOverride() {
511537
return connectionTTLOverride;

artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ public void parseMainConfig(final Element e, final Configuration config) throws
370370

371371
config.setJMXUseBrokerName(getBoolean(e, "jmx-use-broker-name", config.isJMXUseBrokerName()));
372372

373-
config.setSecurityInvalidationInterval(getLong(e, "security-invalidation-interval", config.getSecurityInvalidationInterval(), Validators.GT_ZERO));
373+
config.setSecurityInvalidationInterval(getLong(e, "security-invalidation-interval", config.getSecurityInvalidationInterval(), Validators.GE_ZERO));
374+
375+
config.setAuthenticationCacheSize(getLong(e, "authentication-cache-size", config.getAuthenticationCacheSize(), Validators.GE_ZERO));
376+
377+
config.setAuthorizationCacheSize(getLong(e, "authorization-cache-size", config.getAuthorizationCacheSize(), Validators.GE_ZERO));
374378

375379
config.setConnectionTTLOverride(getLong(e, "connection-ttl-override", config.getConnectionTTLOverride(), Validators.MINUS_ONE_OR_GT_ZERO));
376380

artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import org.apache.activemq.artemis.core.remoting.server.RemotingService;
9292
import org.apache.activemq.artemis.core.security.CheckType;
9393
import org.apache.activemq.artemis.core.security.Role;
94+
import org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl;
9495
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
9596
import org.apache.activemq.artemis.core.server.ActiveMQServer;
9697
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
@@ -757,6 +758,22 @@ public int getAddressMemoryUsagePercentage() {
757758
return (int) result;
758759
}
759760

761+
@Override
762+
public long getAuthenticationCacheSize() {
763+
if (AuditLogger.isEnabled()) {
764+
AuditLogger.getAuthenticationCacheSize(this.server);
765+
}
766+
return ((SecurityStoreImpl)server.getSecurityStore()).getAuthenticationCacheSize();
767+
}
768+
769+
@Override
770+
public long getAuthorizationCacheSize() {
771+
if (AuditLogger.isEnabled()) {
772+
AuditLogger.getAuthorizationCacheSize(this.server);
773+
}
774+
return ((SecurityStoreImpl)server.getSecurityStore()).getAuthorizationCacheSize();
775+
}
776+
760777
@Override
761778
public boolean freezeReplication() {
762779
if (AuditLogger.isEnabled()) {

0 commit comments

Comments
 (0)