001    /**
002     * Copyright (c) 2000-2012 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            @Override
037            public boolean equals(Object obj) {
038                    if (obj == null) {
039                            return false;
040                    }
041    
042                    if (this == obj) {
043                            return true;
044                    }
045    
046                    if (obj instanceof ProtectedPrincipal) {
047                            ProtectedPrincipal protectedPrincipal = (ProtectedPrincipal)obj;
048    
049                            if (protectedPrincipal.getName().equals(_name)) {
050                                    return true;
051                            }
052                            else {
053                                    return false;
054                            }
055                    }
056                    else {
057                            return false;
058                    }
059            }
060    
061            public String getName() {
062                    return _name;
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    }