001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    
019    import java.io.Serializable;
020    
021    import java.security.Principal;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class ProtectedPrincipal implements Principal, Serializable {
027    
028            public ProtectedPrincipal() {
029                    this(StringPool.BLANK);
030            }
031    
032            public ProtectedPrincipal(String name) {
033                    _name = name;
034            }
035    
036            public String getName() {
037                    return _name;
038            }
039    
040            public boolean equals(Object obj) {
041                    if (obj == null) {
042                            return false;
043                    }
044    
045                    if (this == obj) {
046                            return true;
047                    }
048    
049                    if (obj instanceof ProtectedPrincipal) {
050                            ProtectedPrincipal protectedPrincipal = (ProtectedPrincipal)obj;
051    
052                            if (protectedPrincipal.getName().equals(_name)) {
053                                    return true;
054                            }
055                            else {
056                                    return false;
057                            }
058                    }
059                    else {
060                            return false;
061                    }
062            }
063    
064            public int hashCode() {
065                    return _name.hashCode();
066            }
067    
068            public String toString() {
069                    return _name;
070            }
071    
072            private String _name;
073    
074    }