freactoring to get company list work in efficient way
This commit is contained in:
@@ -16,8 +16,8 @@ import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.user.Constants.*;
|
||||
import static de.srsoftware.umbrella.user.Paths.*;
|
||||
import static de.srsoftware.umbrella.user.Paths.IMPERSONATE;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION.*;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission.*;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission;
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.net.HttpURLConnection.*;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@@ -396,7 +396,7 @@ public class UserModule extends BaseHandler implements UserService {
|
||||
private boolean impersonate(HttpExchange ex, Long targetId) throws IOException, UmbrellaException {
|
||||
var requestingUser = loadUser(ex);
|
||||
if (!(requestingUser.isPresent() && requestingUser.get() instanceof DbUser dbUser)) return unauthorized(ex);
|
||||
if (!dbUser.permissions().contains(PERMISSION.IMPERSONATE)) throw forbidden("You are not allowed to impersonate other users!");
|
||||
if (!dbUser.permissions().contains(Permission.IMPERSONATE)) throw forbidden("You are not allowed to impersonate other users!");
|
||||
if (targetId == null) return sendContent(ex,HTTP_UNPROCESSABLE,"user id missing");
|
||||
var targetUser = loadUser(targetId);
|
||||
users.getSession(targetUser).cookie().addTo(ex);
|
||||
@@ -456,7 +456,7 @@ public class UserModule extends BaseHandler implements UserService {
|
||||
private boolean postCreate(HttpExchange ex) throws IOException, UmbrellaException {
|
||||
var optUser = loadUser(ex);
|
||||
if (!(optUser.isPresent() && optUser.get() instanceof DbUser dbUser)) return unauthorized(ex);
|
||||
if (!dbUser.permissions().contains(PERMISSION.CREATE_USERS)) throw forbidden("You are not allowed to create new users!");
|
||||
if (!dbUser.permissions().contains(Permission.CREATE_USERS)) throw forbidden("You are not allowed to create new users!");
|
||||
var json = json(ex);
|
||||
|
||||
if (json.has(USER)) json = json.getJSONObject(USER);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
package de.srsoftware.umbrella.user.model;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION.*;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION.IMPERSONATE;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION.LIST_USERS;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.PERMISSION.MANAGE_LOGIN_SERVICES;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission.*;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission.IMPERSONATE;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission.LIST_USERS;
|
||||
import static de.srsoftware.umbrella.user.model.DbUser.Permission.MANAGE_LOGIN_SERVICES;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.EmailAddress;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
@@ -14,7 +14,7 @@ import java.util.Set;
|
||||
|
||||
public class DbUser extends UmbrellaUser {
|
||||
|
||||
public enum PERMISSION {
|
||||
public enum Permission {
|
||||
CREATE_USERS,
|
||||
UPDATE_USERS,
|
||||
DELETE_USERS,
|
||||
@@ -23,13 +23,13 @@ public class DbUser extends UmbrellaUser {
|
||||
MANAGE_LOGIN_SERVICES
|
||||
}
|
||||
|
||||
public static Set<PERMISSION> ADMIN_PERMISSIONS = Set.of(CREATE_USERS, UPDATE_USERS, DELETE_USERS, IMPERSONATE, MANAGE_LOGIN_SERVICES,LIST_USERS);
|
||||
public static Set<Permission> ADMIN_PERMISSIONS = Set.of(CREATE_USERS, UPDATE_USERS, DELETE_USERS, IMPERSONATE, MANAGE_LOGIN_SERVICES,LIST_USERS);
|
||||
|
||||
private final Set<PERMISSION> permissions;
|
||||
private final Set<Permission> permissions;
|
||||
private final Password hashedPass;
|
||||
private final Long lastLogoff;
|
||||
|
||||
public DbUser(long id, String name, EmailAddress email, Password hashedPassword, String theme, String languageCode, Set<PERMISSION> permissions, Long lastLogoff) {
|
||||
public DbUser(long id, String name, EmailAddress email, Password hashedPassword, String theme, String languageCode, Set<Permission> permissions, Long lastLogoff) {
|
||||
super(id, name, email, theme, languageCode);
|
||||
this.hashedPass = hashedPassword;
|
||||
this.permissions = permissions;
|
||||
@@ -44,11 +44,11 @@ public class DbUser extends UmbrellaUser {
|
||||
return lastLogoff;
|
||||
}
|
||||
|
||||
public boolean may(PERMISSION permission){
|
||||
public boolean may(Permission permission){
|
||||
return permissions.contains(permission);
|
||||
}
|
||||
|
||||
public Set<PERMISSION> permissions() {
|
||||
public Set<Permission> permissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
|
||||
@@ -524,7 +524,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
|
||||
private DbUser toUser(ResultSet rs) throws SQLException, UmbrellaException {
|
||||
long id = rs.getLong(ID);
|
||||
Set<DbUser.PERMISSION> perms = id == 1 ? ADMIN_PERMISSIONS : Set.of();
|
||||
Set<DbUser.Permission> perms = id == 1 ? ADMIN_PERMISSIONS : Set.of();
|
||||
return new DbUser(
|
||||
id,
|
||||
rs.getString(LOGIN),
|
||||
|
||||
Reference in New Issue
Block a user