Commit ec1161da authored by 喻春霖's avatar 喻春霖

fixed

parent 789dd4bc
......@@ -38,7 +38,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@Controller
@RequestMapping("auth")
@RequestMapping("/")
public class AuthController {
Logger logger = Logger.getLogger(AuthController.class);
......@@ -53,108 +53,55 @@ public class AuthController {
private AuthLogService authLogService;
// @RequestMapping("index")
// public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
// ModelAndView modelAndView = new ModelAndView();
// modelAndView.setViewName("index2");
// Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
// try {
// String clientId = request.getParameter("client_id");
// String returnUrl = request.getParameter("redirect_uri");
// ClientItem clientItem = clientItemMap.get(clientId);
// AuthLog authLog = new AuthLog();
// authLog.setLogType(LogType.login);
// if (null == clientItem) {
// modelAndView.setViewName("error");
// modelAndView.addObject("message", "client_id为空或者不正确");
// return modelAndView;
// }
// authLog.setClientId(clientId);
// authLog.setAuthSource(clientItem.getClientName());
// String sign = request.getParameter("sign");
// String signOrigin = clientItem.getClientId() + "$$" + clientItem.getClientSecret();
//
// String md5Hex = EncodeUtil.md5(signOrigin);
// if (!Objects.equals(sign, md5Hex)) {
// modelAndView.setViewName("error");
// modelAndView.addObject("message", "请求不合法");
// return modelAndView;
// }
// if (StringUtils.isEmpty(returnUrl)) {
// modelAndView.setViewName("error");
// modelAndView.addObject("message", "登录成功回调地址为空");
// return modelAndView;
// }
// String loginType = request.getParameter("login_type");
// if(StringUtils.isNotEmpty(loginType) && OauthType.getValue(loginType)!=null) {
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(OauthType.getValue(loginType).getCode());
// authLog.setFowardUrl(oauthConfigItem.getOauthUrl());
// authLog.setOauthType(OauthType.getValue(loginType).getCode());
// // 阅览室日志分离
// ClientItem item = clientItemMap.get("readingroomClientId");
// authLog.setAuthSource(item.getClientName());
// authLogService.save(authLog);
// response.sendRedirect(generateLoginUrl(returnUrl, OauthType.getValue(loginType).getCode(), authLog.getId()));
// return null;
// } else {
// authLogService.save(authLog);
// String url1 = generateLoginUrl(returnUrl, OauthType.dianjiaoguan.getCode(), authLog.getId());
// modelAndView.addObject("loginUrl1", url1);
// String url2 = generateLoginUrl(returnUrl, OauthType.edenoperation.getCode(), authLog.getId());
// modelAndView.addObject("loginUrl2", url2);
// modelAndView.addObject("logId", authLog.getId());
// }
// } catch (Exception e) {
// e.printStackTrace();
// modelAndView.setViewName("error");
// modelAndView.addObject("message", "未知错误");
// }
// return modelAndView;
// }
@RequestMapping("index")
@RequestMapping(value = {"","auth","auth/index"})
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("ds");
Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
try {
String clientId = request.getParameter("client_id");
String returnUrl = request.getParameter("redirect_uri");
ClientItem clientItem = clientItemMap.get(clientId);
AuthLog authLog = new AuthLog();
authLog.setLogType(LogType.login);
if (null == clientItem) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "client_id为空或者不正确");
return modelAndView;
}
authLog.setClientId(clientId);
authLog.setAuthSource(clientItem.getClientName());
String sign = request.getParameter("sign");
String signOrigin = clientItem.getClientId() + "$$" + clientItem.getClientSecret();
if (StringUtils.isNotEmpty(clientId)){
String md5Hex = EncodeUtil.md5(signOrigin);
if (!Objects.equals(sign, md5Hex)) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "请求不合法");
return modelAndView;
}
if (StringUtils.isEmpty(returnUrl)) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "登录成功回调地址为空");
return modelAndView;
}
String loginType = request.getParameter("login_type");
OauthType oauthType = OauthType.getValue(loginType);
if(StringUtils.isNotEmpty(loginType) && oauthType !=null) {
if (StringUtils.isNotEmpty(returnUrl) && returnUrl.contains("readinglab")){
// 阅览室日志分离
ClientItem item = clientItemMap.get("readingroomClientId");
authLog.setAuthSource(item.getClientName());
ClientItem clientItem = clientItemMap.get(clientId);
if (null == clientItem) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "client_id为空或者不正确");
return modelAndView;
}
authLog.setClientId(clientId);
authLog.setAuthSource(clientItem.getClientName());
String sign = request.getParameter("sign");
String signOrigin = clientItem.getClientId() + "$$" + clientItem.getClientSecret();
String md5Hex = EncodeUtil.md5(signOrigin);
if (!Objects.equals(sign, md5Hex)) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "请求不合法");
return modelAndView;
}
if (StringUtils.isEmpty(returnUrl)) {
modelAndView.setViewName("error");
modelAndView.addObject("message", "登录成功回调地址为空");
return modelAndView;
}
String loginType = request.getParameter("login_type");
OauthType oauthType = OauthType.getValue(loginType);
if(StringUtils.isNotEmpty(loginType) && oauthType !=null) {
if (StringUtils.isNotEmpty(returnUrl) && returnUrl.contains("readinglab")){
// 阅览室日志分离
ClientItem item = clientItemMap.get("readingroomClientId");
authLog.setAuthSource(item.getClientName());
}
modelAndView.addObject("loginType",loginType);
}else {
modelAndView.addObject("loginType","");
}
modelAndView.addObject("loginType",loginType);
}else {
modelAndView.addObject("loginType","");
}
authLogService.save(authLog);
......@@ -175,7 +122,7 @@ public class AuthController {
return modelAndView;
}
@RequestMapping("tologin")
@RequestMapping("auth/tologin")
public ModelAndView toLogin(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
String loginUrl = request.getParameter("loginUrl");
......@@ -212,7 +159,7 @@ public class AuthController {
return modelAndView;
}
@RequestMapping("logout")
@RequestMapping("auth/logout")
public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("logout");
......@@ -279,7 +226,7 @@ public class AuthController {
return modelAndView;
}
@RequestMapping(value = "loginsuccess", method = RequestMethod.GET)
@RequestMapping(value = "auth/loginsuccess", method = RequestMethod.GET)
public ModelAndView loginsuccess(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
modelAndView.setViewName("loginsuccess");
String code = request.getParameter("code");
......@@ -364,7 +311,7 @@ public class AuthController {
return modelAndView;
}
@RequestMapping(value = "idp/loginsuccess")
@RequestMapping(value = "auth/idp/loginsuccess")
public ModelAndView idploginsuccess(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
modelAndView.setViewName("loginsuccess");
String code = request.getParameter("code");
......@@ -431,7 +378,7 @@ public class AuthController {
}
@RequestMapping(value = "logoutsuccess", method = RequestMethod.GET)
@RequestMapping(value = "auth/logoutsuccess", method = RequestMethod.GET)
public ModelAndView loginoutsuccess(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) throws IOException {
String returnUrl = request.getParameter("return_url");
if(StringUtils.isNotEmpty(returnUrl)){
......@@ -591,7 +538,7 @@ public class AuthController {
return newUrl;
}
@RequestMapping("shauth")
@RequestMapping("auth/shauth")
public ModelAndView chineseallLogin(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("toward");
......@@ -637,7 +584,7 @@ public class AuthController {
return modelAndView;
}
@RequestMapping("shlogout")
@RequestMapping("auth/shlogout")
public ModelAndView shLogout(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("logout");
......
......@@ -6,7 +6,7 @@
<html class="no-js" xmlns:th="http://www.w3.org/1999/xhtml"> <!--<![endif]-->
<head>
<script type="text/javascript" src="../static/js/browser.js"></script>
<script type="text/javascript" th:src="@{/static/js/browser.js}"></script>
<script th:inline="javascript">
/*<![CDATA[*/
var loginUrl1 = [[${loginUrl1}]];
......@@ -26,7 +26,7 @@
window.location.href = baseUrl+idp+"&loginUrl=" + encodeURIComponent(loginUrl3+"&auth_source="+idp)+"&browser="+info.browser+"&device="+info.device+"&os="+info.os+"&version="+info.version;
}
}
if (loginType.length > 0){
if (loginType && loginType.length > 0){
toLogin(loginType);
}
</script>
......@@ -64,29 +64,29 @@
<div class="ds-content-city-float">
<p>市认证源</p>
<button onclick="toLogin('edenoperation')" class="logo-btn city-btn"
style="background: white url('../static/img/logo-shszjc.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-shszjc.png} +')'" type="button"></button>
<button onclick="toLogin('dianjiaoguan')" class="logo-btn city-btn"
style="background: white url('../static/img/logo-tyrz.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-tyrz.png} +')'" type="button"></button>
</div>
</div>
<div class="ds-divide-line"></div>
<div class="ds-content-district">
<p>区认证源</p>
<div>
<button onclick="toLogin('qpjy')" class="logo-btn idp-btn" style="background: url('../static/img/logo-qp.png')"
<button onclick="toLogin('qpjy')" class="logo-btn idp-btn" th:style="'background: url('+@{/static/img/logo-qp.png} +')'"
type="button"></button>
<button onclick="toLogin('jsjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-js.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-js.png} +')'" type="button"></button>
<button onclick="toLogin('hpjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-hp.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-hp.png} +')'" type="button"></button>
<button onclick="toLogin('fxjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-fx.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-fx.png} +')'" type="button"></button>
<button onclick="toLogin('pdjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-pd.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-pd.png} +')'" type="button"></button>
<button onclick="toLogin('ypjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-yp.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-yp.png} +')'" type="button"></button>
<button onclick="toLogin('cnjy')" class="logo-btn idp-btn logo-btn-mask" disabled="disabled"
style="background: url('../static/img/logo-cn.png')" type="button"></button>
th:style="'background: url('+@{/static/img/logo-cn.png} +')'" type="button"></button>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment