001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: AuthPrincipal.java,v 1.3 2008/06/25 05:41:53 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.authentication.internal; 030 031import com.sun.identity.authentication.internal.server.AuthSPrincipal; 032 033/** 034 * <p> 035 * This class extends the <code>AuthSPrincipal</code> class. 036 * 037 * <p> 038 * Principals such as this <code>AuthPrincipal</code> may be associated with a 039 * particular <code>Subject</code> to augment that <code>Subject</code> with 040 * an additional identity. Refer to the <code>Subject</code> class for more 041 * information on how to achieve this. Authorization decisions can then be based 042 * upon the Principals associated with a <code>Subject</code>. 043 * 044 * @see java.security.Principal 045 * @see javax.security.auth.Subject 046 * 047 * @supported.api 048 */ 049public class AuthPrincipal extends AuthSPrincipal { 050 051 /** 052 * Create an <code>AuthPrincipal</code> with a user name. 053 * 054 * @param name 055 * the name for this user. 056 * @exception NullPointerException 057 * if the <code>name</code> is <code>null</code>. 058 * 059 * @supported.api 060 */ 061 public AuthPrincipal(String name) { 062 super(name); 063 } 064 065 /** 066 * Return the user name for this <code>AuthPrincipal</code>. 067 * 068 * @return the user name for this <code>AuthPrincipal</code> 069 * 070 * @supported.api 071 */ 072 public String getName() { 073 return name; 074 } 075 076 /** 077 * Return the AuthMethod for this <code>AuthPrincipal</code>. 078 * 079 * @return the AuthMethod for this <code>AuthPrincipal</code> 080 */ 081 public String getAuthMethod() { 082 return authMethod; 083 } 084 085 /** 086 * Return the AuthLevel for this <code>AuthPrincipal</code>. 087 * 088 * @return the AuthLevel for this <code>AuthPrincipal</code> 089 */ 090 public String getAuthLevel() { 091 return authLevel; 092 } 093 094 /** 095 * Return a string representation of this 096 * <code>AuthPrincipal</code>. 097 * 098 * @return a string representation of this <code>AuthPrincipal</code>. 099 * 100 * @supported.api 101 */ 102 public String toString() { 103 return ("AuthPrincipal: " + name); 104 } 105 106 /** 107 * Compares the specified object with this 108 * <code>AuthPrincipal</code> for equality. Returns true if the given 109 * object is also an <code>AuthPrincipal</code> and the two 110 * <code>AuthPrincipal</code>s have the same user name. 111 * 112 * @param o 113 * Object to be compared for equality with this 114 * <code>AuthPrincipal</code>. 115 * @return true if the specified Object is equal to this 116 * <code>AuthPrincipal</code>. 117 * 118 * @supported.api 119 */ 120 public boolean equals(Object o) { 121 if (o == null) 122 return false; 123 124 if (this == o) 125 return true; 126 127 if (!(o instanceof AuthPrincipal)) 128 return false; 129 130 AuthPrincipal that = (AuthPrincipal) o; 131 132 if (this.getName().equals(that.getName())) 133 return true; 134 135 return false; 136 } 137 138 /** 139 * Return a hash code for this 140 * <code>AuthPrincipal</code>. 141 * 142 * @return a hash code for this <code>AuthPrincipal</code>. 143 * 144 * @supported.api 145 */ 146 public int hashCode() { 147 return name.hashCode(); 148 } 149}
Copyright © 2010-2017, ForgeRock All Rights Reserved.