001/* 
002    Licensed to the Apache Software Foundation (ASF) under one
003    or more contributor license agreements.  See the NOTICE file
004    distributed with this work for additional information
005    regarding copyright ownership.  The ASF licenses this file
006    to you under the Apache License, Version 2.0 (the
007    "License"); you may not use this file except in compliance
008    with the License.  You may obtain a copy of the License at
009
010       http://www.apache.org/licenses/LICENSE-2.0
011
012    Unless required by applicable law or agreed to in writing,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.  
018 */
019package org.apache.wiki.auth.acl;
020
021import java.io.Serializable;
022import java.security.Principal;
023
024/**
025 * Represents a Principal, typically read from an ACL, that cannot
026 * be resolved based on the current state of the user database, group
027 * manager, and built-in role definitions.
028 * Creating a principal marked "unresolved" allows
029 * delayed resolution, which enables principals to be resolved
030 * lazily during a later access control check. Conceptuallly,
031 * UnresolvedPrincipal performs a function similar to
032 * {@link java.security.UnresolvedPermission}.
033 * 
034 * @since 2.3
035 */
036public final class UnresolvedPrincipal implements Principal, Serializable
037{
038    private static final long serialVersionUID = 1L;
039    private final String m_name;
040
041    /**
042     * Constructs a new UnresolvedPrincipal instance.
043     * @param name the name of the Principal
044     */
045    public UnresolvedPrincipal(final String name )
046    {
047        m_name = name;
048    }
049
050    /**
051     * Returns the name of the principal.
052     * @return the name
053     * @see java.security.Principal#getName()
054     */
055    public String getName()
056    {
057        return m_name;
058    }
059    
060    /**
061     * Returns a String representation of the UnresolvedPrincipal.
062     * @return the String
063     */
064    public String toString()
065    {
066        return "[UnresolvedPrincipal: " + m_name + "]";
067    }
068
069    /**
070     * An unresolved principal is equal to another
071     * unresolved principal if their names match.
072     * @param obj the object to compare to this one
073     * @return the result of the equality test
074     * @see java.lang.Object#equals(java.lang.Object)
075     */
076    public boolean equals(final Object obj )
077    {
078        if ( obj instanceof UnresolvedPrincipal )
079        {
080            return m_name.equals( ( (UnresolvedPrincipal) obj ).m_name );
081        }
082        return false;
083    }
084
085    /**
086     *  The hashCode of this object is equal to the hash code of its name.
087     *  @return the hash code
088     */
089    public int hashCode()
090    {
091        return m_name.hashCode();
092    }
093}