2 * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. and others.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.aaa;
11 import static org.opendaylight.aaa.EqualUtil.areEqual;
12 import static org.opendaylight.aaa.HashCodeUtil.hash;
14 import java.io.Serializable;
15 import java.util.Collections;
16 import java.util.HashSet;
19 import org.opendaylight.aaa.api.Claim;
22 * Builder for a {@link Claim}
27 public class ClaimBuilder {
28 private final MutableClaim mc = new MutableClaim();
30 public ClaimBuilder() {
33 public ClaimBuilder(Claim claim) {
37 protected void setClaim(Claim claim) {
38 mc.clientId = claim.clientId();
39 mc.userId = claim.userId();
40 mc.user = claim.user();
41 mc.domain = claim.domain();
42 mc.roles.addAll(claim.roles());
45 public ClaimBuilder setClientId(String clientId) {
46 mc.clientId = clientId;
50 public ClaimBuilder setUserId(String userId) {
55 public ClaimBuilder setUser(String userName) {
60 public ClaimBuilder setDomain(String domain) {
65 public ClaimBuilder addRoles(Set<String> roles) {
66 mc.roles.addAll(roles);
70 public ClaimBuilder addRole(String role) {
75 public Claim build() {
80 protected static class MutableClaim implements Claim, Serializable {
81 private static final long serialVersionUID = -8115027645190209129L;
87 final Set<String> roles = new HashSet<String>();
90 public String clientId() {
95 public String userId() {
100 public String user() {
105 public String domain() {
110 public Set<String> roles() {
111 return Collections.unmodifiableSet(roles);
115 public boolean equals(Object o) {
118 if (!(o instanceof Claim))
121 return areEqual(roles, a.roles()) && areEqual(domain, a.domain())
122 && areEqual(userId, a.userId()) && areEqual(user, a.user())
123 && areEqual(clientId, a.clientId());
127 public int hashCode() {
129 int result = HashCodeUtil.SEED;
130 result = hash(result, clientId);
131 result = hash(result, userId);
132 result = hash(result, user);
133 result = hash(result, domain);
134 result = hash(result, roles);
141 public String toString() {
142 StringBuffer sb = new StringBuffer();
143 if (clientId != null)
144 sb.append("clientId:").append(clientId).append(",");
146 sb.append("userId:").append(userId).append(",");
148 sb.append("userName:").append(user).append(",");
150 sb.append("domain:").append(domain).append(",");
151 sb.append("roles:").append(roles);
152 return sb.toString();