genericprincipal.java

来自「java 写的一个新闻发布系统」· Java 代码 · 共 81 行

JAVA
81
字号
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////// NK 12.04.2001 - Added to support Multi Site and Servlet APIpackage org.jahia.services.usermanager;import java.security.Principal;/** * The minimal implementation of a Principal * Used in Servlet Request Wrapper getUserPrincipal(). * It's a wrapper around a JahiaUser but its getName() return the login username,  * not the jahia user internal key. * * @author  NK */public class GenericPrincipal implements Principal {	private JahiaUser mUser;			private GenericPrincipal(){};						                    public GenericPrincipal( JahiaUser user ){		mUser = user;    }    public String getName () {    	if ( mUser == null ){    		return "";    	}     	return mUser.getUsername();    }    			    public boolean equals (Object another){    	if ( mUser == null ){    		return false;    	}    	    	if (another instanceof Principal) {        	if (another != null) {        		return (mUser.getName().equals (((Principal)another).getName()));        	}        }   		return false;   	}    public int hashCode () {    	if ( mUser == null ){    		return -1;    	}    	return mUser.hashCode();    }    			    public String toString ()    {    	if ( mUser == null ){    		return "";    	}    	StringBuffer output = new StringBuffer ("Detail of user ["+mUser.getUsername()+"]\n");    	output.append ("  - ID ["+Integer.toString (mUser.hashCode())+"]");		return output.toString();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?