attach userprofile to session

This commit is contained in:
Jörg Prante 2024-04-17 18:41:55 +02:00
parent 3bf46413b1
commit e444bfca5a
5 changed files with 39 additions and 33 deletions

View file

@ -27,8 +27,6 @@ public class BaseUserProfile implements UserProfile {
private boolean isRemembered; private boolean isRemembered;
private boolean isLoggedIn;
public BaseUserProfile() { public BaseUserProfile() {
this.attributes = new BaseAttributes(); this.attributes = new BaseAttributes();
this.effectiveAttributes = new BaseAttributes(); this.effectiveAttributes = new BaseAttributes();
@ -38,15 +36,9 @@ public class BaseUserProfile implements UserProfile {
this.effectivePermissions = new ArrayList<>(); this.effectivePermissions = new ArrayList<>();
} }
@Override
public boolean isLoggedIn() {
return isLoggedIn;
}
@Override @Override
public void setUserId(String uid) { public void setUserId(String uid) {
this.uid = uid; this.uid = uid;
this.isLoggedIn = uid != null;
} }
@Override @Override
@ -94,17 +86,14 @@ public class BaseUserProfile implements UserProfile {
return effectiveRoles; return effectiveRoles;
} }
@Override
public boolean hasRole(String role) { public boolean hasRole(String role) {
return roles.contains(role); return roles.contains(role);
} }
@Override
public boolean hasEffectiveRole(String role) { public boolean hasEffectiveRole(String role) {
return effectiveRoles.contains(role); return effectiveRoles.contains(role);
} }
@Override
public boolean hasAccess(String requireAnyRole, String requireAllRoles) { public boolean hasAccess(String requireAnyRole, String requireAllRoles) {
boolean access = true; boolean access = true;
if (!requireAnyRole.isEmpty()) { if (!requireAnyRole.isEmpty()) {
@ -121,7 +110,6 @@ public class BaseUserProfile implements UserProfile {
return access; return access;
} }
@Override
public boolean hasAnyRole(String[] expectedRoles) { public boolean hasAnyRole(String[] expectedRoles) {
if (expectedRoles == null || expectedRoles.length == 0) { if (expectedRoles == null || expectedRoles.length == 0) {
return true; return true;
@ -134,7 +122,6 @@ public class BaseUserProfile implements UserProfile {
return false; return false;
} }
@Override
public boolean hasAnyEffectiveRole(String[] expectedRoles) { public boolean hasAnyEffectiveRole(String[] expectedRoles) {
if (expectedRoles == null || expectedRoles.length == 0) { if (expectedRoles == null || expectedRoles.length == 0) {
return true; return true;
@ -147,9 +134,8 @@ public class BaseUserProfile implements UserProfile {
return false; return false;
} }
@Override
public boolean hasAllRoles(String[] expectedRoles) { public boolean hasAllRoles(String[] expectedRoles) {
if (expectedRoles == null || expectedRoles.length == 0) { if (expectedRoles == null) {
return true; return true;
} }
for (String role : expectedRoles) { for (String role : expectedRoles) {
@ -160,9 +146,8 @@ public class BaseUserProfile implements UserProfile {
return true; return true;
} }
@Override
public boolean hasAllEffectiveRoles(String[] expectedRoles) { public boolean hasAllEffectiveRoles(String[] expectedRoles) {
if (expectedRoles == null || expectedRoles.length == 0) { if (expectedRoles == null) {
return true; return true;
} }
for (String role : expectedRoles) { for (String role : expectedRoles) {
@ -178,7 +163,6 @@ public class BaseUserProfile implements UserProfile {
permissions.add(permission); permissions.add(permission);
} }
@Override
public void removePermission(String permission) { public void removePermission(String permission) {
permissions.remove(permission); permissions.remove(permission);
} }
@ -189,12 +173,12 @@ public class BaseUserProfile implements UserProfile {
} }
@Override @Override
public Attributes attributes() { public Attributes getAttributes() {
return attributes; return attributes;
} }
@Override @Override
public Attributes effectiveAttributes() { public Attributes getEffectiveAttributes() {
return effectiveAttributes; return effectiveAttributes;
} }
@ -203,6 +187,10 @@ public class BaseUserProfile implements UserProfile {
return permissions; return permissions;
} }
@Override
public void addEffectivePermission(String permission) {
effectivePermissions.add(permission);
}
@Override @Override
public List<String> getEffectivePermissions() { public List<String> getEffectivePermissions() {
return effectivePermissions; return effectivePermissions;
@ -215,15 +203,13 @@ public class BaseUserProfile implements UserProfile {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "uid=" + uid +
sb.append("uid=").append(uid) ",roles=" + roles +
.append(",roles=").append(roles) ",permissons=" + permissions +
.append(",permissons=").append(permissions) ",attributes=" + attributes +
.append(",attributes=").append(attributes) ",euid=" + euid +
.append(",euid=").append(euid) ",eroles=" + effectiveRoles +
.append(",eroles=").append(effectiveRoles) ",epermissions=" + effectivePermissions +
.append(",epermissions=").append(effectivePermissions) ",eattributes=" + effectiveAttributes;
.append(",eattributes=").append(effectiveAttributes);
return sb.toString();
} }
} }

View file

@ -6,7 +6,7 @@ import org.xbib.net.GroupsProvider;
import org.xbib.net.SecurityRealm; import org.xbib.net.SecurityRealm;
import org.xbib.net.UsersProvider; import org.xbib.net.UsersProvider;
public class LdapRealm extends SecurityRealm { public class LdapRealm implements SecurityRealm {
private final String name; private final String name;
@ -24,9 +24,9 @@ public class LdapRealm extends SecurityRealm {
Map<String, LdapGroupMapping> groupMappings) { Map<String, LdapGroupMapping> groupMappings) {
this.name = name; this.name = name;
this.contextFactories = contextFactories; this.contextFactories = contextFactories;
this.authenticator = new LdapAuthenticator(contextFactories, userMappings);
this.usersProvider = new LdapUsersProvider(contextFactories, userMappings); this.usersProvider = new LdapUsersProvider(contextFactories, userMappings);
this.groupsProvider = new LdapGroupsProvider(contextFactories, userMappings, groupMappings); this.groupsProvider = new LdapGroupsProvider(contextFactories, userMappings, groupMappings);
this.authenticator = new LdapAuthenticator(contextFactories, userMappings);
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.xbib.datastructures.common.LRUCache; import org.xbib.datastructures.common.LRUCache;
import org.xbib.net.UserProfile;
public class BaseSession implements Session { public class BaseSession implements Session {
@ -30,6 +31,10 @@ public class BaseSession implements Session {
private boolean valid; private boolean valid;
private boolean authenticated;
private UserProfile userProfile;
public BaseSession(SessionListener sessionListener, public BaseSession(SessionListener sessionListener,
int cacheSize, int cacheSize,
String name, String name,
@ -90,6 +95,19 @@ public class BaseSession implements Session {
return Duration.between(lastModified, now).compareTo(lifetime) > 0; return Duration.between(lastModified, now).compareTo(lifetime) > 0;
} }
public void setUserProfile(UserProfile userProfile) {
this.userProfile = userProfile;
}
public UserProfile getUserProfile() {
return userProfile;
}
@Override
public boolean isAuthenticated() {
return userProfile != null && userProfile.getUserId() != null;
}
@Override @Override
public boolean hasPayload() { public boolean hasPayload() {
return !isEmpty() && return !isEmpty() &&

View file

@ -15,6 +15,8 @@ public interface Session extends Map<String, Object> {
boolean isExpired(); boolean isExpired();
boolean isAuthenticated();
boolean hasPayload(); boolean hasPayload();
Duration getAge(); Duration getAge();

View file

@ -6,7 +6,7 @@ dependencyResolutionManagement {
version('netty', '4.1.109.Final') version('netty', '4.1.109.Final')
version('netty-tcnative', '2.0.65.Final') version('netty-tcnative', '2.0.65.Final')
version('datastructures', '5.0.7') version('datastructures', '5.0.7')
version('net', '4.3.0') version('net', '4.4.0')
library('netty-codec-http2', 'io.netty', 'netty-codec-http2').versionRef('netty') library('netty-codec-http2', 'io.netty', 'netty-codec-http2').versionRef('netty')
library('netty-handler', 'io.netty', 'netty-handler').versionRef('netty') library('netty-handler', 'io.netty', 'netty-handler').versionRef('netty')
library('netty-handler-proxy', 'io.netty', 'netty-handler-proxy').versionRef('netty') library('netty-handler-proxy', 'io.netty', 'netty-handler-proxy').versionRef('netty')