[Fix] trim values in privilege handler when storing
This commit is contained in:
parent
bd51435bd1
commit
fcb0e1fdc0
|
@ -288,16 +288,16 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
boolean propertySelected;
|
||||
|
||||
// userId
|
||||
userIdSelected = selUserId == null || selUserId.equals(user.getUserId());
|
||||
userIdSelected = isEmpty(selUserId) || selUserId.equals(user.getUserId());
|
||||
|
||||
// username
|
||||
usernameSelected = selUsername == null || selUsername.equals(user.getUsername());
|
||||
usernameSelected = isEmpty(selUsername) || selUsername.equals(user.getUsername());
|
||||
|
||||
// firstname
|
||||
firstNameSelected = selFirstName == null || selFirstName.equals(user.getFirstname());
|
||||
firstNameSelected = isEmpty(selFirstName) || selFirstName.equals(user.getFirstname());
|
||||
|
||||
// lastname
|
||||
lastNameSelected = selLastName == null || selLastName.equals(user.getLastname());
|
||||
lastNameSelected = isEmpty(selLastName) || selLastName.equals(user.getLastname());
|
||||
|
||||
// user state
|
||||
userStateSelected = selUserState == null || selUserState.equals(user.getUserState());
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
*/
|
||||
package li.strolch.privilege.model;
|
||||
|
||||
import static li.strolch.utils.helper.StringHelper.trimOrEmpty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
import li.strolch.privilege.handler.PrivilegeHandler;
|
||||
|
@ -49,15 +52,15 @@ public class PrivilegeRep implements Serializable {
|
|||
* the {@link PrivilegePolicy} configured to evaluate if the privilege is granted
|
||||
* @param allAllowed
|
||||
* a boolean defining if a {@link Role} with this {@link IPrivilege} has unrestricted access to a {@link
|
||||
* Restrictable}
|
||||
* Restrictable}
|
||||
* @param denyList
|
||||
* a list of deny rules for this {@link IPrivilege}
|
||||
* @param allowList
|
||||
* a list of allow rules for this {@link IPrivilege}
|
||||
*/
|
||||
public PrivilegeRep(String name, String policy, boolean allAllowed, Set<String> denyList, Set<String> allowList) {
|
||||
this.name = name;
|
||||
this.policy = policy;
|
||||
this.name = trimOrEmpty(name);
|
||||
this.policy = trimOrEmpty(policy);
|
||||
this.allAllowed = allAllowed;
|
||||
this.denyList = denyList;
|
||||
this.allowList = allowList;
|
||||
|
@ -96,7 +99,7 @@ public class PrivilegeRep implements Serializable {
|
|||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.name = trimOrEmpty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,7 +114,7 @@ public class PrivilegeRep implements Serializable {
|
|||
* the policy to set
|
||||
*/
|
||||
public void setPolicy(String policy) {
|
||||
this.policy = policy;
|
||||
this.policy = trimOrEmpty(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +144,7 @@ public class PrivilegeRep implements Serializable {
|
|||
* the denyList to set
|
||||
*/
|
||||
public void setDenyList(Set<String> denyList) {
|
||||
this.denyList = denyList;
|
||||
this.denyList = denyList.stream().map(String::trim).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +159,7 @@ public class PrivilegeRep implements Serializable {
|
|||
* the allowList to set
|
||||
*/
|
||||
public void setAllowList(Set<String> allowList) {
|
||||
this.allowList = allowList;
|
||||
this.allowList = allowList.stream().map(String::trim).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package li.strolch.privilege.model;
|
||||
|
||||
import static li.strolch.utils.helper.StringHelper.trimOrEmpty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -45,7 +47,7 @@ public class RoleRep implements Serializable {
|
|||
* the list of privileges granted to this role
|
||||
*/
|
||||
public RoleRep(String name, List<PrivilegeRep> privileges) {
|
||||
this.name = name;
|
||||
this.name = trimOrEmpty(name);
|
||||
this.privileges = privileges;
|
||||
}
|
||||
|
||||
|
@ -81,7 +83,7 @@ public class RoleRep implements Serializable {
|
|||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.name = trimOrEmpty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
package li.strolch.privilege.model;
|
||||
|
||||
import static li.strolch.privilege.base.PrivilegeConstants.*;
|
||||
import static li.strolch.utils.helper.StringHelper.trimOrEmpty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeConstants;
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
|
@ -70,17 +72,19 @@ public class UserRep implements Serializable {
|
|||
*/
|
||||
public UserRep(String userId, String username, String firstname, String lastname, UserState userState,
|
||||
Set<String> roles, Locale locale, Map<String, String> propertyMap, UserHistory history) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.userId = trimOrEmpty(userId);
|
||||
this.username = trimOrEmpty(username);
|
||||
this.firstname = trimOrEmpty(firstname);
|
||||
this.lastname = trimOrEmpty(lastname);
|
||||
this.userState = userState;
|
||||
this.roles = roles;
|
||||
this.roles = roles == null ? null : roles.stream().map(String::trim).collect(Collectors.toSet());
|
||||
this.locale = locale;
|
||||
|
||||
if (propertyMap != null) {
|
||||
this.properties = new HashMap<>(propertyMap);
|
||||
this.properties.remove("");
|
||||
this.properties = new HashMap<>();
|
||||
propertyMap.forEach((key, value) -> {
|
||||
this.properties.put(key.trim(), value.trim());
|
||||
});
|
||||
}
|
||||
|
||||
this.history = history;
|
||||
|
@ -139,7 +143,7 @@ public class UserRep implements Serializable {
|
|||
* to set
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
this.userId = trimOrEmpty(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,7 +158,7 @@ public class UserRep implements Serializable {
|
|||
* the username to set
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
this.username = trimOrEmpty(username);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,7 +173,7 @@ public class UserRep implements Serializable {
|
|||
* the firstname to set
|
||||
*/
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
this.firstname = trimOrEmpty(firstname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,7 +188,7 @@ public class UserRep implements Serializable {
|
|||
* the lastname to set
|
||||
*/
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
this.lastname = trimOrEmpty(lastname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,7 +218,7 @@ public class UserRep implements Serializable {
|
|||
* the roles to set
|
||||
*/
|
||||
public void setRoles(Set<String> roles) {
|
||||
this.roles = roles;
|
||||
this.roles = roles.stream().map(String::trim).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,7 +284,7 @@ public class UserRep implements Serializable {
|
|||
public void setProperty(String key, String value) {
|
||||
if (this.properties == null)
|
||||
this.properties = new HashMap<>(1);
|
||||
this.properties.put(key, value);
|
||||
this.properties.put(key.trim(), value.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue