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. Conceptually,
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    @Override
056    public String getName()
057    {
058        return m_name;
059    }
060    
061    /**
062     * Returns a String representation of the UnresolvedPrincipal.
063     * @return the String
064     */
065    public String toString()
066    {
067        return "[UnresolvedPrincipal: " + m_name + "]";
068    }
069
070    /**
071     * An unresolved principal is equal to another
072     * unresolved principal if their names match.
073     * @param obj the object to compare to this one
074     * @return the result of the equality test
075     * @see java.lang.Object#equals(java.lang.Object)
076     */
077    public boolean equals(final Object obj )
078    {
079        if ( obj instanceof UnresolvedPrincipal )
080        {
081            return m_name.equals( ( (UnresolvedPrincipal) obj ).m_name );
082        }
083        return false;
084    }
085
086    /**
087     *  The hashCode of this object is equal to the hash code of its name.
088     *  @return the hash code
089     */
090    public int hashCode()
091    {
092        return m_name.hashCode();
093    }
094}