httpuserid.java

来自「esri的ArcGIS Server超级学习模板程序(for java)」· Java 代码 · 共 58 行

JAVA
58
字号
package com.esri.solutions.jitk.common.personalization;

import java.security.Principal;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;

import com.esri.solutions.jitk.personalization.data.IUser;
import com.esri.solutions.jitk.personalization.data.IUserId;

/**
 * Implementation of {@link IUser} to represent a User from an
 * HTTP request.  The user's name is retrieved from the <code>UserPrincipal</code>
 * property of the Http Request.
 * 
 * <p>
 * This implementation retrieves the User Principal from the {@link ExternalContext}
 * object, so all of its restrictions apply.
 * </p>
 */
public class HttpUserId implements IUserId  {
	private static final Logger _logger = Logger.getLogger(HttpUserId.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = -4127340782137753788L;
	
	/**
	 * Reference to User Principal
	 */
	private Principal m_principal;
	
	/**
	 * Constructs a new <code>HttpUserId</code> object.  The User Principal
	 * is retrieved from the {@link ExternalContext}.
	 */
	public HttpUserId () {
		FacesContext fc = null;
		fc = FacesContext.getCurrentInstance();
		m_principal = fc.getExternalContext().getUserPrincipal();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.personalization.data.IUser#getUsername()
	 */
	public String getUsername() {
		return m_principal.getName();
	}
	
	
	public void setUsername (String username) {
		_logger.warn("Username being set to " + username + " via configuration, ignoring");
	}
}

⌨️ 快捷键说明

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