001    /**
002     * Copyright (c) 2000-2013 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 (this == obj) {
039                            return true;
040                    }
041    
042                    if (!(obj instanceof ProtectedPrincipal)) {
043                            return false;
044                    }
045    
046                    ProtectedPrincipal protectedPrincipal = (ProtectedPrincipal)obj;
047    
048                    if (protectedPrincipal.getName().equals(_name)) {
049                            return true;
050                    }
051                    else {
052                            return false;
053                    }
054            }
055    
056            @Override
057            public String getName() {
058                    return _name;
059            }
060    
061            @Override
062            public int hashCode() {
063                    return _name.hashCode();
064            }
065    
066            @Override
067            public String toString() {
068                    return _name;
069            }
070    
071            private String _name;
072    
073    }