-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTEMIS-4399 fix disabled authn/z cache
- Loading branch information
Showing
2 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...r/src/test/java/org/apache/activemq/artemis/core/security/impl/SecurityStoreImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.activemq.artemis.core.security.impl; | ||
|
||
import javax.security.auth.Subject; | ||
import java.util.Set; | ||
|
||
import org.apache.activemq.artemis.core.security.CheckType; | ||
import org.apache.activemq.artemis.core.security.Role; | ||
import org.apache.activemq.artemis.core.security.SecurityAuth; | ||
import org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository; | ||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; | ||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager5; | ||
import org.apache.activemq.artemis.spi.core.security.jaas.NoCacheLoginException; | ||
import org.apache.activemq.artemis.utils.RandomUtil; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class SecurityStoreImplTest { | ||
|
||
@Test | ||
public void zeroCacheSizeTest() throws Exception { | ||
ActiveMQSecurityManager5 securityManager = new ActiveMQSecurityManager5() { | ||
@Override | ||
public Subject authenticate(String user, | ||
String password, | ||
RemotingConnection remotingConnection, | ||
String securityDomain) throws NoCacheLoginException { | ||
return new Subject(); | ||
} | ||
|
||
@Override | ||
public boolean authorize(Subject subject, Set<Role> roles, CheckType checkType, String address) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean validateUser(String user, String password) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean validateUserAndRole(String user, String password, Set<Role> roles, CheckType checkType) { | ||
return false; | ||
} | ||
}; | ||
SecurityStoreImpl securityStore = new SecurityStoreImpl(new HierarchicalObjectRepository<>(), securityManager, 999, true, "", null, null, 0, 0); | ||
assertNull(securityStore.getAuthenticationCache()); | ||
securityStore.authenticate(RandomUtil.randomString(), RandomUtil.randomString(), null); | ||
assertEquals(0, securityStore.getAuthenticationCacheSize()); | ||
securityStore.invalidateAuthenticationCache(); // ensure this doesn't throw an NPE | ||
|
||
assertNull(securityStore.getAuthorizationCache()); | ||
securityStore.check(RandomUtil.randomSimpleString(), CheckType.SEND, new SecurityAuth() { | ||
@Override | ||
public String getUsername() { | ||
return RandomUtil.randomString(); | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return RandomUtil.randomString(); | ||
} | ||
|
||
@Override | ||
public RemotingConnection getRemotingConnection() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getSecurityDomain() { | ||
return null; | ||
} | ||
}); | ||
assertEquals(0, securityStore.getAuthorizationCacheSize()); | ||
securityStore.invalidateAuthorizationCache(); // ensure this doesn't throw an NPE | ||
} | ||
} |