2 * Copyright (c) 2013 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.usermanager.internal;
11 import java.io.Serializable;
13 import org.apache.commons.lang3.builder.EqualsBuilder;
14 import org.apache.commons.lang3.builder.HashCodeBuilder;
15 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
16 import org.opendaylight.controller.usermanager.AuthResponse;
19 * Configuration Java Object which represents a Local AAA user
20 * configuration information for User Manager.
22 public class UserConfig implements Serializable {
23 private static final long serialVersionUID = 1L;
26 * Clear text password as we are moving to some MD5 digest
27 * for when saving configurations
29 protected String user;
30 protected String role;
31 private String password;
36 public UserConfig(String user, String password, String role) {
38 this.password = password;
42 public String getUser() {
46 public String getPassword() {
50 public String getRole() {
55 public int hashCode() {
56 return HashCodeBuilder.reflectionHashCode(this);
60 public boolean equals(Object obj) {
61 return EqualsBuilder.reflectionEquals(this, obj);
65 public String toString() {
66 return "UserConfig[user="+ user + ", password=" + password + "]";
69 public boolean isValid() {
70 return (user != null && !user.isEmpty() && role != null
71 && !role.isEmpty() && password != null && !password.isEmpty());
74 public boolean update(String currentPassword, String newPassword,
76 // To make any changes to a user configured profile, current password
77 // must always be provided
78 if (!this.password.equals(currentPassword)) {
81 if (newPassword != null) {
82 this.password = newPassword;
84 if (newRole != null) {
90 public AuthResponse authenticate(String clearTextPass) {
91 AuthResponse locResponse = new AuthResponse();
92 if (password.equals(clearTextPass)) {
93 locResponse.setStatus(AuthResultEnum.AUTH_ACCEPT_LOC);
94 locResponse.addData(role.replace(",", " "));
96 locResponse.setStatus(AuthResultEnum.AUTH_REJECT_LOC);