You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/07/31 18:33:39 UTC
[isis] branch v2 updated: ISIS-2156 completes smoketest for module
security (secman) realm
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 124ef9f ISIS-2156 completes smoketest for module security (secman) realm
124ef9f is described below
commit 124ef9fa403f8ec1c7b768122ad51fb178e83069
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jul 31 20:33:30 2019 +0200
ISIS-2156 completes smoketest for module security (secman) realm
- we bring up the JDO testdomain with secman having seeded initial users
and roles, then we test Isis' Shiro Security Authentication
---
.../isis/security/shiro/IsisBootSecurityShiro.java | 5 +-
.../isis/security/IsisBootSecurityBypass.java | 5 +-
examples/smoketest/pom.xml | 24 ++++++++
.../isis/testdomain/jdo/JdoTestDomainModule.java | 9 +--
....java => JdoTestDomainModule_withSecurity.java} | 39 ++++++++++--
.../ldap/LdapEmbeddedServer.java | 12 ++--
.../ldap/LdapEmbeddedServerTest.java | 8 +--
.../shiro/AbstractShiroTest.java | 2 +-
.../shiro/ShiroIsisSecmanTest.java | 70 +++++++++++++++-------
.../shiro/ShiroSimpleTest.java | 2 +-
10 files changed, 126 insertions(+), 50 deletions(-)
diff --git a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/IsisBootSecurityShiro.java b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/IsisBootSecurityShiro.java
index e1f1e1d..326c50d 100644
--- a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/IsisBootSecurityShiro.java
+++ b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/IsisBootSecurityShiro.java
@@ -18,7 +18,6 @@
*/
package org.apache.isis.security.shiro;
-import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import org.apache.isis.security.authentication.manager.AuthorizationManagerStandard;
@@ -44,12 +43,12 @@ import org.springframework.context.annotation.Import;
})
public class IsisBootSecurityShiro {
- @Bean @Produces @Singleton
+ @Bean @Singleton
public Authenticator authenticator() {
return new ShiroAuthenticator();
}
- @Bean @Produces @Singleton
+ @Bean @Singleton
public Authorizor autorizor() {
return new ShiroAuthorizor();
}
diff --git a/core/security/src/main/java/org/apache/isis/security/IsisBootSecurityBypass.java b/core/security/src/main/java/org/apache/isis/security/IsisBootSecurityBypass.java
index 52ad904..a8580db 100644
--- a/core/security/src/main/java/org/apache/isis/security/IsisBootSecurityBypass.java
+++ b/core/security/src/main/java/org/apache/isis/security/IsisBootSecurityBypass.java
@@ -18,7 +18,6 @@
*/
package org.apache.isis.security;
-import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import org.apache.isis.security.authentication.bypass.AuthenticatorBypass;
@@ -43,12 +42,12 @@ import org.springframework.context.annotation.Import;
})
public class IsisBootSecurityBypass {
- @Bean @Produces @Singleton
+ @Bean @Singleton
public Authenticator authenticator() {
return new AuthenticatorBypass();
}
- @Bean @Produces @Singleton
+ @Bean @Singleton
public Authorizor autorizor() {
return new AuthorizorBypass();
}
diff --git a/examples/smoketest/pom.xml b/examples/smoketest/pom.xml
index def523c..1d7380f 100644
--- a/examples/smoketest/pom.xml
+++ b/examples/smoketest/pom.xml
@@ -116,6 +116,30 @@
<artifactId>isis-extensions-fixtures</artifactId>
<version>${isis.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.extensions</groupId>
+ <artifactId>isis-extensions-secman-model</artifactId>
+ <version>${isis.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.extensions</groupId>
+ <artifactId>isis-extensions-secman-encryption-jbcrypt</artifactId>
+ <version>${isis.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.extensions</groupId>
+ <artifactId>isis-extensions-secman-persistence-jdo</artifactId>
+ <version>${isis.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.extensions</groupId>
+ <artifactId>isis-extensions-secman-realm-shiro</artifactId>
+ <version>${isis.version}</version>
+ </dependency>
<!-- OTHER DEPENDENCIES -->
<!-- <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId>
diff --git a/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java b/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java
index 4907ce3..5336609 100644
--- a/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java
+++ b/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java
@@ -18,7 +18,6 @@
*/
package org.apache.isis.testdomain.jdo;
-import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import org.apache.isis.config.Presets;
@@ -28,6 +27,7 @@ import org.apache.isis.extensions.fixtures.IsisBootFixtures;
import org.apache.isis.jdo.IsisBootDataNucleus;
import org.apache.isis.runtime.spring.IsisBoot;
import org.apache.isis.security.IsisBootSecurityBypass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -49,16 +49,17 @@ import org.springframework.context.annotation.PropertySources;
JdoTestDomainModule.class
},
includeFilters= {
- @Filter(type = FilterType.CUSTOM, classes= {IsisBeanScanInterceptorForSpring.class})
- })
+ @Filter(type = FilterType.CUSTOM, classes= {IsisBeanScanInterceptorForSpring.class})}
+ )
@PropertySources({
@PropertySource("classpath:/org/apache/isis/testdomain/jdo/isis-non-changing.properties"),
@PropertySource(name=Presets.H2InMemory, factory = Presets.Factory.class, value = { "" }),
@PropertySource(name=Presets.NoTranslations, factory = Presets.Factory.class, value = { "" }),
})
+@ConditionalOnProperty(value = "withSecurity", havingValue = "false", matchIfMissing = true)
public class JdoTestDomainModule {
- @Bean @Produces @Singleton
+ @Bean @Singleton
public WebAppConfigBean webAppConfigBean() {
return WebAppConfigBean.builder()
//.menubarsLayoutXml(new ClassPathResource(path, clazz))
diff --git a/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java b/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule_withSecurity.java
similarity index 63%
copy from examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java
copy to examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule_withSecurity.java
index 4907ce3..9a5b520 100644
--- a/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule.java
+++ b/examples/smoketest/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainModule_withSecurity.java
@@ -18,16 +18,23 @@
*/
package org.apache.isis.testdomain.jdo;
-import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import org.apache.isis.config.Presets;
import org.apache.isis.config.beans.IsisBeanScanInterceptorForSpring;
import org.apache.isis.config.beans.WebAppConfigBean;
import org.apache.isis.extensions.fixtures.IsisBootFixtures;
+import org.apache.isis.extensions.secman.api.SecurityModuleConfig;
+import org.apache.isis.extensions.secman.api.permission.PermissionsEvaluationService;
+import org.apache.isis.extensions.secman.api.permission.PermissionsEvaluationServiceAllowBeatsVeto;
+import org.apache.isis.extensions.secman.encryption.jbcrypt.IsisBootSecmanEncryptionJbcrypt;
+import org.apache.isis.extensions.secman.jdo.IsisBootSecmanPersistenceJdo;
+import org.apache.isis.extensions.secman.model.IsisBootSecmanModel;
+import org.apache.isis.extensions.secman.shiro.IsisBootSecmanRealmShiro;
import org.apache.isis.jdo.IsisBootDataNucleus;
import org.apache.isis.runtime.spring.IsisBoot;
-import org.apache.isis.security.IsisBootSecurityBypass;
+import org.apache.isis.security.shiro.IsisBootSecurityShiro;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -40,13 +47,21 @@ import org.springframework.context.annotation.PropertySources;
@Configuration
@Import({
IsisBoot.class,
- IsisBootSecurityBypass.class,
+
+ IsisBootSecurityShiro.class,
+
+ // Security Manager Extension (secman)
+ IsisBootSecmanModel.class,
+ IsisBootSecmanRealmShiro.class,
+ IsisBootSecmanPersistenceJdo.class,
+ IsisBootSecmanEncryptionJbcrypt.class,
+
IsisBootDataNucleus.class,
IsisBootFixtures.class
})
@ComponentScan(
basePackageClasses= {
- JdoTestDomainModule.class
+ JdoTestDomainModule_withSecurity.class
},
includeFilters= {
@Filter(type = FilterType.CUSTOM, classes= {IsisBeanScanInterceptorForSpring.class})
@@ -56,13 +71,25 @@ import org.springframework.context.annotation.PropertySources;
@PropertySource(name=Presets.H2InMemory, factory = Presets.Factory.class, value = { "" }),
@PropertySource(name=Presets.NoTranslations, factory = Presets.Factory.class, value = { "" }),
})
-public class JdoTestDomainModule {
+@ConditionalOnProperty(value = "withSecurity", havingValue = "true", matchIfMissing = false)
+public class JdoTestDomainModule_withSecurity {
- @Bean @Produces @Singleton
+ @Bean @Singleton
public WebAppConfigBean webAppConfigBean() {
return WebAppConfigBean.builder()
//.menubarsLayoutXml(new ClassPathResource(path, clazz))
.build();
}
+
+ @Bean @Singleton
+ public SecurityModuleConfig securityModuleConfigBean() {
+ return SecurityModuleConfig.builder()
+ .build();
+ }
+
+ @Bean @Singleton
+ public PermissionsEvaluationService permissionsEvaluationService() {
+ return new PermissionsEvaluationServiceAllowBeatsVeto();
+ }
}
diff --git a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServer.java b/examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServer.java
similarity index 91%
rename from examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServer.java
rename to examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServer.java
index 0808734..65e15e0 100644
--- a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServer.java
+++ b/examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServer.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.testsecurity.ldap;
+package org.apache.isis.testdomain.ldap;
import java.util.concurrent.CountDownLatch;
@@ -42,13 +42,15 @@ import lombok.val;
@CreatePartition(name = "test", suffix = "dc=myorg,dc=com")
})
@CreateLdapServer(transports = {
- @CreateTransport(protocol = "LDAP", address = "localhost", port = 10389)})
+ @CreateTransport(protocol = "LDAP", address = "localhost", port = LdapEmbeddedServer.PORT)})
@ApplyLdifFiles({"ldap-users.ldif"})
public class LdapEmbeddedServer extends AbstractLdapTestUnit {
- @Test
+ public static final int PORT = 10389;
+
+ @Test
public void authenticateAgainstLdap() {
- // at this stage the LDAP server is setup an listening
+ // at this stage the LDAP server is setup and listening
}
public static CountDownLatch run() throws InitializationError, InterruptedException {
@@ -75,7 +77,7 @@ public class LdapEmbeddedServer extends AbstractLdapTestUnit {
thread.start();
- serverLanchedLatch.await();
+ serverLanchedLatch.await(); // wait for the server to be fully launched
return serverTerminatedLatch;
diff --git a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServerTest.java b/examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServerTest.java
similarity index 90%
rename from examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServerTest.java
rename to examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServerTest.java
index c1a2875..c92c02e 100644
--- a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/ldap/LdapEmbeddedServerTest.java
+++ b/examples/smoketest/src/test/java/org/apache/isis/testdomain/ldap/LdapEmbeddedServerTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.testsecurity.ldap;
+package org.apache.isis.testdomain.ldap;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@@ -39,11 +39,11 @@ class LdapEmbeddedServerTest {
@Test
void authenticateAgainstLdap() throws InitializationError, InterruptedException {
- val latch = LdapEmbeddedServer.run();
+ val serverLatch = LdapEmbeddedServer.run();
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
+ env.put(Context.PROVIDER_URL, "ldap://localhost:" + LdapEmbeddedServer.PORT);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Sven Tester,ou=Users,dc=myorg,dc=com");
@@ -64,7 +64,7 @@ class LdapEmbeddedServerTest {
} catch (NamingException e) {
fail(e.getMessage());
} finally {
- latch.countDown(); // release the ldap-server
+ serverLatch.countDown(); // release the ldap-server
}
diff --git a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/AbstractShiroTest.java b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
similarity index 98%
rename from examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/AbstractShiroTest.java
rename to examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
index b5903d1..8e5d6dd 100644
--- a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/AbstractShiroTest.java
+++ b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.testsecurity.shiro;
+package org.apache.isis.testdomain.shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.UnavailableSecurityManagerException;
diff --git a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroIsisSecmanTest.java b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroIsisSecmanTest.java
similarity index 58%
rename from examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroIsisSecmanTest.java
rename to examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroIsisSecmanTest.java
index f799d70..394359e 100644
--- a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroIsisSecmanTest.java
+++ b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroIsisSecmanTest.java
@@ -16,29 +16,42 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.testsecurity.shiro;
+package org.apache.isis.testdomain.shiro;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.apache.isis.extensions.secman.jdo.seed.scripts.IsisModuleSecurityAdminUser;
+import org.apache.isis.testdomain.jdo.JdoTestDomainModule_withSecurity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
-import org.apache.shiro.subject.Subject;
import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
import lombok.val;
+@SpringBootTest(
+ classes = {
+ JdoTestDomainModule_withSecurity.class,
+ },
+ properties = {
+ "withSecurity=true",
+ "logging.config=log4j2-test.xml",
+ "logging.level.org.apache.isis.jdo.transaction.IsisPlatformTransactionManagerForJdo=DEBUG",
+ "logging.level.org.apache.isis.runtime.system.transaction.IsisTransaction=DEBUG",
+ // "isis.reflector.introspector.parallelize=false",
+ // "logging.level.org.apache.isis.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
+ })
class ShiroIsisSecmanTest extends AbstractShiroTest {
@BeforeAll
- public static void beforeClass() {
+ static void beforeClass() {
//0. Build and set the SecurityManager used to build Subject instances used in your tests
// This typically only needs to be done once per class if your shiro.ini doesn't change,
// otherwise, you'll need to do this logic in each test that is different
@@ -47,27 +60,12 @@ class ShiroIsisSecmanTest extends AbstractShiroTest {
}
@AfterAll
- public static void tearDownSubject() {
+ static void tearDownSubject() {
tearDownShiro();
}
- @BeforeEach
- public void setUp() {
- //1. Build the Subject instance for the test to run:
- val subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
- //2. Bind the subject to the current thread:
- setSubject(subjectUnderTest);
- }
-
- @AfterEach
- public void cleanUp() {
- //3. Unbind the subject from the current thread:
- clearSubject();
- }
-
-
@Test
- public void loginLogoutRoundtrip() {
+ void loginLogoutRoundtrip() {
val secMan = SecurityUtils.getSecurityManager();
assertNotNull(secMan);
@@ -76,16 +74,42 @@ class ShiroIsisSecmanTest extends AbstractShiroTest {
assertNotNull(subject);
assertFalse(subject.isAuthenticated());
- val token = (AuthenticationToken) new UsernamePasswordToken("sven", "pass");
+ val token = (AuthenticationToken) new UsernamePasswordToken(
+ IsisModuleSecurityAdminUser.USER_NAME,
+ IsisModuleSecurityAdminUser.PASSWORD);
+
subject.login(token);
assertTrue(subject.isAuthenticated());
subject.logout();
assertFalse(subject.isAuthenticated());
+ }
+
+ @Test
+ void invalidLogin() {
+
+ val secMan = SecurityUtils.getSecurityManager();
+ assertNotNull(secMan);
+
+ val subject = SecurityUtils.getSubject();
+ assertNotNull(subject);
+ assertFalse(subject.isAuthenticated());
+
+ val token = (AuthenticationToken) new UsernamePasswordToken(
+ "non-existent-user",
+ "pass");
+
+ assertThrows(Exception.class, ()->{
+ subject.login(token);
+ });
+
+ assertFalse(subject.isAuthenticated());
+
}
+
}
diff --git a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroSimpleTest.java b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
similarity index 98%
rename from examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroSimpleTest.java
rename to examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
index 072f79d..d6a3755 100644
--- a/examples/smoketest/src/test/java/org/apache/isis/testsecurity/shiro/ShiroSimpleTest.java
+++ b/examples/smoketest/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.testsecurity.shiro;
+package org.apache.isis.testdomain.shiro;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;