use of org.exist.config.Configuration in project exist by eXist-db.
the class AbstractPrincipal method setCollection.
public final void setCollection(DBBroker broker, Collection collection, XmldbURI uri) throws ConfigurationException {
if (collection != null) {
Configurator.unregister(configuration);
final Configuration _config_ = Configurator.parse(this, broker, collection, uri);
configuration = Configurator.configure(this, _config_);
}
}
use of org.exist.config.Configuration in project exist by eXist-db.
the class AbstractRealm method loadRemovedAccountsFromRealmStorage.
private void loadRemovedAccountsFromRealmStorage(final DBBroker broker) throws ConfigurationException, PermissionDeniedException, LockException {
// load marked for remove accounts information
if (collectionRemovedAccounts != null && collectionRemovedAccounts.getDocumentCount(broker) > 0) {
for (final Iterator<DocumentImpl> i = collectionRemovedAccounts.iterator(broker); i.hasNext(); ) {
final Configuration conf = Configurator.parse(broker.getBrokerPool(), i.next());
final Integer id = conf.getPropertyInteger("id");
if (id != null && !getSecurityManager().hasUser(id)) {
// A account = instantiateAccount(this, conf, true);
final AccountImpl account = new AccountImpl(this, conf);
account.removed = true;
getSecurityManager().registerAccount(account);
}
}
}
}
use of org.exist.config.Configuration in project exist by eXist-db.
the class SecurityManagerImpl method processParameter.
@Override
public void processParameter(final DBBroker broker, final DocumentImpl document) throws ConfigurationException {
XmldbURI uri = document.getCollection().getURI();
final boolean isRemoved = uri.endsWith(SecurityManager.REMOVED_COLLECTION_URI);
if (isRemoved) {
uri = uri.removeLastSegment();
}
final boolean isAccount = uri.endsWith(SecurityManager.ACCOUNTS_COLLECTION_URI);
final boolean isGroup = uri.endsWith(SecurityManager.GROUPS_COLLECTION_URI);
if (isAccount || isGroup) {
uri = uri.removeLastSegment();
final String realmId = uri.lastSegment().toString();
final AbstractRealm realm = (AbstractRealm) findRealmForRealmId(realmId);
final Configuration conf = Configurator.parse(broker.getBrokerPool(), document);
Integer id = -1;
if (isRemoved) {
id = conf.getPropertyInteger("id");
}
final String name = conf.getProperty("name");
if (isAccount) {
if (isRemoved && id > 2 && !hasUser(id)) {
final AccountImpl account = new AccountImpl(realm, conf);
account.removed = true;
registerAccount(account);
} else if (name != null) {
if (realm.hasAccount(name)) {
final Integer oldId = saving.get(document.getURI());
final Integer newId = conf.getPropertyInteger("id");
if (!newId.equals(oldId)) {
final Account current = realm.getAccount(name);
try (final ManagedLock<ReadWriteLock> lock = ManagedLock.acquire(accountLocks.getLock(current), LockMode.WRITE_LOCK)) {
usersById.write(principalDb -> {
principalDb.remove(oldId);
principalDb.put(newId, current);
});
}
}
} else {
final Account account = new AccountImpl(realm, conf);
if (account.getGroups().length == 0) {
try {
account.setPrimaryGroup(realm.getGroup(SecurityManager.UNKNOWN_GROUP));
LOG.warn("Account '{}' has no groups, but every account must have at least 1 group. Assigned group: " + SecurityManager.UNKNOWN_GROUP, account.getName());
} catch (final PermissionDeniedException e) {
throw new ConfigurationException("Account has no group, unable to default to " + SecurityManager.UNKNOWN_GROUP + ": " + e.getMessage(), e);
}
}
registerAccount(account);
realm.registerAccount(account);
}
} else {
// this can't be! log any way
LOG.error("Account '{}' already exists in realm: '{}', but received notification that a new one was created.", name, realmId);
}
} else if (isGroup) {
if (isRemoved && id > 2 && !hasGroup(id)) {
final GroupImpl group = new GroupImpl(realm, conf);
group.removed = true;
registerGroup(group);
} else if (name != null && !realm.hasGroup(name)) {
final GroupImpl group = new GroupImpl(realm, conf);
registerGroup(group);
realm.registerGroup(group);
} else {
// this can't be! log any way
LOG.error("Group '{}' already exists in realm: '{}', but received notification that a new one was created.", name, realmId);
}
}
saving.remove(document.getURI());
}
}
use of org.exist.config.Configuration in project exist by eXist-db.
the class ConfigurableTest method simple.
@Test
public void simple() throws Exception {
InputStream is = new UnsynchronizedByteArrayInputStream(config1.getBytes(UTF_8));
Configuration config = Configurator.parse(is);
ConfigurableObject object = new ConfigurableObject(config);
assertNotNull(object.subclasses);
assertEquals("A", object.subclasses.name);
assertEquals("1", object.subclasses.version);
assertEquals(1, object.subclasses.subconfs.size());
// XXX: assertEquals(2, object.subclasses.subconfs.size());
assertEquals("1", object.subclasses.subconfs.get(0).getKey());
assertEquals("secret1", object.subclasses.subconfs.get(0).getSecret());
// XXX: assertEquals("2", object.subclasses.subconfs.get(1).getKey());
// XXX: assertEquals("secret2", object.subclasses.subconfs.get(1).getSecret());
}
use of org.exist.config.Configuration in project exist by eXist-db.
the class ActiveDirectoryRealmTest method setUpBeforeClass.
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
InputStream is = new UnsynchronizedByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8));
Configuration config = Configurator.parse(is);
realm = new ActiveDirectoryRealm(null, config);
}
Aggregations