From bfb06f0065ed882cd6c6f33f8353b92ea7a1e3b3 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 5 May 2024 13:02:59 +0200 Subject: [PATCH 1/6] Remove immutable runtime dependencies for the second time --- ukelonn.web.services/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ukelonn.web.services/pom.xml b/ukelonn.web.services/pom.xml index d9393cb4..6e670de9 100644 --- a/ukelonn.web.services/pom.xml +++ b/ukelonn.web.services/pom.xml @@ -86,12 +86,6 @@ beans.immutable provided - - no.priv.bang.beans - beans.immutable - xml - features - org.apache.commons commons-lang3 From 7c772ff49870510e390d5c378a618091a78f16f6 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Tue, 7 May 2024 21:53:14 +0200 Subject: [PATCH 2/6] Upgrade parent to get shiro 2.0.1 and UserService 2.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0b9f762b..a7a71930 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ no.priv.bang.pom bang-authservice-client-pom - 1.1.50 + 2.0.0 no.priv.bang.ukelonn ukelonn From 6ee612e46a69163a308bb181daaaa3c433931281 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Tue, 7 May 2024 22:16:17 +0200 Subject: [PATCH 3/6] Adapt from bean getters to the record methods used in UserService 2.0.0 --- .../backend/UkelonnServiceProvider.java | 8 ++++---- .../backend/UkelonnServiceProviderTest.java | 12 ++++++------ .../api/resources/AdminUserResource.java | 18 +++++++++--------- .../ukelonn/api/UkelonnRestApiServletTest.java | 16 ++++++++-------- .../api/resources/AdminUserResourceTest.java | 16 ++++++++-------- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/UkelonnServiceProvider.java b/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/UkelonnServiceProvider.java index d430534f..fa040130 100644 --- a/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/UkelonnServiceProvider.java +++ b/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/UkelonnServiceProvider.java @@ -724,8 +724,8 @@ public Account mapAccount(ResultSet results) throws SQLException { return Account.with() .accountid(results.getInt("account_id")) .username(username) - .firstName(user.getFirstname()) - .lastName(user.getLastname()) + .firstName(user.firstname()) + .lastName(user.lastname()) .balance(results.getDouble("balance")) .build(); } catch (AuthserviceException e) { @@ -746,10 +746,10 @@ private void addRolesIfNotPresent() { Optional addRoleIfNotPresent(String rolename, String description) { var roles = useradmin.getRoles(); - var existingRole = roles.stream().filter(r -> rolename.equals(r.getRolename())).findFirst(); + var existingRole = roles.stream().filter(r -> rolename.equals(r.rolename())).findFirst(); if (!existingRole.isPresent()) { roles = useradmin.addRole(Role.with().rolename(rolename).description(description).build()); - return roles.stream().filter(r -> rolename.equals(r.getRolename())).findFirst(); + return roles.stream().filter(r -> rolename.equals(r.rolename())).findFirst(); } return existingRole; diff --git a/ukelonn.backend/src/test/java/no/priv/bang/ukelonn/backend/UkelonnServiceProviderTest.java b/ukelonn.backend/src/test/java/no/priv/bang/ukelonn/backend/UkelonnServiceProviderTest.java index 672ca06b..de2b2bce 100644 --- a/ukelonn.backend/src/test/java/no/priv/bang/ukelonn/backend/UkelonnServiceProviderTest.java +++ b/ukelonn.backend/src/test/java/no/priv/bang/ukelonn/backend/UkelonnServiceProviderTest.java @@ -285,11 +285,11 @@ void testAddAccount() { // Create a user in the database, and retrieve it (to get the user id) var updatedUsers = usermanagement.addUser(passwords); - var createdUser = updatedUsers.stream().filter(u -> newUsername.equals(u.getUsername())).findFirst().get(); + var createdUser = updatedUsers.stream().filter(u -> newUsername.equals(u.username())).findFirst().get(); // Add a new account to the database var userWithUserId = User.with() - .userId(createdUser.getUserid()) + .userId(createdUser.userid()) .username(newUsername) .email(newEmailaddress) .firstname(newFirstname) @@ -333,11 +333,11 @@ void testAddAccountWhenSqlExceptionIsThrown() throws Exception { var passwords = UserAndPasswords.with().user(user).password1("zecret").password2("zecret").build(); // Create a user in the database, and retrieve it (to get the user id) var updatedUsers = usermanagement.addUser(passwords); - var createdUser = updatedUsers.stream().filter(u -> newUsername.equals(u.getUsername())).findFirst().get(); + var createdUser = updatedUsers.stream().filter(u -> newUsername.equals(u.username())).findFirst().get(); // Add a new account to the database and expect to fail var userWithUserId = User.with() - .userId(createdUser.getUserid()) + .userId(createdUser.userid()) .username(newUsername) .email(newEmailaddress) .firstname(newFirstname) @@ -1514,7 +1514,7 @@ void testAddRoleIfNotPresentWhenRoleIsPresent() { var role = ukelonn.addRoleIfNotPresent(UKELONNADMIN_ROLE, "Administrator av applikasjonen ukelonn"); assertThat(role).isNotEmpty(); - assertEquals(UKELONNADMIN_ROLE, role.get().getRolename()); + assertEquals(UKELONNADMIN_ROLE, role.get().rolename()); } @Test @@ -1529,7 +1529,7 @@ void testAddRoleIfNotPresentWhenRoleIsNotPresent() { var role = ukelonn.addRoleIfNotPresent(UKELONNADMIN_ROLE, "Administrator av applikasjonen ukelonn"); assertThat(role).isNotEmpty(); - assertEquals(UKELONNADMIN_ROLE, role.get().getRolename()); + assertEquals(UKELONNADMIN_ROLE, role.get().rolename()); } @Test diff --git a/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/resources/AdminUserResource.java b/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/resources/AdminUserResource.java index 48a0c433..a1b06942 100644 --- a/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/resources/AdminUserResource.java +++ b/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/resources/AdminUserResource.java @@ -69,7 +69,7 @@ public List modify(User user) { try { return useradmin.modifyUser(user); } catch (AuthserviceException e) { - logger.error(String.format("REST endpoint /ukelonn/api/admin/user/modify failed to modify user %d", user.getUserid())); + logger.error(String.format("REST endpoint /ukelonn/api/admin/user/modify failed to modify user %d", user.userid())); throw new InternalServerErrorException("See log for details"); } } @@ -82,18 +82,18 @@ public List create(UserAndPasswords passwords) { var users = useradmin.addUser(passwords); // Create an account with a balance for the new user - var username = passwords.getUser().getUsername(); - var createdUser = users.stream().filter(u -> username.equals(u.getUsername())).findFirst(); + var username = passwords.user().username(); + var createdUser = users.stream().filter(u -> username.equals(u.username())).findFirst(); if (!createdUser.isPresent()) { throw new UkelonnException(String.format("Found no user matching %s in the users table", username)); } var user = no.priv.bang.ukelonn.beans.User.with() - .userId(createdUser.get().getUserid()) + .userId(createdUser.get().userid()) .username(username) - .email(createdUser.get().getEmail()) - .firstname(createdUser.get().getFirstname()) - .lastname(createdUser.get().getLastname()) + .email(createdUser.get().email()) + .firstname(createdUser.get().firstname()) + .lastname(createdUser.get().lastname()) .build(); ukelonn.addAccount(user); @@ -138,7 +138,7 @@ public AdminStatus adminStatus(User user) { @Consumes(MediaType.APPLICATION_JSON) public AdminStatus changeAdminStatus(AdminStatus status) { if (status.administrator() != userIsAdministrator(status.user())) { - var ukelonnadmin = useradmin.getRoles().stream().filter(r -> UKELONNADMIN_ROLE.equals(r.getRolename())).findFirst(); + var ukelonnadmin = useradmin.getRoles().stream().filter(r -> UKELONNADMIN_ROLE.equals(r.rolename())).findFirst(); if (!ukelonnadmin.isPresent()) { // If no ukelonn admin role is present in the auth service // administrator will always be false @@ -164,7 +164,7 @@ public AdminStatus changeAdminStatus(AdminStatus status) { } boolean userIsAdministrator(User user) { - return useradmin.getRolesForUser(user.getUsername()).stream().anyMatch(r -> UKELONNADMIN_ROLE.equals(r.getRolename())); + return useradmin.getRolesForUser(user.username()).stream().anyMatch(r -> UKELONNADMIN_ROLE.equals(r.rolename())); } } diff --git a/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/UkelonnRestApiServletTest.java b/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/UkelonnRestApiServletTest.java index 81337777..031427ed 100644 --- a/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/UkelonnRestApiServletTest.java +++ b/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/UkelonnRestApiServletTest.java @@ -1287,10 +1287,10 @@ void testModifyUser() throws Exception { // Verify that the first user has the modified values var updatedUsers = mapper.readValue(getBinaryContent(response), new TypeReference>() {}); var firstUser = updatedUsers.get(userToModify); - assertEquals(modifiedUsername, firstUser.getUsername()); - assertEquals(modifiedEmailaddress, firstUser.getEmail()); - assertEquals(modifiedFirstname, firstUser.getFirstname()); - assertEquals(modifiedLastname, firstUser.getLastname()); + assertEquals(modifiedUsername, firstUser.username()); + assertEquals(modifiedEmailaddress, firstUser.email()); + assertEquals(modifiedFirstname, firstUser.firstname()); + assertEquals(modifiedLastname, firstUser.lastname()); } @Test @@ -1347,10 +1347,10 @@ void testCreateUser() throws Exception { // Verify that the last user has the expected values assertThat(updatedUsers).hasSizeGreaterThan(originalUserCount); var lastUser = updatedUsers.get(updatedUsers.size() - 1); - assertEquals(newUsername, lastUser.getUsername()); - assertEquals(newEmailaddress, lastUser.getEmail()); - assertEquals(newFirstname, lastUser.getFirstname()); - assertEquals(newLastname, lastUser.getLastname()); + assertEquals(newUsername, lastUser.username()); + assertEquals(newEmailaddress, lastUser.email()); + assertEquals(newFirstname, lastUser.firstname()); + assertEquals(newLastname, lastUser.lastname()); } @Test diff --git a/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/resources/AdminUserResourceTest.java b/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/resources/AdminUserResourceTest.java index 88ba18d7..7364310d 100644 --- a/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/resources/AdminUserResourceTest.java +++ b/ukelonn.web.services/src/test/java/no/priv/bang/ukelonn/api/resources/AdminUserResourceTest.java @@ -78,10 +78,10 @@ void testModify() { // Verify that the first user has the modified values var firstUser = updatedUsers.get(0); - assertEquals(modifiedUsername, firstUser.getUsername()); - assertEquals(modifiedEmailaddress, firstUser.getEmail()); - assertEquals(modifiedFirstname, firstUser.getFirstname()); - assertEquals(modifiedLastname, firstUser.getLastname()); + assertEquals(modifiedUsername, firstUser.username()); + assertEquals(modifiedEmailaddress, firstUser.email()); + assertEquals(modifiedFirstname, firstUser.firstname()); + assertEquals(modifiedLastname, firstUser.lastname()); } @Test @@ -157,10 +157,10 @@ void testCreate() { // Verify that the modified user has the modified values assertThat(updatedUsers).hasSizeGreaterThan(originalUserCount); var lastUser = updatedUsers.get(updatedUsers.size() - 1); - assertEquals(newUsername, lastUser.getUsername()); - assertEquals(newEmailaddress, lastUser.getEmail()); - assertEquals(newFirstname, lastUser.getFirstname()); - assertEquals(newLastname, lastUser.getLastname()); + assertEquals(newUsername, lastUser.username()); + assertEquals(newEmailaddress, lastUser.email()); + assertEquals(newFirstname, lastUser.firstname()); + assertEquals(newLastname, lastUser.lastname()); } @Test From e691c282701f7fa86120212328bac8519ba18b71 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Tue, 7 May 2024 22:22:13 +0200 Subject: [PATCH 4/6] Remove beans.immutable as compile and runtime dependencies since all beans are now records --- ukelonn.backend/pom.xml | 11 ----------- ukelonn.services/pom.xml | 5 ----- ukelonn.testutils/pom.xml | 4 ---- ukelonn.web.security/pom.xml | 5 ----- ukelonn.web.services/pom.xml | 5 ----- 5 files changed, 30 deletions(-) diff --git a/ukelonn.backend/pom.xml b/ukelonn.backend/pom.xml index 6f3119fc..8d13a30f 100644 --- a/ukelonn.backend/pom.xml +++ b/ukelonn.backend/pom.xml @@ -146,17 +146,6 @@ shiro-core provided - - no.priv.bang.beans - beans.immutable - provided - - - no.priv.bang.beans - beans.immutable - xml - features - org.apache.commons commons-lang3 diff --git a/ukelonn.services/pom.xml b/ukelonn.services/pom.xml index 3c973a49..8693a24e 100644 --- a/ukelonn.services/pom.xml +++ b/ukelonn.services/pom.xml @@ -66,11 +66,6 @@ jackson-annotations compile - - no.priv.bang.beans - beans.immutable - provided - org.apache.commons commons-lang3 diff --git a/ukelonn.testutils/pom.xml b/ukelonn.testutils/pom.xml index 037872fd..58bf95ee 100644 --- a/ukelonn.testutils/pom.xml +++ b/ukelonn.testutils/pom.xml @@ -76,10 +76,6 @@ service-mocks compile - - no.priv.bang.beans - beans.immutable - diff --git a/ukelonn.web.security/pom.xml b/ukelonn.web.security/pom.xml index d07e4b2a..119546ff 100644 --- a/ukelonn.web.security/pom.xml +++ b/ukelonn.web.security/pom.xml @@ -114,11 +114,6 @@ service-mocks test - - no.priv.bang.beans - beans.immutable - test - org.ops4j.pax.web pax-web-api diff --git a/ukelonn.web.services/pom.xml b/ukelonn.web.services/pom.xml index 6e670de9..74fb9e78 100644 --- a/ukelonn.web.services/pom.xml +++ b/ukelonn.web.services/pom.xml @@ -81,11 +81,6 @@ org.osgi.service.component.annotations provided - - no.priv.bang.beans - beans.immutable - provided - org.apache.commons commons-lang3 From bcb537ec8379f5107bcd7e4f9e38b49b27dd7996 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Wed, 22 May 2024 19:17:36 +0200 Subject: [PATCH 5/6] Use ByteSource.Util package location for shiro 2.0.1 --- .../bang/ukelonn/db/liquibase/test/TestLiquibaseRunnerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ukelonn.db.liquibase.test/src/test/java/no/priv/bang/ukelonn/db/liquibase/test/TestLiquibaseRunnerTest.java b/ukelonn.db.liquibase.test/src/test/java/no/priv/bang/ukelonn/db/liquibase/test/TestLiquibaseRunnerTest.java index 073d58f3..a9c1a74e 100644 --- a/ukelonn.db.liquibase.test/src/test/java/no/priv/bang/ukelonn/db/liquibase/test/TestLiquibaseRunnerTest.java +++ b/ukelonn.db.liquibase.test/src/test/java/no/priv/bang/ukelonn/db/liquibase/test/TestLiquibaseRunnerTest.java @@ -34,7 +34,7 @@ import org.apache.shiro.authc.credential.HashedCredentialsMatcher; import org.apache.shiro.crypto.SecureRandomNumberGenerator; import org.apache.shiro.crypto.hash.Sha256Hash; -import org.apache.shiro.util.ByteSource.Util; +import org.apache.shiro.lang.util.ByteSource.Util; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; From 6e039a3b5671dc25577113a7d6c28e837e1601a7 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 26 May 2024 09:31:04 +0200 Subject: [PATCH 6/6] Manually create PassThruAuthenticationFilter because the shiro 2.x INI parser can't find and create it when running in OSGi --- .../no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java | 2 ++ ukelonn.web.security/src/main/resources/shiro.ini | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java b/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java index d2980bcd..6ef65f76 100644 --- a/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java +++ b/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java @@ -21,6 +21,7 @@ import org.apache.shiro.realm.Realm; import org.apache.shiro.session.mgt.eis.SessionDAO; import org.apache.shiro.web.env.IniWebEnvironment; +import org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.servlet.AbstractShiroFilter; import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; @@ -66,6 +67,7 @@ public void setSession(SessionDAO session) { @Activate public void activate() { var environment = new IniWebEnvironment(); + environment.getObjects().put("authc", new PassThruAuthenticationFilter()); environment.setIni(INI_FILE); environment.setServletContext(getServletContext()); environment.init(); diff --git a/ukelonn.web.security/src/main/resources/shiro.ini b/ukelonn.web.security/src/main/resources/shiro.ini index 51f5a927..7a73a8f2 100644 --- a/ukelonn.web.security/src/main/resources/shiro.ini +++ b/ukelonn.web.security/src/main/resources/shiro.ini @@ -1,6 +1,5 @@ [main] shiro.loginUrl = /login -authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter authc.loginUrl = /login shiro.unauthorizedUrl = /unauthorized