[New] PrivilegeContext.isRemoteUser() and others
This commit is contained in:
parent
e5eb130f99
commit
0eaf3b20fb
|
@ -32,8 +32,8 @@ import li.strolch.utils.helper.StringHelper;
|
|||
|
||||
/**
|
||||
* The {@link Certificate} is the object a client keeps when accessing a Privilege enabled system. This object is the
|
||||
* instance which is always used when performing an access and is returned when a user performs a login through {@link
|
||||
* PrivilegeHandler#authenticate(String, char[], boolean)}
|
||||
* instance which is always used when performing an access and is returned when a user performs a login through
|
||||
* {@link PrivilegeHandler#authenticate(String, char[], boolean)}
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
|
@ -134,6 +134,18 @@ public final class Certificate implements Serializable {
|
|||
this.lastAccess = ZonedDateTime.now();
|
||||
}
|
||||
|
||||
public boolean isSystemUser() {
|
||||
return this.userState.isSystem();
|
||||
}
|
||||
|
||||
public boolean isisRemoteUser() {
|
||||
return this.userState.isRemote();
|
||||
}
|
||||
|
||||
public boolean isNormalEnabledUser() {
|
||||
return this.userState.isNormalEnabledUser();
|
||||
}
|
||||
|
||||
public Usage getUsage() {
|
||||
return this.usage;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,18 @@ public class PrivilegeContext {
|
|||
this.policies = Map.copyOf(policies);
|
||||
}
|
||||
|
||||
public boolean isSystemUser() {
|
||||
return this.userRep.isSystemUser();
|
||||
}
|
||||
|
||||
public boolean isRemoteUser() {
|
||||
return this.userRep.isRemoteUser();
|
||||
}
|
||||
|
||||
public boolean isNormalEnabledUser() {
|
||||
return this.userRep.isNormalEnabledUser();
|
||||
}
|
||||
|
||||
public UserRep getUserRep() {
|
||||
return this.userRep;
|
||||
}
|
||||
|
@ -170,10 +182,8 @@ public class PrivilegeContext {
|
|||
String privilegeName = restrictable.getPrivilegeName();
|
||||
IPrivilege privilege = this.privileges.get(privilegeName);
|
||||
if (privilege == null) {
|
||||
String msg = MessageFormat
|
||||
.format(PrivilegeMessages.getString("Privilege.accessdenied.noprivilege"),
|
||||
getUsername(), privilegeName, restrictable.getClass().getName(),
|
||||
restrictable.getPrivilegeValue());
|
||||
String msg = MessageFormat.format(PrivilegeMessages.getString("Privilege.accessdenied.noprivilege"),
|
||||
getUsername(), privilegeName, restrictable.getClass().getName(), restrictable.getPrivilegeValue());
|
||||
throw new AccessDeniedException(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,9 +88,6 @@ public class UserRep implements Serializable {
|
|||
this.history = history;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private UserRep() {
|
||||
// No arg constructor for JAXB
|
||||
|
@ -109,8 +106,7 @@ public class UserRep implements Serializable {
|
|||
|
||||
// username must be at least 2 characters in length
|
||||
if (this.username.length() < 2) {
|
||||
String msg = MessageFormat
|
||||
.format("The given username ''{0}'' is shorter than 2 characters", this.username);
|
||||
String msg = MessageFormat.format("The given username ''{0}'' is shorter than 2 characters", this.username);
|
||||
throw new PrivilegeException(msg);
|
||||
}
|
||||
|
||||
|
@ -127,6 +123,18 @@ public class UserRep implements Serializable {
|
|||
throw new PrivilegeException("roles is null or empty");
|
||||
}
|
||||
|
||||
public boolean isSystemUser() {
|
||||
return this.userState.isSystem();
|
||||
}
|
||||
|
||||
public boolean isRemoteUser() {
|
||||
return this.userState.isRemote();
|
||||
}
|
||||
|
||||
public boolean isNormalEnabledUser() {
|
||||
return this.userState.isNormalEnabledUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userId
|
||||
*/
|
||||
|
|
|
@ -64,4 +64,8 @@ public enum UserState {
|
|||
public boolean isRemote() {
|
||||
return this == UserState.REMOTE;
|
||||
}
|
||||
|
||||
public boolean isNormalEnabledUser() {
|
||||
return this == UserState.ENABLED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue