Java源码示例:com.okta.sdk.resource.user.UserBuilder

示例1
private void createUser() {
    User user = UserBuilder.instance()
        .setEmail("[email protected]")
        .setFirstName("Joe")
        .setLastName("Code")
        .buildAndCreate(client);
}
 
示例2
public UserBuilder setGroups(Set<String> groupIds) {
    this.groupIds = groupIds;
    return this;
}
 
示例3
public UserBuilder setBcryptPasswordHash(String value, String salt, int workFactor) {
    passwordHashProperties = new HashMap<>();
    passwordHashProperties.put("algorithm", "BCRYPT");
    passwordHashProperties.put("workFactor", workFactor);
    passwordHashProperties.put("salt", salt);
    passwordHashProperties.put("value", value);
    return this;
}
 
示例4
private UserBuilder setShaPasswordHash(String shaAlgorithm, String value, String salt, String saltOrder) {
    passwordHashProperties = new HashMap<>();
    passwordHashProperties.put("algorithm", shaAlgorithm);
    passwordHashProperties.put("salt", salt);
    passwordHashProperties.put("value", value);
    passwordHashProperties.put("saltOrder", saltOrder);
    return this;
}
 
示例5
@GetMapping("/createUser")
public User createUser() {
    char[] tempPassword = {'P','a','$','$','w','0','r','d'};
    User user = UserBuilder.instance()
        .setEmail("[email protected].com")
        .setFirstName("Norman")
        .setLastName("Lewis")
        .setPassword(tempPassword)
        .setActive(true)
        .buildAndCreate(client);
    return user;
}
 
示例6
public void executeWorkItem(WorkItem workItem,
                            WorkItemManager workItemManager) {

    try {

        RequiredParameterValidator.validate(this.getClass(),
                                            workItem);

        String userEmail = (String) workItem.getParameter("UserEmail");
        String userFirstName = (String) workItem.getParameter("UserFirstName");
        String userLastName = (String) workItem.getParameter("UserLastName");
        String userActive = (String) workItem.getParameter("UserActive");
        String userGroupIds = (String) workItem.getParameter("UserGroupIds");
        String userLogin = (String) workItem.getParameter("UserLogin");
        String userPassword = (String) workItem.getParameter("UserPassword");
        String userSecurityQuestion = (String) workItem.getParameter("UserSecurityQuestion");
        String userSecurityAnswer = (String) workItem.getParameter("UserSecurityAnswer");

        UserBuilder userBuilder = UserBuilder.instance()
                .setEmail(userEmail)
                .setFirstName(userFirstName)
                .setLastName(userLastName);

        if (userActive != null) {
            userBuilder = userBuilder.setActive(Boolean.parseBoolean(userActive));
        }

        if (userGroupIds != null) {
            List<String> groupIdsList = Arrays.asList(userGroupIds.split(","));
            for (String grp : groupIdsList) {
                userBuilder = userBuilder.addGroup(grp);
            }
        }

        if (userLogin != null) {
            userBuilder = userBuilder.setLogin(userLogin);
        }

        if (userPassword != null) {
            userBuilder = userBuilder.setPassword(userPassword.toCharArray());
        }

        if (userSecurityQuestion != null) {
            userBuilder = userBuilder.setSecurityQuestion(userSecurityQuestion);
        }

        if (userSecurityAnswer != null) {
            userBuilder = userBuilder.setSecurityQuestionAnswer(userSecurityAnswer);
        }

        User user = userBuilder.buildAndCreate(oktaClient);

        Map<String, Object> results = new HashMap<>();
        results.put(RESULTS_VALUE,
                    user.getId());

        workItemManager.completeWorkItem(workItem.getId(),
                                         results);
    } catch (Exception e) {
        handleException(e);
    }
}
 
示例7
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;
        }
    }
 
示例8
public UserBuilder setPassword(char[] password) {
    this.password = Arrays.copyOf(password, password.length);
    return this;
}
 
示例9
public UserBuilder setSecurityQuestion(String securityQuestion) {
    this.securityQuestion = securityQuestion;
    return this;
}
 
示例10
public UserBuilder setSecurityQuestionAnswer(String answer) {
    this.securityQuestionAnswer = answer;
    return this;
}
 
示例11
public UserBuilder setEmail(String email) {
    this.email = email;
    return this;
}
 
示例12
public UserBuilder setFirstName(String firstName) {
    this.firstName = firstName;
    return this;
}
 
示例13
public UserBuilder setLastName(String lastName) {
    this.lastName = lastName;
    return this;
}
 
示例14
public UserBuilder setLogin(String login) {
    this.login = login;
    return this;
}
 
示例15
public UserBuilder setMobilePhone(String mobilePhone) {
    this.mobilePhone = mobilePhone;
    return this;
}
 
示例16
public UserBuilder setSecondEmail(String secondEmail) {
    this.secondEmail = secondEmail;
    return this;
}
 
示例17
public UserBuilder setActive(Boolean active) {
    this.active = active;
    return this;
}
 
示例18
public UserBuilder setProvider(Boolean provider) {
    this.provider = provider;
    return this;
}
 
示例19
public UserBuilder setProfileProperties(Map<String, Object> profileProperties) {

        this.customProfileAttributes.clear();
        return putAllProfileProperties(profileProperties);
    }
 
示例20
public UserBuilder putAllProfileProperties(Map<String, Object> profileProperties) {

        this.customProfileAttributes.putAll(profileProperties);
        return this;
    }
 
示例21
public UserBuilder putProfileProperty(String key, Object value) {
    this.customProfileAttributes.put(key, value);
    return this;
}
 
示例22
public UserBuilder addGroup(String groupId) {
    this.groupIds.add(groupId);
    return this;
}
 
示例23
@Override
public UserBuilder setNextLogin(UserNextLogin nextLogin) {
    this.nextLogin = nextLogin;
    return this;
}
 
示例24
public UserBuilder setSha256PasswordHash(String value, String salt, String saltOrder) {
    return setShaPasswordHash("SHA-256", value, salt, saltOrder);
}
 
示例25
public UserBuilder setSha512PasswordHash(String value, String salt, String saltOrder) {
    return setShaPasswordHash("SHA-512", value, salt, saltOrder);
}
 
示例26
public UserBuilder setSha1PasswordHash(String value, String salt, String saltOrder) {
    return setShaPasswordHash("SHA-1", value, salt, saltOrder);
}