授权功能开发
This commit is contained in:
parent
c28f8ebdbd
commit
51e0b74308
|
|
@ -55,7 +55,7 @@ public class LogAspect {
|
||||||
|
|
||||||
|
|
||||||
//单位时间内最大访问数
|
//单位时间内最大访问数
|
||||||
private static final Integer MAX_COUNT = 20;
|
private static final Integer MAX_COUNT = 50;
|
||||||
|
|
||||||
//单位时间
|
//单位时间
|
||||||
private static final Integer UNIT_TIME = 1 * 1000;
|
private static final Integer UNIT_TIME = 1 * 1000;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.common.utils.DateUtils;
|
import com.common.utils.DateUtils;
|
||||||
import com.common.utils.RandomNumber;
|
import com.common.utils.RandomNumber;
|
||||||
|
import com.common.utils.StringUtils;
|
||||||
import com.common.utils.encryption.PasswdFactory;
|
import com.common.utils.encryption.PasswdFactory;
|
||||||
import com.common.utils.httpClient.WebUtils;
|
import com.common.utils.httpClient.WebUtils;
|
||||||
import com.rzyc.bean.user.auth.GetCode;
|
import com.rzyc.bean.user.auth.GetCode;
|
||||||
|
|
@ -73,8 +74,12 @@ public class AuthController extends BaseController{
|
||||||
try {
|
try {
|
||||||
System.out.println("getCode ----> "+JSONArray.toJSONString(getCode));
|
System.out.println("getCode ----> "+JSONArray.toJSONString(getCode));
|
||||||
|
|
||||||
|
String userId = "";
|
||||||
|
|
||||||
String accessToken = getAccessToken(getCode.getCode());
|
String accessToken = getAccessToken(getCode.getCode());
|
||||||
|
if(StringUtils.isNotBlank(accessToken)){
|
||||||
String userName = getUserName(accessToken);
|
String userName = getUserName(accessToken);
|
||||||
|
if(StringUtils.isNotBlank(userName)){
|
||||||
System.out.println("userName --> "+userName);
|
System.out.println("userName --> "+userName);
|
||||||
SysUser sysUser = sysUserMapper.authUser(unitId,userName);
|
SysUser sysUser = sysUserMapper.authUser(unitId,userName);
|
||||||
if(null == sysUser){
|
if(null == sysUser){
|
||||||
|
|
@ -104,8 +109,10 @@ public class AuthController extends BaseController{
|
||||||
|
|
||||||
sysUserMapper.insert(sysUser);
|
sysUserMapper.insert(sysUser);
|
||||||
}
|
}
|
||||||
|
userId = sysUser.getSysuserid();
|
||||||
model.addAttribute("userId",sysUser.getSysuserid());
|
}
|
||||||
|
}
|
||||||
|
model.addAttribute("userId",userId);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +145,7 @@ public class AuthController extends BaseController{
|
||||||
* @date 2023/12/14 16:32
|
* @date 2023/12/14 16:32
|
||||||
*/
|
*/
|
||||||
public static String getAccessToken(String code)throws Exception{
|
public static String getAccessToken(String code)throws Exception{
|
||||||
|
String accessToken = "";
|
||||||
// 发送请求
|
// 发送请求
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url("https://222.209.85.39:1443/authcenter/getOauth2Token?grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientSecret+"&code="+code+"&redirect_uri="+redirectUri)
|
.url("https://222.209.85.39:1443/authcenter/getOauth2Token?grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientSecret+"&code="+code+"&redirect_uri="+redirectUri)
|
||||||
|
|
@ -146,7 +154,10 @@ public class AuthController extends BaseController{
|
||||||
String responseStr = response.body().string();
|
String responseStr = response.body().string();
|
||||||
System.out.println("responseStr --> "+responseStr);
|
System.out.println("responseStr --> "+responseStr);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(responseStr);
|
JSONObject jsonObject = JSONObject.parseObject(responseStr);
|
||||||
return jsonObject.get("access_token")+"";
|
if(null != jsonObject.get("access_token")){
|
||||||
|
accessToken = jsonObject.get("access_token")+"";
|
||||||
|
}
|
||||||
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -156,6 +167,7 @@ public class AuthController extends BaseController{
|
||||||
* @date 2023/12/14 16:30
|
* @date 2023/12/14 16:30
|
||||||
*/
|
*/
|
||||||
public static String getUserName(String accessToken)throws Exception{
|
public static String getUserName(String accessToken)throws Exception{
|
||||||
|
String userName = "";
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url("https://222.209.85.39:1443/authcenter/getOauth2UserInfo?access_token="+accessToken+"&client_id="+clientId)
|
.url("https://222.209.85.39:1443/authcenter/getOauth2UserInfo?access_token="+accessToken+"&client_id="+clientId)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -163,7 +175,10 @@ public class AuthController extends BaseController{
|
||||||
String responseStr = response.body().string();
|
String responseStr = response.body().string();
|
||||||
System.out.println("responseStr --> "+responseStr);
|
System.out.println("responseStr --> "+responseStr);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(responseStr);
|
JSONObject jsonObject = JSONObject.parseObject(responseStr);
|
||||||
return jsonObject.get("username")+"";
|
if(null != jsonObject.get("username")){
|
||||||
|
userName = jsonObject.get("username")+"";
|
||||||
|
}
|
||||||
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ package com.rzyc.filter;
|
||||||
|
|
||||||
import com.rzyc.config.RedisUtil;
|
import com.rzyc.config.RedisUtil;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.*;
|
||||||
import javax.servlet.annotation.WebFilter;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -25,7 +22,7 @@ public class IpFilter implements Filter {
|
||||||
|
|
||||||
|
|
||||||
//单位时间内最大访问数
|
//单位时间内最大访问数
|
||||||
private static final Integer MAX_COUNT = 15;
|
private static final Integer MAX_COUNT = 50;
|
||||||
|
|
||||||
//单位时间
|
//单位时间
|
||||||
private static final Integer UNIT_TIME = 1 * 1000;
|
private static final Integer UNIT_TIME = 1 * 1000;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@ server:
|
||||||
port: 7010
|
port: 7010
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
redis:
|
||||||
|
host: 172.27.181.247
|
||||||
|
password: gzQdzRedis
|
||||||
|
#host: 127.0.0.1
|
||||||
|
# 进入哨兵项目-这个端口就不用了,除非是单体
|
||||||
|
port: 8011
|
||||||
|
# sentinel:
|
||||||
|
# master: mymaster
|
||||||
|
# nodes: 172.27.181.247:26379,172.27.181.247:26380,172.27.181.247:26381
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
max-active: 8
|
||||||
|
max-idle: 8
|
||||||
|
min-idle: 0
|
||||||
|
max-wait: 100
|
||||||
|
shutdown-timeout: 50000
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
安全生产清单制管理系统授权页面
|
<div id="msg" class="msg" style="text-align: center;">安全生产清单制管理系统授权页面</div>
|
||||||
<input type="hidden" id="userId" name="userId" th:value="${userId}">
|
<input type="hidden" id="userId" name="userId" th:value="${userId}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -19,10 +19,16 @@
|
||||||
console.log('-------安全生产清单制管理系统授权页面-------')
|
console.log('-------安全生产清单制管理系统授权页面-------')
|
||||||
|
|
||||||
var userId = $("#userId").val();
|
var userId = $("#userId").val();
|
||||||
|
|
||||||
console.log("userId ---> "+userId)
|
console.log("userId ---> "+userId)
|
||||||
alert("userId -> "+userId)
|
|
||||||
location.href = "http://192.168.110.226:8081/auth?uid="+userId;
|
if(null != userId && '' != userId){
|
||||||
|
location.href = "http://182.132.59.28:8018/auth?uid="+userId;
|
||||||
|
}else{
|
||||||
|
$("#msg").text("授权失败,请重试或联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user