简体   繁体   中英

How to retrieve only AS400 Enabled Users using jt400 API

is there a possibility to retrieve only the Enabled Users -to add a filter- to the getUsers method of UserList of jt400?

I did the following implementation but it does not have a good performance, so I am trying to find a better way and if there is a possibility to filter the users and to get only the Enabled users.

Set<String> as400Users = new HashSet(); 
AS400 as400 = new AS400(host, username, password);

//Retrieving Users
UserList users = new UserList(as400);
Enumeration io = users.getUsers();

  while (io.hasMoreElements()) {
            com.ibm.as400.access.User u = (com.ibm.as400.access.User)io.nextElement();
            String userName = u.getName();

            if (u.getStatus().equalsIgnoreCase("*ENABLED")) {
                as400Users.add(userName);
            }

        }

You could query the USER_INFO view like this:

select * 
from qsys2.user_info
where status = '*ENABLED'

This became available at v7.1. Note that this only provides users that you have authority to.

You also might want to move the getName() call inside the filter:

Set<String> as400Users = new HashSet(); 
AS400 as400 = new AS400(host, username, password);

//Retrieving Users
UserList users = new UserList(as400);
Enumeration io = users.getUsers();

while (io.hasMoreElements()) {
    com.ibm.as400.access.User u = (com.ibm.as400.access.User)io.nextElement();

    if (u.getStatus().equalsIgnoreCase("*ENABLED")) {
        as400Users.add(u.getName());
    }

}

Or you could use the newer foreach syntax with getUsers(-1,0)

Set<String> as400Users = new HashSet(); 
AS400 as400 = new AS400(host, username, password);

//Retrieving Users
UserList users = new UserList(as400);
for (com.ibm.as400.access.User u: users.getUser(-1,0)) {
    if (u.getStatus().equalsIgnoreCase("*ENABLED")) {
        as400Users.add(u.getName());
    }
}

Now just choose the fastest method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM