001/* 002 * (C) Copyright 2010 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 */ 017 018package org.nuxeo.ecm.platform.login; 019 020import java.security.*; 021 022/** 023 * This class implements the principal interface. 024 * 025 * @author Satish Dharmaraj 026 */ 027public class PrincipalImpl implements Principal { 028 029 private String user; 030 031 /** 032 * Construct a principal from a string user name. 033 * 034 * @param user The string form of the principal name. 035 */ 036 public PrincipalImpl(String user) { 037 this.user = user; 038 } 039 040 /** 041 * Returns true if the object passed matches the principal represented in this implementation. 042 * 043 * @param another the Principal to compare with. 044 * @return true if the Principal passed is the same as that encapsulated in this object, false otherwise 045 */ 046 @Override 047 public boolean equals(Object another) { 048 if (another instanceof PrincipalImpl) { 049 PrincipalImpl p = (PrincipalImpl) another; 050 return user.equals(p.toString()); 051 } else { 052 return false; 053 } 054 } 055 056 /** 057 * Prints a stringified version of the principal. 058 */ 059 @Override 060 public String toString() { 061 return user; 062 } 063 064 /** 065 * return a hashcode for the principal. 066 */ 067 @Override 068 public int hashCode() { 069 return user.hashCode(); 070 } 071 072 /** 073 * return the name of the principal. 074 */ 075 public String getName() { 076 return user; 077 } 078 079}