mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 12:32:09 +08:00
Provider
This commit is contained in:
@@ -71,7 +71,7 @@ public class LoginEntryPoint {
|
||||
@Autowired
|
||||
@Qualifier("authenticationProvider")
|
||||
AbstractAuthenticationProvider authenticationProvider ;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("socialSignOnProviderService")
|
||||
SocialSignOnProviderService socialSignOnProviderService;
|
||||
@@ -146,12 +146,20 @@ public class LoginEntryPoint {
|
||||
*/
|
||||
@RequestMapping(value={"/signin"}, produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public ResponseEntity<?> signin( @RequestBody LoginCredential loginCredential) {
|
||||
|
||||
Authentication authentication = authenticationProvider.authenticate(loginCredential);
|
||||
if(authentication == null) {
|
||||
return new Message<AuthJwt>(Message.FAIL).buildResponse();
|
||||
Message<AuthJwt> authJwtMessage = new Message<AuthJwt>(Message.FAIL);
|
||||
if(authJwtService.validateJwtToken(loginCredential.getState())){
|
||||
String authType = loginCredential.getAuthType();
|
||||
_logger.debug("Login AuthN Type " + authType);
|
||||
if (StringUtils.isNotBlank(authType)){
|
||||
Authentication authentication = authenticationProvider.doAuthenticate(loginCredential);
|
||||
if(authentication != null) {
|
||||
authJwtMessage = new Message<AuthJwt>(authJwtService.genAuthJwt(authentication));
|
||||
}
|
||||
}else {
|
||||
_logger.error("Login AuthN type must eq normal , tfa or mobile . ");
|
||||
}
|
||||
}
|
||||
return new Message<AuthJwt>(authJwtService.genAuthJwt(authentication)).buildResponse();
|
||||
return authJwtMessage.buildResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.maxkey.web.contorller;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.maxkey.authn.AbstractAuthenticationProvider;
|
||||
import org.maxkey.authn.LoginCredential;
|
||||
import org.maxkey.authn.jwt.AuthJwt;
|
||||
@@ -35,7 +37,6 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
|
||||
@@ -48,14 +49,11 @@ public class LoginEntryPoint {
|
||||
private static Logger _logger = LoggerFactory.getLogger(LoginEntryPoint.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authJwtService")
|
||||
AuthJwtService authJwtService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authenticationProvider")
|
||||
AbstractAuthenticationProvider authenticationProvider ;
|
||||
@@ -64,34 +62,28 @@ public class LoginEntryPoint {
|
||||
* init login
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"/login"})
|
||||
public ModelAndView login() {
|
||||
@RequestMapping(value={"/get"}, produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public ResponseEntity<?> get() {
|
||||
_logger.debug("LoginController /login.");
|
||||
|
||||
boolean isAuthenticated= false;//WebContext.isAuthenticated();
|
||||
//for normal login
|
||||
if(isAuthenticated){
|
||||
return WebContext.redirect("/main");
|
||||
}
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
HashMap<String , Object> model = new HashMap<String , Object>();
|
||||
model.put("isRemeberMe", applicationConfig.getLoginConfig().isRemeberMe());
|
||||
Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
|
||||
modelAndView.addObject("isRemeberMe", applicationConfig.getLoginConfig().isRemeberMe());
|
||||
modelAndView.addObject("captchaSupport", inst.getCaptchaSupport());
|
||||
modelAndView.addObject("captchaType", inst.getCaptchaType());
|
||||
modelAndView.addObject("sessionid", WebContext.getSession().getId());
|
||||
Object loginErrorMessage=WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE);
|
||||
modelAndView.addObject("loginErrorMessage", loginErrorMessage==null?"":loginErrorMessage);
|
||||
WebContext.removeAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE);
|
||||
modelAndView.setViewName("login");
|
||||
return modelAndView;
|
||||
model.put("inst", inst);
|
||||
model.put("captcha", inst.getCaptchaSupport());
|
||||
model.put("captchaType", inst.getCaptchaType());
|
||||
model.put("state", authJwtService.genJwt());
|
||||
return new Message<HashMap<String , Object>>(model).buildResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value={"/signin"}, produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public ResponseEntity<?> signin( @RequestBody LoginCredential loginCredential) {
|
||||
Authentication authentication = authenticationProvider.authenticate(loginCredential);
|
||||
AuthJwt authJwt = authJwtService.genAuthJwt(authentication);
|
||||
return new Message<AuthJwt>(authJwt).buildResponse();
|
||||
if(authJwtService.validateJwtToken(loginCredential.getState())){
|
||||
Authentication authentication = authenticationProvider.authenticate(loginCredential);
|
||||
AuthJwt authJwt = authJwtService.genAuthJwt(authentication);
|
||||
return new Message<AuthJwt>(authJwt).buildResponse();
|
||||
}
|
||||
return new Message<AuthJwt>(Message.FAIL).buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user