Search in sources :

Example 6 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class Restore method setAdminCredentials.

private void setAdminCredentials(final DBBroker broker, final String adminPassword) throws EXistException, PermissionDeniedException {
    final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
    final Account dba = securityManager.getAccount(SecurityManager.DBA_USER);
    if (dba == null) {
        throw new EXistException("'" + SecurityManager.DBA_USER + "' account can't be found.");
    }
    dba.setCredential(new Password(dba, adminPassword));
    securityManager.updateAccount(dba);
}
Also used : Account(org.exist.security.Account) SecurityManager(org.exist.security.SecurityManager) EXistException(org.exist.EXistException) Password(org.exist.security.internal.Password)

Example 7 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class DocumentView method viewDocument.

public void viewDocument() {
    try {
        if (// $NON-NLS-1$
        "XMLResource".equals(resource.getResourceType())) {
            setText((String) resource.getContent());
        } else {
            setText(new String((byte[]) resource.getContent()));
        }
        // lock the resource for editing
        final UserManagementService service = (UserManagementService) // $NON-NLS-1$ //$NON-NLS-2$
        client.current.getService("UserManagementService", "1.0");
        // $NON-NLS-1$
        final Account user = service.getAccount(properties.getProperty("user"));
        final String lockOwner = service.hasUserLock(resource);
        if (lockOwner != null) {
            if (JOptionPane.showConfirmDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.6") + lockOwner + // $NON-NLS-1$
            Messages.getString("DocumentView.7"), // $NON-NLS-1$
            Messages.getString("DocumentView.8"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                dispose();
                this.setCursor(Cursor.getDefaultCursor());
                return;
            }
        }
        try {
            service.lockResource(resource, user);
        } catch (final XMLDBException ex) {
            System.out.println(ex.getMessage());
            JOptionPane.showMessageDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.9"));
            setReadOnly();
        }
        setVisible(true);
    } catch (final XMLDBException ex) {
        // $NON-NLS-1$
        showErrorMessage(Messages.getString("DocumentView.10") + ex.getMessage(), ex);
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 8 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class ChownTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    if ((name == null) || (group == null)) {
        throw (new BuildException("Must specify user and group"));
    }
    try {
        final Account usr = service.getAccount(name);
        if (resource != null) {
            final Resource res = base.getResource(resource);
            service.chown(res, usr, group);
        } else {
            service.chown(usr, group);
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Account(org.exist.security.Account) Resource(org.xmldb.api.base.Resource) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 9 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class UserPasswordTask method execute.

@Override
public void execute() throws BuildException {
    super.execute();
    if (name == null) {
        throw (new BuildException("Must specify at least a user name"));
    }
    try {
        log("Looking up user " + name, Project.MSG_INFO);
        final Account usr = service.getAccount(name);
        if (usr != null) {
            log("Setting password for user " + name, Project.MSG_INFO);
            if (secret != null) {
                usr.setCredential(new Password(usr, secret));
                this.service.updateAccount(usr);
            }
        } else {
            final String msg = "user " + name + " not found";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) Password(org.exist.security.internal.Password)

Example 10 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class CreateCollectionsTest method setUp.

@Before
public void setUp() throws XMLDBException {
    // create a test collection
    final CollectionManagementService cms = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    final Collection test = cms.createCollection(TEST_COLLECTION);
    final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
    // change ownership to guest
    Account guest = ums.getAccount(GUEST_DB_USER);
    ums.chown(guest, guest.getPrimaryGroup());
    ums.chmod("rwxrwxrwx");
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection)

Aggregations

Account (org.exist.security.Account)60 PermissionDeniedException (org.exist.security.PermissionDeniedException)18 SecurityManager (org.exist.security.SecurityManager)17 EXistException (org.exist.EXistException)12 XMLDBException (org.xmldb.api.base.XMLDBException)11 Group (org.exist.security.Group)10 Collection (org.xmldb.api.base.Collection)10 AuthenticationException (org.exist.security.AuthenticationException)9 DBBroker (org.exist.storage.DBBroker)9 AbstractAccount (org.exist.security.AbstractAccount)7 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)7 Txn (org.exist.storage.txn.Txn)6 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 Subject (org.exist.security.Subject)5 UserAider (org.exist.security.internal.aider.UserAider)5 UserManagementService (org.exist.xmldb.UserManagementService)5 Permission (org.exist.security.Permission)4 XPathException (org.exist.xquery.XPathException)4 Before (org.junit.Before)4 Test (org.junit.Test)4