001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            @Override
041            public boolean equals(Object obj) {
042                    if (obj == null) {
043                            return false;
044                    }
045    
046                    if (this == obj) {
047                            return true;
048                    }
049    
050                    if (obj instanceof ProtectedPrincipal) {
051                            ProtectedPrincipal protectedPrincipal = (ProtectedPrincipal)obj;
052    
053                            if (protectedPrincipal.getName().equals(_name)) {
054                                    return true;
055                            }
056                            else {
057                                    return false;
058                            }
059                    }
060                    else {
061                            return false;
062                    }
063            }
064    
065            @Override
066            public int hashCode() {
067                    return _name.hashCode();
068            }
069    
070            @Override
071            public String toString() {
072                    return _name;
073            }
074    
075            private String _name;
076    
077    }