Crystal.Sea 4 лет назад
Родитель
Сommit
d194c91958

+ 1 - 0
maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyMvcConfig.java

@@ -85,6 +85,7 @@ public class MaxKeyMvcConfig implements WebMvcConfigurer {
                 .addPathPatterns("/profile/**")
                 .addPathPatterns("/safe/**")
                 .addPathPatterns("/historys/**")
+                .addPathPatterns("/appList")
                 .addPathPatterns("/appList/**")
                 .addPathPatterns("/socialsignon/**")
                 

+ 19 - 11
maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SafeController.java

@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.maxkey.constants.ConstantsOperateMessage;
+import org.maxkey.constants.ConstantsPasswordSetType;
 import org.maxkey.constants.ConstantsTimeInterval;
 import org.maxkey.crypto.ReciprocalUtils;
 import org.maxkey.crypto.password.PasswordReciprocal;
@@ -77,17 +78,20 @@ public class SafeController {
 
 	@RequestMapping(value="/changeExpiredPassword") 
 	public ModelAndView changeExpiredPassword(
-			@RequestParam(value ="oldPassword",required = false) String oldPassword,
-			@RequestParam("newPassword") String newPassword,
-			@RequestParam("confirmPassword") String confirmPassword) {
+			@RequestParam(value ="oldPassword" ,required = false) String oldPassword,
+			@RequestParam(value ="newPassword",required = false) String newPassword,
+			@RequestParam(value ="confirmPassword",required = false) String confirmPassword) {
 			ModelAndView modelAndView=new ModelAndView("passwordExpired");
-		
-			if(changeUserPassword(oldPassword,newPassword,confirmPassword)){
+	        if(newPassword ==null ||newPassword.equals("")) {
+	            UserInfo userInfo=WebContext.getUserInfo();
+	            modelAndView.addObject("model", userInfo);
+	            return modelAndView;
+	        }else if(changeUserPassword(oldPassword,newPassword,confirmPassword)){
+	            WebContext.getSession().setAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE,ConstantsPasswordSetType.PASSWORD_NORMAL);
 				return WebContext.redirect("/index");
 				//modelAndView.setViewName("index");
 			}
-				
-		
+	        
 			new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
 		 
 			return modelAndView;
@@ -97,11 +101,15 @@ public class SafeController {
 	@RequestMapping(value="/changeInitPassword") 
 	public ModelAndView changeInitPassword(
 			@RequestParam(value ="oldPassword",required = false) String oldPassword,
-			@RequestParam("newPassword") String newPassword,
-			@RequestParam("confirmPassword") String confirmPassword) {
+			@RequestParam(value ="newPassword",required = false) String newPassword,
+			@RequestParam(value ="confirmPassword",required = false) String confirmPassword) {
 		ModelAndView modelAndView=new ModelAndView("passwordInitial");
-		
-		if(changeUserPassword(oldPassword,newPassword,confirmPassword)){
+        if(newPassword ==null ||newPassword.equals("")) {
+            UserInfo userInfo=WebContext.getUserInfo();
+            modelAndView.addObject("model", userInfo);
+            return modelAndView;
+        }else if(changeUserPassword(oldPassword,newPassword,confirmPassword)){
+            WebContext.getSession().setAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE,ConstantsPasswordSetType.PASSWORD_NORMAL);
 			return WebContext.redirect("/index");
 			//modelAndView.setViewName("index");
 		}

+ 8 - 40
maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/IndexEndpoint.java

@@ -24,9 +24,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.maxkey.configuration.ApplicationConfig;
-import org.maxkey.constants.ConstantsPasswordSetType;
-import org.maxkey.domain.UserInfo;
-import org.maxkey.web.WebConstants;
 import org.maxkey.web.WebContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,49 +48,20 @@ public class IndexEndpoint {
 	@RequestMapping(value={"/forwardindex"})
 	public ModelAndView forwardindex(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
-	    
 		_logger.debug("IndexEndpoint /forwardindex.");
-		ModelAndView modelAndView=new ModelAndView();
-		Integer passwordSetType=(Integer)WebContext.getSession().getAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
-		if(passwordSetType==null || passwordSetType==ConstantsPasswordSetType.PASSWORD_NORMAL){
-			if(applicationConfig.getLoginConfig().getDefaultUri()!=null&&
-					!applicationConfig.getLoginConfig().getDefaultUri().equals("")){
-				if(applicationConfig.getLoginConfig().getDefaultUri().startsWith("http")){
-					return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
-				}
-				return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
-			}
-			modelAndView.setViewName("index");
-			return  modelAndView;
-		}
-		
-		UserInfo userInfo=WebContext.getUserInfo();
-		modelAndView.addObject("model", userInfo);
-		
-		if(passwordSetType==ConstantsPasswordSetType.PASSWORD_EXPIRED||
-                passwordSetType==ConstantsPasswordSetType.MANAGER_CHANGED_PASSWORD){
-			modelAndView.setViewName("passwordExpired");
-			return  modelAndView;
-		}else if(passwordSetType==ConstantsPasswordSetType.INITIAL_PASSWORD){
-			modelAndView.setViewName("passwordInitial");
-			return  modelAndView;
-		}
-		
-		
-		
-		return  new ModelAndView("index");
+        String defaultUri = applicationConfig.getLoginConfig().getDefaultUri();
+        if (defaultUri != null && !defaultUri.equals("")) {
+            _logger.debug("defaultUri " + defaultUri);
+            return WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
+        }
+        _logger.debug("Uri /appList");
+		return  new ModelAndView("/appList");
 	}
 	
 	@RequestMapping(value={"/index"})
 	public ModelAndView home(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
-		_logger.debug("IndexEndpoint /index.");
-		
-		if(applicationConfig.getLoginConfig().getDefaultUri()!=null&&
-				!applicationConfig.getLoginConfig().getDefaultUri().equals("")	){
-			return  WebContext.redirect(applicationConfig.getLoginConfig().getDefaultUri());
-		}
-		
+		_logger.debug("home /index.");
 		return  new ModelAndView("index");
 	}
 	

+ 26 - 0
maxkey-web-maxkey/src/main/java/org/maxkey/web/interceptor/PermissionAdapter.java

@@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
 import org.maxkey.configuration.ApplicationConfig;
+import org.maxkey.constants.ConstantsPasswordSetType;
 import org.maxkey.web.WebConstants;
 import org.maxkey.web.WebContext;
 import org.slf4j.Logger;
@@ -70,6 +71,31 @@ public class PermissionAdapter extends HandlerInterceptorAdapter {
             HttpServletResponse response, Object handler)
             throws Exception {
         _logger.trace("PermissionAdapter preHandle");
+        
+        Object passwordSetTypeAttribute=WebContext.getSession().getAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
+        
+        if(passwordSetTypeAttribute != null) {
+            Integer passwordSetType=(Integer)passwordSetTypeAttribute;
+            if(passwordSetType==ConstantsPasswordSetType.PASSWORD_EXPIRED||
+                    passwordSetType==ConstantsPasswordSetType.MANAGER_CHANGED_PASSWORD){
+                _logger.trace("changeExpiredPassword ... forward to /safe/changeExpiredPassword");
+                if(request.getRequestURI().indexOf("/changeExpiredPassword")>-1) {
+                    return true;
+                }
+                RequestDispatcher dispatcher = request.getRequestDispatcher("/safe/changeExpiredPassword");
+                dispatcher.forward(request, response);
+                return false;
+            }else if(passwordSetType==ConstantsPasswordSetType.INITIAL_PASSWORD){
+                _logger.trace("changeInitPassword ... forward to /safe/changeInitPassword");
+                if(request.getRequestURI().indexOf("/changeInitPassword")>-1) {
+                    return true;
+                }
+                RequestDispatcher dispatcher = request.getRequestDispatcher("/safe/changeInitPassword");
+                dispatcher.forward(request, response);
+                return false;
+            }
+        }
+        
         //save  first protected url 
         SavedRequest  firstSavedRequest = (SavedRequest)WebContext.getAttribute(WebConstants.FIRST_SAVED_REQUEST_PARAMETER);
         // 判断用户是否登录, 判断用户和角色,判断用户是否登录用户