Java tutorial
/** * Copyright (C) 2012 skymobi LTD * * Licensed under GNU GENERAL PUBLIC LICENSE Version 3 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl-3.0.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.skymobi.monitor.security; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author hill.hu * */ public class UserInterceptor extends HandlerInterceptorAdapter { private static Logger logger = LoggerFactory.getLogger(UserInterceptor.class); @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (request.getUserPrincipal() != null) { request.setAttribute(SimpleAuthz.USER_PRINCIPAL, request.getUserPrincipal()); request.setAttribute("userName", request.getUserPrincipal().getName()); } logger.debug("receive a page request "); return true; } }