com.huawei.openstack4j.openstack.identity.v2.domain.KeystoneUser Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2016 ContainX and OpenStack4j
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package com.huawei.openstack4j.openstack.identity.v2.domain;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.huawei.openstack4j.model.identity.v2.Role;
import com.huawei.openstack4j.model.identity.v2.Tenant;
import com.huawei.openstack4j.model.identity.v2.User;
import com.huawei.openstack4j.model.identity.v2.builder.UserBuilder;
import com.huawei.openstack4j.openstack.common.ListResult;
import com.google.common.base.MoreObjects;
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonRootName("user")
public class KeystoneUser implements User
{
private static final long serialVersionUID = 1L;
private String id;
private String username;
@JsonProperty("password")
private String password;
private String tenantId;
private String name;
private String email;
@JsonProperty("enabled")
private Boolean enabled;
@JsonProperty("OS-ROLE:roles")
private List roles;
public static UserBuilder builder() {
return new UserConcreteBuilder();
}
@Override
public UserBuilder toBuilder() {
return new UserConcreteBuilder(this);
}
public String getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getTenantId() {
return tenantId;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public Boolean isEnabled() {
return enabled;
}
public List getRoles() {
return roles;
}
public String toString() {
return MoreObjects.toStringHelper(this).omitNullValues()
.add("name", name)
.add("id", id)
.add("username", username)
.add("password", password)
.add("tenantId", tenantId)
.add("email", email)
.add("enabled", enabled)
.add("roles", roles)
.toString();
}
public static class Users extends ListResult {
private static final long serialVersionUID = 1L;
@JsonProperty("users")
private List list;
public List value() {
return list;
}
}
public static class UserConcreteBuilder implements UserBuilder {
private KeystoneUser model;
UserConcreteBuilder() {
this(new KeystoneUser());
}
UserConcreteBuilder(KeystoneUser model) {
this.model = model;
}
public UserBuilder name(String name) {
model.name = name;
return this;
}
/**
* ID should only ever be set if the user already exists and this is used for update based actions
* @param id the user id
* @return this for method chaining
*/
public UserBuilder id(String id) {
model.id = id;
return this;
}
public UserBuilder password(String password) {
model.password = password;
return this;
}
public UserBuilder email(String email) {
model.email = email;
return this;
}
public UserBuilder enabled(boolean enabled) {
model.enabled = enabled;
return this;
}
public UserBuilder tenantId(String tenantId) {
model.tenantId = tenantId;
return this;
}
public UserBuilder tenant(Tenant tenant) {
if (tenant != null && tenant.getId() != null)
model.tenantId = tenant.getId();
return this;
}
@Override
public User build() {
return model;
}
@Override
public UserBuilder from(User in) {
model = (KeystoneUser) in;
return this;
}
}
}