Java源码示例:com.okta.sdk.resource.user.UserList
示例1
public void executeWorkItem(WorkItem workItem,
WorkItemManager workItemManager) {
try {
RequiredParameterValidator.validate(this.getClass(),
workItem);
String userids = (String) workItem.getParameter("UserIds");
List<OktaUser> retUserList = new ArrayList<>();
UserList userList = oktaClient.listUsers();
if (userids != null && userids.length() > 0) {
List<String> useridsList = Arrays.asList(userids.split(","));
userList.stream()
.filter(usr -> useridsList.contains(usr.getId()))
.forEach(usr -> retUserList.add(new OktaUser(usr)));
} else {
// get all
userList.stream().forEach(usr -> retUserList.add(new OktaUser(usr)));
}
Map<String, Object> results = new HashMap<>();
results.put(RESULTS_VALUE,
retUserList);
workItemManager.completeWorkItem(workItem.getId(),
results);
} catch (Exception e) {
handleException(e);
}
}
示例2
private void listAllUsers() {
UserList users = client.listUsers();
// stream
client.listUsers().stream()
.forEach(user -> {
// do something
});
}
示例3
private void userSearch() {
// search by email
UserList users = client.listUsers("[email protected]", null, null, null, null);
// filter parameter
users = client.listUsers(null, "status eq \"ACTIVE\"", null, null, null);
}
示例4
private void paging() {
// get the list of users
UserList users = client.listUsers();
// get the first user in the collection
log.info("First user in collection: {}", users.iterator().next().getProfile().getEmail());
// or loop through all of them (paging is automatic)
for (User tmpUser : users) {
log.info("User: {}", tmpUser.getProfile().getEmail());
}
// or via a stream
users.stream().forEach(tmpUser -> log.info("User: {}", tmpUser.getProfile().getEmail()));
}
示例5
public static void main(String[] args) {
try {
// Instantiate a builder for your Client. If needed, settings like Proxy and Caching can be defined here.
ClientBuilder builder = Clients.builder();
// No need to define anything else; build the Client instance. The ClientCredential information will be automatically found
// in pre-defined locations: i.e. ~/.okta/okta.yaml
Client client = builder.build();
// Create a group
Group group = GroupBuilder.instance()
.setName("my-user-group-" + UUID.randomUUID().toString())
.setDescription("Quickstart created Group")
.buildAndCreate(client);
println("Group: '" + group.getId() + "' was last updated on: " + group.getLastUpdated());
// Create a User Account
String email = "joe.coder+" + UUID.randomUUID().toString() + "@example.com";
char[] password = {'P','a','s','s','w','o','r','d','1'};
User user = UserBuilder.instance()
.setEmail(email)
.setFirstName("Joe")
.setLastName("Coder")
.setPassword(password)
.setSecurityQuestion("Favorite security question?")
.setSecurityQuestionAnswer("None of them!")
.putProfileProperty("division", "Seven") // key/value pairs predefined in the user profile schema
.setActive(true)
.buildAndCreate(client);
// add user to the newly created group
user.addToGroup(group.getId());
String userId = user.getId();
println("User created with ID: " + userId);
// You can look up user by ID
println("User lookup by ID: "+ client.getUser(userId).getProfile().getLogin());
// or by Email
println("User lookup by Email: "+ client.getUser(email).getProfile().getLogin());
// get the list of users
UserList users = client.listUsers();
// get the first user in the collection
println("First user in collection: " + users.iterator().next().getProfile().getEmail());
// or loop through all of them (paging is automatic)
// int ii = 0;
// for (User tmpUser : users) {
// println("["+ ii++ +"] User: " + tmpUser.getProfile().getEmail());
// }
}
catch (ResourceException e) {
// we can get the user friendly message from the Exception
println(e.getMessage());
// and you can get the details too
e.getCauses().forEach( cause -> println("\t" + cause.getSummary()));
throw e;
}
}
示例6
@GetMapping("/users")
public UserList getUsers() {
return client.listUsers();
}
示例7
@GetMapping("/user")
public UserList searchUserByEmail(@RequestParam String query) {
return client.listUsers(query, null, null, null, null);
}