Package org.exist.security

Examples of org.exist.security.Account


                }

                DBBroker broker = null;
                try {
                    broker = getDatabase().get(null);
                    final Account user = broker.getSubject();

                    if(!(account.getName().equals(user.getName()) || user.hasDbaRole()) ) {
                        throw new PermissionDeniedException("You are not allowed to delete '" +account.getName() + "' user");
                    }

                    remove_account.setRemoved(true);
                    remove_account.setCollection(broker, collectionRemovedAccounts, XmldbURI.create(UUIDGenerator.getUUID()+".xml"));
View Full Code Here


        return true;
    }

    @Override
    public Subject authenticate(final String accountName, Object credentials) throws AuthenticationException {
        final Account account = getAccount(accountName);
       
        if(account == null) {
            throw new AuthenticationException(AuthenticationException.ACCOUNT_NOT_FOUND, "Account '" + accountName + "' not found.");
        }
       
        if("SYSTEM".equals(accountName) || (!allowGuestAuthentication && "guest".equals(accountName))) {
            throw new AuthenticationException(AuthenticationException.ACCOUNT_NOT_FOUND, "Account '" + accountName + "' can not be used.");
        }

        if(!account.isEnabled()) {
            throw new AuthenticationException(AuthenticationException.ACCOUNT_LOCKED, "Account '" + accountName + "' is disabled.");
        }

        final Subject subject = new SubjectImpl((AccountImpl) account, credentials);
        if(!subject.isAuthenticated()) {
View Full Code Here

        minor = Integer.parseInt(numbers[1]);
      }
      final NodeList nl = root.getChildNodes();
      Node node;
      Element next;
      Account account;
      NodeList ul;
//      String lastId;
      Group group;
      for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i).getNodeType() != Node.ELEMENT_NODE)
          {continue;}
        next = (Element) nl.item(i);
        if ("users".equals(next.getTagName())) {
//          lastId = next.getAttribute("last-id");
//          try {
//            nextUserId = Integer.parseInt(lastId);
//          } catch (NumberFormatException e) {
//          }
          ul = next.getChildNodes();
          for (int j = 0; j < ul.getLength(); j++) {
            node = ul.item(j);
            if (node.getNodeType() == Node.ELEMENT_NODE && "user".equals(node.getLocalName())) {
              account = createAccount(major, minor, (Element) node);
             
              if (sm.hasAccount(account.getName())) {
                                sm.updateAccount(account);
              } else {
                sm.addAccount(account);
              }
            }
View Full Code Here

    home = homeAttr == null ? null : XmldbURI.create(homeAttr.getValue());
   
    //TODO: workaround for 'null' admin's password. It should be removed after 6 months (@ 10 July 2010)
    if (id == 1 && password == null) {password = "";}
   
    final Account new_account = new UserAider(RealmImpl.ID, name);
    new_account.setPassword(password);
   
    final NodeList gl = node.getChildNodes();
    Node group;
    for (int i = 0; i < gl.getLength(); i++) {
      group = gl.item(i);
      if (group.getNodeType() == Node.ELEMENT_NODE && group.getLocalName().equals(GROUP))
        {new_account.addGroup(group.getFirstChild().getNodeValue());}
    }
   
    return new_account;
  }
View Full Code Here

                    e.printStackTrace();
                }
            } else if (args[0].equalsIgnoreCase("users")) {
                final UserManagementService mgtService = (UserManagementService) current
                        .getService("UserManagementService", "1.0");
                final Account users[] = mgtService.getAccounts();
                System.out.println("User\t\tGroups");
                System.out.println("-----------------------------------------");
                for (int i = 0; i < users.length; i++) {
                    System.out.print(users[i].getName() + "\t\t");
                    final String[] groups = users[i].getGroups();
                    for (int j = 0; j < groups.length; j++) {
                        System.out.print(groups[j]);
                        if (j + 1< groups.length) {
                            System.out.print(", ");
                        }
                    }
                    System.out.println();
                }
            } else if (args[0].equalsIgnoreCase("passwd")) {
                if (startGUI) {
                    messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");
                    return true;
                }
                if (args.length < 2) {
                    System.out.println("Usage: passwd username");
                    return true;
                }
                try {
                    final UserManagementService mgtService = (UserManagementService) current
                            .getService("UserManagementService", "1.0");
                    final Account user = mgtService.getAccount(args[1]);
                    if (user == null) {
                        System.out.println("no such user.");
                        return true;
                    }
                    String p1;
                    String p2;
                    while (true) {
                        p1 = console.readLine("password: ", Character.valueOf('*'));
                        p2 = console.readLine("re-enter password: ", Character.valueOf('*'));
                        if (p1.equals(p2)) {
                            break;
                        }
                        System.out.println(EOL + "entered passwords differ. Try again...");
                    }
                    user.setPassword(p1);
                    mgtService.updateAccount(user);
                    properties.setProperty("password", p1);
                } catch (final Exception e) {
                    System.err.println("ERROR: " + e.getMessage());
                }
            } else if (args[0].equalsIgnoreCase("chmod")) {
                if (args.length < 2) {
                    System.out.println("Usage: chmod [resource] mode");
                    return true;
                }
               
                final Collection temp;
                if (args.length == 3) {
                    System.out.println("trying collection: " + args[1]);
                    temp = current.getChildCollection(args[1]);
                    if (temp == null) {
                        System.out.println(EOL + "trying resource: " + args[1]);
                        final Resource r = current.getResource(args[1]);
                        if (r != null) {
                            final UserManagementService mgtService = (UserManagementService) current
                                .getService("UserManagementService", "1.0");
                            mgtService.chmod(r, args[2]);
                        } else {
                            System.err.println("Resource " + args[1]
                                    + " not found.");
                        }
                    } else {
                        final UserManagementService mgtService = (UserManagementService) temp
                            .getService("UserManagementService", "1.0");
                        mgtService.chmod(args[2]);
                    }
                } else {
                    final UserManagementService mgtService = (UserManagementService) current
                        .getService("UserManagementService", "1.0");
                    mgtService.chmod(args[1]);
                }
                // re-read current collection
                current = DatabaseManager.getCollection(properties
                    .getProperty("uri")
                    + path, properties.getProperty("user"), properties
                    .getProperty("password"));
                getResources();
            } else if (args[0].equalsIgnoreCase("chown")) {
                if (args.length < 3) {
                    System.out
                            .println("Usage: chown username group [resource]");
                    return true;
                }
               
                final Collection temp;
                if (args.length == 4) {
                    temp = current.getChildCollection(args[3]);
                } else {
                    temp = current;
                }
                if (temp != null) {
                    final UserManagementService mgtService = (UserManagementService) temp
                            .getService("UserManagementService", "1.0");
                    final Account u = mgtService.getAccount(args[1]);
                    if (u == null) {
                        System.out.println("unknown user");
                        return true;
                    }
                    mgtService.chown(u, args[2]);
                    System.out.println("owner changed.");
                    getResources();
                    return true;
                }
                final Resource res = current.getResource(args[3]);
                if (res != null) {
                    final UserManagementService mgtService = (UserManagementService) current
                            .getService("UserManagementService", "1.0");
                    final Account u = mgtService.getAccount(args[1]);
                    if (u == null) {
                        System.out.println("unknown user");
                        return true;
                    }
                    mgtService.chown(res, u, args[2]);
                    getResources();
                    return true;
                }
                System.err.println("Resource " + args[3] + " not found.");
               
            } else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
                if(args.length < 2) {
                    messageln("Usage: lock resource");
                    return true;
                }
                final Resource res = current.getResource(args[1]);
                if (res != null) {
                    final UserManagementService mgtService = (UserManagementService)
                    current.getService("UserManagementService", "1.0");
                    final Account user = mgtService.getAccount(properties.getProperty("user", "guest"));
                    if(args[0].equalsIgnoreCase("lock")) {
                        mgtService.lockResource(res, user);
                    } else {
                        mgtService.unlockResource(res);
                    }
View Full Code Here

    public Account getAccount(String name) {
//      if (SYSTEM.equals(name))
//        return defaultRealm.ACCOUNT_SYSTEM;
     
        for(final Realm realm : realms) {
            final Account account = realm.getAccount(name);
            if (account != null) {
                return account;
            }
        }
       
View Full Code Here

                  final Integer newId = conf.getPropertyInteger("id");
                 
                  //XXX: resolve conflicts on ids!!!
                 
                  if (!newId.equals(oldId)) {
                        final Account current = realm.getAccount(name);
                        accountLocks.getWriteLock(current).lock();
                        try {
                            usersById.modify(new PrincipalDbModify<Account>(){
                                @Override
                                public void execute(final Int2ObjectHashMap<Account> principalDb) {
                                    principalDb.remove(oldId);
                                    principalDb.put(newId, current);
                                }
                            });
                        } finally {
                            accountLocks.getWriteLock(current).unlock();
                        }
                  }
                  } else {
                    final Account account = new AccountImpl( realm, conf );
                    addUser(account.getId(), account);
                    realm.registerAccount(account);
                  }
                } else {
                    //this can't be! log any way
                    LOG.error("Account '"+name+"' pressent at '"+realmId+"' realm, but get event that new one created.");
View Full Code Here

                }
               
               
            } else {
                name = XmldbURI.create(".."); //$NON-NLS-1$
                final Account account = service.getAccount(properties.getProperty(InteractiveClient.USER));
                permAider = PermissionAiderFactory.getPermission(account.getName(), account.getPrimaryGroup(), Permission.DEFAULT_RESOURCE_PERM); //$NON-NLS-1$ //$NON-NLS-2$
            }
           
            final List<ResourceDescriptor> selected = new ArrayList<ResourceDescriptor>();
            final int rows[] = fileman.getSelectedRows();
            for(int i = 0; i < rows.length; i++) {
View Full Code Here

            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.setPassword( secret );
                    this.service.updateUser(usr);
                }

            } else {
                final String msg = "user " + name + " not found";
View Full Code Here

        //get copy resource
        Resource copyRes = col.getResource(copyResource);
       
        //change permission on copy
        Account admin = ums.getAccount(ADMIN_UID);
        ums.chown(copyRes, admin, admin.getPrimaryGroup());
        ums.chmod(copyRes, "rwx--x---");
       
        //check permission of copy
        prm = ums.getPermissions(copyRes);
        assertEquals("rwx--x---", prm.toString());
View Full Code Here

TOP

Related Classes of org.exist.security.Account

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.