All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.util.security.struct.JPrincipal Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2006-2012 Bull S.A.S.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ow2.util.security.struct;

import java.io.Serializable;
import java.security.Principal;

/**
 * Implementation of Principal class.
 * @author Florent Benoit
 */
public class JPrincipal implements Principal, Serializable {

    /**
     * UID for serialization.
     */
    private static final long serialVersionUID = 5864848835776239991L;

    /**
     * Name of this principal.
     */
    private String name = null;

    /**
     * Constructor.
     * @param name the name of this principal
     */
    public JPrincipal(final String name) {
        this.name = name;
    }

    /**
     * Compares this principal to the specified object. Returns true if the
     * object passed in matches the principal represented by the implementation
     * of this interface.
     * @param another principal to compare with.
     * @return true if the principal passed in is the same as that encapsulated
     *         by this principal, and false otherwise.
     */
    @Override
    public boolean equals(final Object another) {
        if (!(another instanceof Principal)) {
            return false;
        }
        // else
        return name.equals(((Principal) another).getName());
    }

    /**
     * Returns a string representation of this principal.
     * @return a string representation of this principal.
     */
    @Override
    public String toString() {
        return "Principal[" + name + "]";
    }

    /**
     * Returns a hashcode for this principal.
     * @return a hashcode for this principal.
     */
    @Override
    public int hashCode() {
        return name.hashCode();
    }

    /**
     * Returns the name of this principal.
     * @return the name of this principal.
     */
    public String getName() {
        return name;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy