use of com.okta.sdk.resource.group.Group in project okta-sdk-java by okta.
the class Quickstart method main.
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", // key/value pairs predefined in the user profile schema
"Seven").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;
}
}
use of com.okta.sdk.resource.group.Group in project okta-sdk-java by okta.
the class DefaultGroupBuilder method buildAndCreate.
@Override
public Group buildAndCreate(Client client) {
Group group = client.instantiate(Group.class);
group.setProfile(client.instantiate(GroupProfile.class));
group.getProfile().setName(name);
if (Strings.hasText(description))
group.getProfile().setDescription(description);
return client.createGroup(group);
}
Aggregations