IndexEndpoint.java 3.0 KB
Newer Older
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
1 2
package org.maxkey.web.endpoint;

3 4 5 6 7
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
8 9

import org.maxkey.configuration.ApplicationConfig;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
10
import org.maxkey.constants.ConstantsPasswordSetType;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import org.maxkey.domain.UserInfo;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Index
 * @author Crystal.Sea
 *
 */
@Controller
public class IndexEndpoint {
	private static Logger _logger = LoggerFactory.getLogger(IndexEndpoint.class);
	
	@Autowired
  	@Qualifier("applicationConfig")
  	ApplicationConfig applicationConfig;
	@RequestMapping(value={"/forwardindex"})
35 36 37
	public ModelAndView forwardindex(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
	    
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
38 39 40
		_logger.debug("IndexEndpoint /forwardindex.");
		ModelAndView modelAndView=new ModelAndView();
		Integer passwordSetType=(Integer)WebContext.getSession().getAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
41
		if(passwordSetType==null || passwordSetType==ConstantsPasswordSetType.PASSWORD_NORMAL){
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
42 43 44 45 46
			if(applicationConfig.getLoginConfig().getDefaultUri()!=null&&
					!applicationConfig.getLoginConfig().getDefaultUri().equals("")){
				if(applicationConfig.getLoginConfig().getDefaultUri().startsWith("http")){
					return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
				}
47
				return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
48 49 50 51 52 53 54
			}
			modelAndView.setViewName("index");
			return  modelAndView;
		}
		
		UserInfo userInfo=WebContext.getUserInfo();
		modelAndView.addObject("model", userInfo);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
55
		if(passwordSetType==ConstantsPasswordSetType.PASSWORD_EXPIRED){
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
56 57
			modelAndView.setViewName("passwordExpired");
			return  modelAndView;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
58 59
		}else if(passwordSetType==ConstantsPasswordSetType.INITIAL_PASSWORD||
				 passwordSetType==ConstantsPasswordSetType.MANAGER_CHANGED_PASSWORD){
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
60 61 62 63
			modelAndView.setViewName("passwordInitial");
			return  modelAndView;
		}
		
64 65
		
		
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
66 67 68 69
		return  new ModelAndView("index");
	}
	
	@RequestMapping(value={"/index"})
70 71
	public ModelAndView home(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
		_logger.debug("IndexEndpoint /index.");
		
		if(applicationConfig.getLoginConfig().getDefaultUri()!=null&&
				!applicationConfig.getLoginConfig().getDefaultUri().equals("")	){
			return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
		}
		
		return  new ModelAndView("index");
	}
	
	@RequestMapping(value={"/"})
	public ModelAndView index() {
		_logger.debug("IndexEndpoint /.");
		return  new ModelAndView("index");
		
	}
}