This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch jpa-SNAPSHOT
in repository https://gitbox.apache.org/repos/asf/causeway-app-helloworld.git


The following commit(s) were added to refs/heads/jpa-SNAPSHOT by this push:
     new 0bb6726  replace security-shiro with security-simple
0bb6726 is described below

commit 0bb67263a44046f21538d447a8074bee4e363acf
Author: Andi Huber <[email protected]>
AuthorDate: Thu Mar 21 12:58:18 2024 +0100

    replace security-shiro with security-simple
---
 pom.xml                                         |  2 +-
 src/main/java/domainapp/webapp/AppManifest.java | 41 ++++++++++++++++++++-
 src/main/resources/shiro.ini                    | 49 -------------------------
 3 files changed, 40 insertions(+), 52 deletions(-)

diff --git a/pom.xml b/pom.xml
index cad7745..672ecc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,7 +88,7 @@
 
         <dependency>
             <groupId>org.apache.causeway.security</groupId>
-            <artifactId>causeway-security-shiro</artifactId>
+            <artifactId>causeway-security-simple</artifactId>
         </dependency>
 
         <dependency>
diff --git a/src/main/java/domainapp/webapp/AppManifest.java 
b/src/main/java/domainapp/webapp/AppManifest.java
index 1ad5341..3d274c7 100644
--- a/src/main/java/domainapp/webapp/AppManifest.java
+++ b/src/main/java/domainapp/webapp/AppManifest.java
@@ -1,16 +1,22 @@
 package domainapp.webapp;
 
+import java.util.List;
+
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 import org.springframework.context.annotation.PropertySource;
 import org.springframework.context.annotation.PropertySources;
+import org.springframework.security.crypto.password.PasswordEncoder;
 
 import 
org.apache.causeway.applib.CausewayModuleApplibChangeAndExecutionLoggers;
 import org.apache.causeway.applib.CausewayModuleApplibMixins;
 import org.apache.causeway.core.config.presets.CausewayPresets;
 import 
org.apache.causeway.core.runtimeservices.CausewayModuleCoreRuntimeServices;
 import 
org.apache.causeway.persistence.jpa.eclipselink.CausewayModulePersistenceJpaEclipselink;
-import org.apache.causeway.security.shiro.CausewayModuleSecurityShiro;
+import org.apache.causeway.security.simple.CausewayModuleSecuritySimple;
+import org.apache.causeway.security.simple.realm.SimpleRealm;
+import org.apache.causeway.security.simple.realm.SimpleRealm.Grant;
 import 
org.apache.causeway.testing.h2console.ui.CausewayModuleTestingH2ConsoleUi;
 import 
org.apache.causeway.viewer.restfulobjects.jaxrsresteasy.CausewayModuleViewerRestfulObjectsJaxrsResteasy;
 import 
org.apache.causeway.viewer.wicket.applib.CausewayModuleViewerWicketApplibMixins;
@@ -24,7 +30,7 @@ import domainapp.modules.hello.HelloWorldModule;
         CausewayModuleApplibChangeAndExecutionLoggers.class,
 
         CausewayModuleCoreRuntimeServices.class,
-        CausewayModuleSecurityShiro.class,
+        CausewayModuleSecuritySimple.class,
         CausewayModulePersistenceJpaEclipselink.class,
         CausewayModuleViewerRestfulObjectsJaxrsResteasy.class,
         CausewayModuleViewerWicketApplibMixins.class,
@@ -37,4 +43,35 @@ import domainapp.modules.hello.HelloWorldModule;
     @PropertySource(CausewayPresets.NoTranslations),
 })
 public class AppManifest {
+
+    /**
+     * Sets up a simple in-memory authentication/authorization realm.
+     * <p>
+     * For production use you would perhaps replace the {@link 
CausewayModuleSecuritySimple}
+     * with a different CausewayModuleSecurityXxx integration.
+     */
+    @Bean
+    public SimpleRealm simpleAuthRealm(final PasswordEncoder passwordEncoder) {
+        var hashedPass = passwordEncoder.encode("pass");
+        return new SimpleRealm()
+            .addRole("admin_role", id->Grant.CHANGE)
+            .addRole("hello_role", id->
+                id.getFullIdentityString().contains("HelloWorldObject")
+                    ? Grant.CHANGE
+                    : Grant.NONE)
+            .addRole("default_role", id->
+                id.getFullIdentityString().startsWith("causeway.applib")
+                    || 
id.getFullIdentityString().startsWith("causeway.security")
+                    ? Grant.CHANGE
+                    : Grant.NONE)
+            .addRole("fixtures_role", id->
+                
id.getFullIdentityString().startsWith("causeway.testing.fixtures")
+                    ? Grant.CHANGE
+                    : Grant.NONE)
+            .addUser("sven", hashedPass, List.of("admin_role"))
+            .addUser("dick", hashedPass, List.of("hello_role", "default_role"))
+            .addUser("bob", hashedPass, List.of("hello_role", "default_role", 
"fixtures_role"))
+            .addUser("joe", hashedPass, List.of("hello_role", "default_role"));
+    }
+
 }
diff --git a/src/main/resources/shiro.ini b/src/main/resources/shiro.ini
deleted file mode 100644
index 30faa89..0000000
--- a/src/main/resources/shiro.ini
+++ /dev/null
@@ -1,49 +0,0 @@
-[main]
-
-# to use .ini file
-securityManager.realms = $iniRealm
-
-
-
-# -----------------------------------------------------------------------------
-# Users and their assigned roles
-#
-# Each line conforms to the format defined in the
-# org.apache.shiro.realm.text.TextConfigurationRealm#setUserDefinitions JavaDoc
-# -----------------------------------------------------------------------------
-
-[users]
-# user = password, role1, role2, role3, ...
-
-
-sven = pass, admin_role
-dick = pass, hello_role, default_role
-bob  = pass, hello_role, default_role, fixtures_role
-joe  = pass, hello_role, default_role
-
-
-
-# -----------------------------------------------------------------------------
-# Roles with assigned permissions
-#
-# Each line conforms to the format defined in the
-# org.apache.shiro.realm.text.TextConfigurationRealm#setRoleDefinitions JavaDoc
-# -----------------------------------------------------------------------------
-
-[roles]
-# role = perm1, perm2, perm3, ...
-# perm in format: logicalTypeNamespace:logicalTypeSimpleName:memberName:r,w
-
-hello_role =   *:HelloWorldObjects:*:*,\
-               *:HelloWorldObject:*:*
-admin_role = *
-default_role   = causeway.applib,\
-                 causeway.security
-fixtures_role  = causeway.testing.fixtures
-features_role  = causeway.feat
-metamodel_role = causeway.metamodel
-h2_role        = causeway.ext.h2Console
-jdo_role       = causeway.persistence.jdo
-swagger_role   = causeway.viewer.restfulobjects
-conf_role      = causeway.conf
-sudo_role      = causeway.sudo

Reply via email to