Reputation: 504
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);
}
}
Upvotes: 0
Views: 690
Reputation: 11473
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.
Upvotes: 3