mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 04:35:32 +00:00
fix for bug 4883: principal collection now stored such that principal/user name may contain any characters
Change-Id: Ifb32acd377fcfdb137f7092958309bf88d1b0017
This commit is contained in:
+4
-4
@@ -45,11 +45,11 @@ public class SessionPersistenceTest {
|
||||
final String attr2Key = "a2";
|
||||
final boolean attr2Value = true;
|
||||
final String realm1Name = "realm1";
|
||||
final String realm1Principal1Name = "r1p1";
|
||||
final String realm1Principal2Name = "r1p2";
|
||||
final String realm1Principal1Name = "r1.p1";
|
||||
final String realm1Principal2Name = "r1/\",,p2";
|
||||
final String realm2Name = "realm2";
|
||||
final String realm2Principal1Name = "r2p1";
|
||||
final String realm2Principal2Name = "r2p2";
|
||||
final String realm2Principal1Name = "r2\\p1";
|
||||
final String realm2Principal2Name = "r2.'_p2";
|
||||
final String principalAttribute = "org.apache.shiro.subject.support.DefaultSubjectContext_PRINCIPALS_SESSION_KEY";
|
||||
final SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
|
||||
principalCollection.add(realm1Principal1Name, realm1Name);
|
||||
|
||||
+5
-2
@@ -61,9 +61,12 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
final Iterable<Document> sessionAttributes = sessionDocument.get(FieldNames.SESSION_ATTRIBUTES.name(), Iterable.class);
|
||||
for (final Document sessionAttributeDocument : sessionAttributes) {
|
||||
final Object value = sessionAttributeDocument.get(FieldNames.SESSION_ATTRIBUTE_VALUE.name());
|
||||
if (value instanceof Document) { // assume this encodes a PrincipalCollection
|
||||
if (value instanceof Iterable<?>) { // assume this encodes a PrincipalCollection in the form of a list of Document objects with
|
||||
// a realm name and a principal list, each:
|
||||
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
|
||||
((Document) value).forEach((realmName, principalList)->{
|
||||
((Iterable<?>) value).forEach(realmDocument->{
|
||||
final String realmName = ((Document) realmDocument).getString(FieldNames.SESSION_PRINCIPAL_REALM_NAME.name());
|
||||
final Iterable<?> principalList = (Iterable<?>) ((Document) realmDocument).get(FieldNames.SESSION_PRINCIPAL_REALM_VALUE.name());
|
||||
for (final Object principal : (Iterable<?>) principalList) {
|
||||
principalCollection.add(principal, realmName);
|
||||
}
|
||||
|
||||
+2
-1
@@ -4,5 +4,6 @@ public enum FieldNames {
|
||||
CACHE_NAME,
|
||||
|
||||
SESSION_ID, SESSION_HOST, SESSION_LAST_ACCESS_TIME, SESSION_START_TIMESTAMP, SESSION_TIMEOUT,
|
||||
SESSION_ATTRIBUTES, SESSION_ATTRIBUTE_NAME, SESSION_ATTRIBUTE_VALUE;
|
||||
SESSION_ATTRIBUTES, SESSION_ATTRIBUTE_NAME, SESSION_ATTRIBUTE_VALUE, SESSION_PRINCIPAL_REALM_NAME,
|
||||
SESSION_PRINCIPAL_REALM_VALUE;
|
||||
}
|
||||
|
||||
+6
-3
@@ -69,14 +69,17 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
sessionCollection.replaceOne(key, sessionAsDocument, new UpdateOptions().upsert(true));
|
||||
}
|
||||
|
||||
private Document storePrincipalCollection(PrincipalCollection principalCollection) {
|
||||
final Document result = new Document();
|
||||
private List<Document> storePrincipalCollection(PrincipalCollection principalCollection) {
|
||||
final List<Document> result = new ArrayList<>();
|
||||
for (final String realmName : principalCollection.getRealmNames()) {
|
||||
final List<String> principalNames = new ArrayList<>();
|
||||
for (Object o : principalCollection.fromRealm(realmName)) {
|
||||
principalNames.add(o.toString());
|
||||
}
|
||||
result.append(realmName, principalNames);
|
||||
final Document realmDocument = new Document().
|
||||
append(FieldNames.SESSION_PRINCIPAL_REALM_NAME.name(), realmName).
|
||||
append(FieldNames.SESSION_PRINCIPAL_REALM_VALUE.name(), principalNames);
|
||||
result.add(realmDocument);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user