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

edu.vt.middleware.ldap.jaas.LdapRole Maven / Gradle / Ivy

There is a newer version: 3.3.9
Show newest version
/*
  $Id: LdapRole.java 1330 2010-05-23 22:10:53Z dfisher $

  Copyright (C) 2003-2010 Virginia Tech.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware Services
  Email:   [email protected]
  Version: $Revision: 1330 $
  Updated: $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
*/
package edu.vt.middleware.ldap.jaas;

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

/**
 * LdapRole provides a custom implementation for adding LDAP
 * principals to a Subject that represent roles.
 *
 * @author  Middleware Services
 * @version  $Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
 */
public class LdapRole implements Principal, Serializable, Comparable
{

  /** serial version uid. */
  private static final long serialVersionUID = 1427032827399935399L;

  /** LDAP role name. */
  private String name;


  /**
   * This creates a new LdapRole with the supplied name.
   *
   * @param  name  String
   */
  public LdapRole(final String name)
  {
    this.name = name;
  }


  /**
   * This returns the name for this LdapRole.
   *
   * @return  String
   */
  public String getName()
  {
    return this.name;
  }


  /**
   * This returns the supplied Object is equal to this LdapRole.
   *
   * @param  o  Object
   *
   * @return  boolean
   */
  public boolean equals(final Object o)
  {
    boolean b = false;
    if (o != null) {
      if (this != o) {
        if (o instanceof LdapRole) {
          if (((LdapRole) o).getName().equals(this.name)) {
            b = true;
          }
        }
      } else {
        b = true;
      }
    }
    return b;
  }


  /**
   * This returns the hash code for this LdapRole.
   *
   * @return  int
   */
  public int hashCode()
  {
    return this.name.hashCode();
  }


  /**
   * This returns a String representation of this LdapRole.
   *
   * @return  String
   */
  @Override
  public String toString()
  {
    return this.name;
  }


  /**
   * This compares the supplied object for order. LdapRole is
   * always greater than any other object. Otherwise principals are compared
   * lexicographically on name.
   *
   * @param  p  Principal
   *
   * @return  int
   */
  public int compareTo(final Principal p)
  {
    return this.name.compareTo(p.getName());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy