001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.security.realm.providers;
018    
019    import java.io.Serializable;
020    import java.security.Principal;
021    
022    /**
023     * A principal that represents a group for the login modules distributed
024     * with Geronimo.  Custom login modules may use this if convenient or provide
025     * their own Principal implementations -- it doesn't matter.
026     * 
027     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
028     */
029    public class GeronimoGroupPrincipal implements Principal, Serializable {
030        private final String name;
031    
032        public GeronimoGroupPrincipal(String name) {
033            this.name = name;
034        }
035    
036        /**
037         * Compares this principal to the specified object.  Returns true
038         * if the object passed in is a GeronimoGroupPrincipal with the
039         * same name.
040         */
041        public boolean equals(Object another) {
042            if (!(another instanceof GeronimoGroupPrincipal)) return false;
043    
044            return ((GeronimoGroupPrincipal) another).name.equals(name);
045        }
046    
047        /**
048         * Returns a string representation of this principal.
049         */
050        public String toString() {
051            return name;
052        }
053    
054        /**
055         * Returns a hashcode for this principal.
056         */
057        public int hashCode() {
058            return name.hashCode();
059        }
060    
061        /**
062         * Returns the name of this principal.
063         */
064        public String getName() {
065            return name;
066        }
067    }