1 15 16 package org.jahia.services.usermanager; 17 18 19 import java.security.Principal ; 20 21 29 public class GenericPrincipal implements Principal { 30 31 private JahiaUser mUser; 32 33 private GenericPrincipal () { 34 }; 35 36 37 38 public GenericPrincipal (JahiaUser user) { 39 mUser = user; 40 } 41 42 43 public String getName () { 44 if (mUser == null) { 45 return ""; 46 } 47 return mUser.getUsername (); 48 } 49 50 public boolean equals (Object another) { 51 if (mUser == null) { 52 return false; 53 } 54 55 if (another instanceof Principal ) { 56 if (another != null) { 57 return (mUser.getName ().equals (((Principal ) another).getName ())); 58 } 59 } 60 return false; 61 } 62 63 public int hashCode () { 64 if (mUser == null) { 65 return -1; 66 } 67 return mUser.hashCode (); 68 } 69 70 71 public String toString () { 72 if (mUser == null) { 73 return ""; 74 } 75 76 StringBuffer output = new StringBuffer ("Detail of user [" + mUser.getUsername () + "]\n"); 77 output.append (" - ID [" + Integer.toString (mUser.hashCode ()) + "]"); 78 return output.toString (); 79 } 80 81 } | Popular Tags |