Explorar o código

login fail message

MaxKey %!s(int64=2) %!d(string=hai) anos
pai
achega
71d53daa90

+ 5 - 0
maxkey-common/src/main/java/org/maxkey/entity/Message.java

@@ -76,6 +76,11 @@ public class Message<T> {
 	public void setMessage(String message) {
 		this.message = message;
 	}
+	
+	public void setMessage(int code,String message) {
+		this.code = code;
+		this.message = message;
+	}
 
 	public T getData() {
 		return data;

+ 5 - 0
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java

@@ -190,6 +190,11 @@ public class LoginEntryPoint {
 		 					(Integer)WebContext.getAttribute(WebConstants.CURRENT_USER_PASSWORD_SET_TYPE));
 		 			authJwtMessage = new Message<AuthJwt>(authJwt);
 		 			
+		 		}else {//fail
+	 				String errorMsg = WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE) == null ? 
+							  "" : WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE).toString();
+	 				authJwtMessage.setMessage(errorMsg);
+	 				_logger.debug("login fail , message {}",errorMsg);
 		 		}
  	        }else {
  	        	_logger.error("Login AuthN type must eq normal , tfa or mobile . ");

+ 11 - 3
maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java

@@ -81,12 +81,20 @@ public class LoginEntryPoint {
  	
  	@RequestMapping(value={"/signin"}, produces = {MediaType.APPLICATION_JSON_VALUE})
 	public ResponseEntity<?> signin( @RequestBody LoginCredential loginCredential) {
+ 		Message<AuthJwt> authJwtMessage = new Message<AuthJwt>(Message.FAIL);
  		if(authTokenService.validateJwtToken(loginCredential.getState())){
 	 		Authentication  authentication  = authenticationProvider.authenticate(loginCredential);
-	 		AuthJwt authJwt = authTokenService.genAuthJwt(authentication);
-	 		return new Message<AuthJwt>(authJwt).buildResponse();
+	 		if(authentication != null) {
+	 			AuthJwt authJwt = authTokenService.genAuthJwt(authentication);
+	 			authJwtMessage = new Message<AuthJwt>(authJwt);
+	 		}else {//fail
+ 				String errorMsg = WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE) == null ? 
+						  "" : WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE).toString();
+				authJwtMessage.setMessage(Message.FAIL,errorMsg);
+				_logger.debug("login fail , message {}",errorMsg);
+	 		}
  		}
- 		return new Message<AuthJwt>(Message.FAIL).buildResponse();
+ 		return authJwtMessage.buildResponse();
  	}
  	
 }