Package org.exist.security

Examples of org.exist.security.Subject


        BrokerPool pool = BrokerPool.getInstance();
        DBBroker broker = null;
        TransactionManager transact = null;
        Txn txn = null;
        try {
            Subject admin = pool.getSecurityManager().authenticate(ADMIN_UID, ADMIN_PWD);

            broker = pool.get(admin);

            transact = pool.getTransactionManager();
            txn = transact.beginTransaction();
View Full Code Here


        }
       
        //do any preparation before execution
        context.prepareForExecution();
       
        final Subject callingUser = broker.getSubject();

        //if setUid or setGid, become Effective User
        EffectiveSubject effectiveSubject = null;
        final Source src = expression.getContext().getSource();
        if(src instanceof DBSource) {
View Full Code Here

    logger.info("Attempting to create group " + groupName);

    Group group = new GroupAider(groupName);

    final DBBroker broker = context.getBroker();
    final Subject currentUser = broker.getSubject();

    try {

      final SecurityManager sm = broker.getBrokerPool().getSecurityManager();

      // add the current user as a group manager
      group.addManager(currentUser);

      if (args.length == 2) {
        // add the additional group managers, this also makes sure they
        // all exist first!
        for (final SequenceIterator i = args[1].iterate(); i.hasNext();) {
          final String groupManager = i.nextItem().getStringValue();

          final Account groupManagerAccount = sm.getAccount(groupManager);
          if (groupManagerAccount == null) {
            logger.error("Could not find the user: " + groupManager);
            // throw exception is better -shabanovd
            return BooleanValue.FALSE;
          }
          group.addManager(groupManagerAccount);
        }
      }

      // create the group
      group = sm.addGroup(group);

            //TEMP - ESCALATE TO DBA :-(
            //START TEMP - we also need to make every manager a member of the group otherwise
            //they do not show up as group members automatically - this is a design problem because group
            //membership is managed on the user and not the group, this needs to be fixed!
            //see XMLDBAddUserToGroup and XMLDBRemoveUserFromGroup also
            final Subject currentSubject = context.getBroker().getSubject();
            try {
                //escalate
                context.getBroker().setSubject(sm.getSystemSubject());

                //perform action
View Full Code Here

     */
    @Override
    public void prepareForExecution() {
        //if there is an existing user in the current http session
        //then set the DBBroker user
      final Subject user = getUserFromHttpSession();
        if(user != null) {
            getBroker().setSubject(user);
        }
       
        setRealUser(getBroker().getSubject());
View Full Code Here

    public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {

        Sequence result = Sequence.EMPTY_SEQUENCE;
       
        final DBBroker broker = getContext().getBroker();
        final Subject currentUser = broker.getSubject();

        if(args.length == 0) {
            if(isCalledAs(qnGetAccountMetadataKeys.getLocalName())) {
                result = getAllAccountMetadataKeys();
            } else if(isCalledAs(qnGetGroupMetadataKeys.getLocalName())) {
                result = getAllGroupMetadataKeys();
            } else {
                throw new XPathException("Unknown function");
            }
        } else {
            final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
            final String strPrincipal = args[0].getStringValue();
            final Principal principal;
            if(isCalledAs(qnGetAccountMetadataKeys.getLocalName()) || isCalledAs(qnGetAccountMetadata.getLocalName())) {
                if(!currentUser.hasDbaRole() && !currentUser.getUsername().equals(strPrincipal)) {
                    throw new XPathException("You must be a DBA to retrieve metadata about other users, otherwise you may only retrieve metadata about yourself.");
                }
                principal = securityManager.getAccount(strPrincipal);
            } else if(isCalledAs(qnGetGroupMetadataKeys.getLocalName()) || isCalledAs(qnGetGroupMetadata.getLocalName())) {
                if(!currentUser.hasDbaRole() && !currentUser.hasGroup(strPrincipal)) {
                    throw new XPathException("You must be a DBA to retrieve metadata about other groups, otherwise you may only retrieve metadata about groups you are a member of.");
                }
                principal = securityManager.getGroup(strPrincipal);
            } else {
                throw new XPathException("Unknown function");
View Full Code Here

  public Sequence eval(Sequence args[], Sequence contextSequence)
      throws XPathException {
   
        final String user = args[0].getStringValue();
       
        final Subject contextUser = context.getSubject();
    if (contextUser.hasDbaRole()) {
      if (contextUser.getName().equals(user)) {
        final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must not be deleting itself");
        logger.error("Invalid user", xPathException);
        throw xPathException;
      } else {
            Collection collection = null;
View Full Code Here

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        final DBBroker broker = getContext().getBroker();
        final Subject currentUser = broker.getSubject();

        final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
       
        final Sequence result;
       
        if(isCalledAs(qnListUsers.getLocalName())) {
            result = new ValueSequence();
            if(currentUser.getName().equals(SecurityManager.GUEST_USER)) {
                result.add(new StringValue(SecurityManager.GUEST_USER));
            } else {
                addUserNamesToSequence(securityManager.findAllUserNames(), result);
            }
        } else {
       
            if(currentUser.getName().equals(SecurityManager.GUEST_USER)) {
                throw new XPathException("You must be an authenticated user");
            }
           
            if(isCalledAs(qnUserExists.getLocalName())) {
                 final String username = args[0].getStringValue();
View Full Code Here

    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        final DBBroker broker = getContext().getBroker();
        final Subject currentUser = broker.getSubject();
        if(currentUser.getName().equals(SecurityManager.GUEST_USER)) {
            throw new XPathException("You must be an authenticated user");
        }
       
        final String username = args[0].getStringValue();
       
View Full Code Here

 
    /* (non-Javadoc)
     * @see org.exist.xmldb.IndexQueryService#reindexCollection()
     */
    public void reindexCollection() throws XMLDBException {
      final Subject preserveSubject = pool.getSubject();
        DBBroker broker = null;
        try {
            broker = pool.get(user);
            broker.reindexCollection(parent.getCollection().getURI());
            broker.sync(Sync.MAJOR_SYNC);
View Full Code Here

         * @see org.exist.xmldb.IndexQueryService#reindexCollection(java.lang.String)
         */
   public void reindexCollection(XmldbURI collectionPath) throws XMLDBException {
       if (parent != null)
         {collectionPath = parent.getPathURI().resolveCollectionPath(collectionPath);}       
       final Subject preserveSubject = pool.getSubject();
        DBBroker broker = null;
        try {
            broker = pool.get(user);
            broker.reindexCollection(collectionPath);
            broker.sync(Sync.MAJOR_SYNC);
View Full Code Here

TOP

Related Classes of org.exist.security.Subject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.