2 * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.aaa.shiro.tokenauthrealm.auth;
10 import static org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil.areEqual;
11 import static org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil.hash;
13 import org.opendaylight.aaa.api.PasswordCredentials;
14 import org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil;
15 import org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil;
18 * {@link PasswordCredentials} builder.
22 public class PasswordCredentialBuilder {
23 private final MutablePasswordCredentials pc = new MutablePasswordCredentials();
25 public PasswordCredentialBuilder setUserName(String username) {
26 pc.username = username;
30 public PasswordCredentialBuilder setPassword(String password) {
31 pc.password = password;
35 public PasswordCredentialBuilder setDomain(String domain) {
40 public PasswordCredentials build() {
44 private static class MutablePasswordCredentials implements PasswordCredentials {
45 private int hashCode = 0;
46 private String username;
47 private String password;
48 private String domain;
51 public String username() {
56 public String password() {
61 public String domain() {
66 public boolean equals(Object object) {
70 if (!(object instanceof PasswordCredentials)) {
73 PasswordCredentials passwordCredentials = (PasswordCredentials) object;
74 return EqualUtil.areEqual(username, passwordCredentials.username())
75 && EqualUtil.areEqual(password, passwordCredentials.password());
79 public int hashCode() {
81 int result = HashCodeUtil.SEED;
82 result = HashCodeUtil.hash(result, username);
83 result = HashCodeUtil.hash(result, password);