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

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

There is a newer version: 3.3.9
Show newest version
/*
  $Id: LdapPrincipal.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;
import edu.vt.middleware.ldap.bean.LdapAttributes;
import edu.vt.middleware.ldap.bean.LdapBeanProvider;

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

  /** hash code seed. */
  protected static final int HASH_CODE_SEED = 79;

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

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

  /** User attributes. */
  private LdapAttributes attributes = LdapBeanProvider.getLdapBeanFactory()
      .newLdapAttributes();


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


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


  /**
   * This returns the ldap attributes for this LdapPrincipal.
   *
   * @return  LdapAttributes
   */
  public LdapAttributes getLdapAttributes()
  {
    return this.attributes;
  }


  /**
   * This returns the supplied Object is equal to this 
   * LdapPrincipal.
   *
   * @param  o  Object
   *
   * @return  boolean
   */
  public boolean equals(final Object o)
  {
    if (o == null) {
      return false;
    }
    return
      o == this ||
        (this.getClass() == o.getClass() && o.hashCode() == this.hashCode());
  }


  /**
   * This returns the hash code for this LdapPrincipal.
   *
   * @return  int
   */
  public int hashCode()
  {
    int hc = HASH_CODE_SEED;
    if (this.name != null) {
      hc += this.name.hashCode();
    }
    return hc;
  }


  /**
   * This returns a String representation of this LdapPrincipal.
   *
   * @return  String
   */
  @Override
  public String toString()
  {
    return String.format("%s%s", this.name, this.attributes);
  }


  /**
   * This compares the supplied object for order. LdapPrincipal is
   * always less 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