Skip to content

Commit

Permalink
Merge branch 'work/using-react-with-bootstrap4'
Browse files Browse the repository at this point in the history
  • Loading branch information
steinarb committed May 31, 2024
2 parents ddd8ada + 80f8699 commit 4742447
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 74 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>no.priv.bang.pom</groupId>
<artifactId>bang-authservice-client-pom</artifactId>
<version>1.1.50</version>
<version>2.0.0</version>
</parent>
<groupId>no.priv.bang.ukelonn</groupId>
<artifactId>ukelonn</artifactId>
Expand Down
11 changes: 0 additions & 11 deletions ukelonn.backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,6 @@
<artifactId>shiro-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -746,10 +746,10 @@ private void addRolesIfNotPresent() {

Optional<Role> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions ukelonn.services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@
<artifactId>jackson-annotations</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions ukelonn.testutils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
<artifactId>service-mocks</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 0 additions & 5 deletions ukelonn.web.security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@
<artifactId>service-mocks</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion ukelonn.web.security/src/main/resources/shiro.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[main]
shiro.loginUrl = /login
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /login
shiro.unauthorizedUrl = /unauthorized

Expand Down
11 changes: 0 additions & 11 deletions ukelonn.web.services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<User> 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");
}
}
Expand All @@ -82,18 +82,18 @@ public List<User> 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);

Expand Down Expand Up @@ -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
Expand All @@ -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()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<User>>() {});
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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4742447

Please sign in to comment.