Commit 74b4b318 authored by 喻春霖's avatar 喻春霖

ds发布上线

parents 32828439 2184307b
......@@ -17,6 +17,25 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
......@@ -71,6 +90,12 @@
<systemPath>${project.basedir}/lib/alpha-framework-core-2.0.6.0014.jar</systemPath>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<!--因配置外部TOMCAT 而配置-->
<dependency>
......
......@@ -7,7 +7,7 @@ import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
@AlphaFrameworkApplication
@ComponentScan(basePackages = {"com.chineseall.eden.authcenter.agent","com.chineseall.eden.authcenter.log"})
@ComponentScan(basePackages = {"com.chineseall.eden.authcenter.agent","com.chineseall.eden.authcenter.log","com.chineseall.eden.authcenter.config"})
public class EdenAuthcenterAgentApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
......
package com.chineseall.eden.authcenter.agent.account;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Getter
@Setter
@Component
@ConfigurationProperties("admin-user")
public class AdminUser {
private String account;
private String password;
}
......@@ -10,6 +10,6 @@ public class ClientDataInfo {
private String returnUrl;
private OauthType oauthType;
private String oauthType;
}
package com.chineseall.eden.authcenter.agent.controller;
import cn.sh.chineseall.framework.api.MapMessage;
import cn.sh.chineseall.framework.core.util.StringUtils;
import com.chineseall.eden.authcenter.config.entity.AuthClient;
import com.chineseall.eden.authcenter.config.entity.AuthSource;
import com.chineseall.eden.authcenter.config.service.AuthClientService;
import com.chineseall.eden.authcenter.config.service.AuthSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequestMapping("/config")
public class AuthConfigController {
@Autowired
private AuthSourceService authSourceService;
@Autowired
private AuthClientService authClientService;
@GetMapping("index")
public String index(){
return "config/index";
}
/**
* 认证源列表
* @param model
* @return
*/
@GetMapping("authsource/list")
public String authSourceList(Model model){
List<AuthSource> dataList = authSourceService.listAll();
model.addAttribute("dataList", dataList);
return "config/authsource_list";
}
@PostMapping("authsource/save")
@ResponseBody
public MapMessage saveAuthSource(@RequestBody AuthSource data){
boolean result = authSourceService.saveAuthSource(data);
return result ? MapMessage.successMessage(): MapMessage.errorMessage();
}
@GetMapping("authsource/detail")
@ResponseBody
public MapMessage authSourceDetail(@RequestParam("key") String key){
if(StringUtils.isBlank(key)){
return MapMessage.errorMessage("参数不全");
}
AuthSource data = authSourceService.getAuthSourceByKey(key);
if(data == null){
return MapMessage.errorMessage("数据不存在");
}
return MapMessage.successMessage().add("data", data);
}
@PostMapping("authsource/changestatus")
@ResponseBody
public MapMessage changeAuthSourceStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){
if(StringUtils.isBlank(key) || status == null){
return MapMessage.errorMessage("参数不全");
}
MapMessage message = new MapMessage();
message.setSuccess(authSourceService.changeStatus(key, status));
return message;
}
/**
* 认证源列表
* @param model
* @return
*/
@GetMapping("authclient/list")
public String authClientList(Model model){
List<AuthClient> dataList = authClientService.listAll();
model.addAttribute("dataList", dataList);
return "config/authclient_list";
}
@PostMapping("authclient/save")
@ResponseBody
public MapMessage saveAuthClient(@RequestBody AuthClient data){
MapMessage message = new MapMessage();
message.setSuccess(authClientService.saveAuthClient(data));
return message;
}
@GetMapping("authclient/detail")
@ResponseBody
public MapMessage authClientDetail(@RequestParam("key") String key){
if(StringUtils.isBlank(key)){
return MapMessage.errorMessage("参数不全");
}
AuthClient data = authClientService.getAuthClientByKey(key);
if(data == null){
return MapMessage.errorMessage("数据不存在");
}
return MapMessage.successMessage().add("data", data);
}
@PostMapping("authclient/changestatus")
@ResponseBody
public MapMessage changeAuthClientStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){
if(StringUtils.isBlank(key) || status == null){
return MapMessage.errorMessage("参数不全");
}
MapMessage message = new MapMessage();
message.setSuccess(authClientService.changeStatus(key, status));
return message;
}
}
package com.chineseall.eden.authcenter.agent.controller;
import com.alibaba.fastjson.JSON;
import com.chineseall.eden.authcenter.log.util.BusinessLogUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Controller
@RequestMapping("log")
public class LogController {
private static final Logger logger = LoggerFactory.getLogger(LogController.class);
@GetMapping("test")
@ResponseBody
public void test(HttpServletRequest request){
Map<String, String[]> params = request.getParameterMap();
BusinessLogUtils.info(params);
logger.info(" ==== logs : " + JSON.toJSONString(params));
}
}
package com.chineseall.eden.authcenter.agent.controller;
import cn.sh.chineseall.framework.core.util.StringUtils;
import com.chineseall.eden.authcenter.agent.account.AdminUser;
import com.chineseall.eden.authcenter.agent.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Controller
@RequestMapping("/login")
public class LoginController {
@Autowired
private AdminUser adminUser;
@GetMapping("index")
public String index(){
return "/login/index";
}
@PostMapping("login")
public String login(HttpServletRequest request, HttpServletResponse response, String account,String password){
if(StringUtils.isEmpty(account) || StringUtils.isEmpty(password)){
return "/login/index";
}
if(Objects.equals(adminUser.getAccount(), account) && Objects.equals(adminUser.getPassword(), password)){
Map<String, Object> map = new HashMap<>();
map.put("account", account);
map.put("password", password);
Cookie cookie = new Cookie("sign", JwtUtils.createJWT(map));
cookie.setMaxAge(24 * 60 * 60);
cookie.setPath("/");
response.addCookie(cookie);
return "/config/index";
}else {
return "/login/index";
}
}
}
package com.chineseall.eden.authcenter.agent.interceptor;
import com.chineseall.eden.authcenter.log.util.RequestResponseHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class AccessInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
RequestResponseHolder.set(httpServletRequest, httpServletResponse);
return true;
}
@Override
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
RequestResponseHolder.remove();
}
@Override
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
}
}
package com.chineseall.eden.authcenter.agent.interceptor;
import cn.sh.chineseall.framework.core.util.MapUtils;
import com.alibaba.fastjson.JSON;
import com.chineseall.eden.authcenter.agent.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Service
public class ApiInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
Cookie[] cookies = request.getCookies();
boolean checkResult = false;
if(cookies != null && cookies.length > 0){
Cookie signCookie = Arrays.stream(cookies).filter(p -> Objects.equals(p.getName(), "sign")).findFirst().orElse(null);
if(signCookie != null){
String sign = signCookie.getValue();
Map<String, Object> userInfo = JwtUtils.parseJWT(sign);
if (MapUtils.isNotEmpty(userInfo)) {
checkResult = true;
}
}
}
if(!checkResult){
response.sendRedirect("redirect:" + request.getContextPath() + "/login/index");
}
return checkResult;
}
@Override
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
}
}
package com.chineseall.eden.authcenter.agent.interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
@Configuration
public class ApiInterceptorConfig extends WebMvcConfigurerAdapter {
@Autowired
ApiInterceptor apiInterceptor;
@Autowired
AccessInterceptor accessInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册TestInterceptor拦截器
InterceptorRegistration accessRegistration = registry.addInterceptor(accessInterceptor);
accessRegistration.addPathPatterns("/**");
InterceptorRegistration registration = registry.addInterceptor(apiInterceptor);
registration.addPathPatterns("/config/**"); //
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converters.add(0, converter);
}
}
package com.chineseall.eden.authcenter.agent.utils;
import cn.sh.chineseall.framework.api.random.RandomUtils;
import cn.sh.chineseall.framework.core.util.StringUtils;
import com.alibaba.fastjson.JSON;
import io.jsonwebtoken.*;
import org.apache.xerces.impl.dv.util.Base64;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Date;
import java.util.Map;
public class JwtUtils {
private static final String JWT_SECRET = "or00RX0XnUfDVr5w";
private static long TOKEN_TIMEOUT_MILLIS= 1 * 24 * 60* 60 * 1000;
/**
* 签发JWT
*
* @return String
*
*/
public static String createJWT(Map<String, Object> dataMap) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
SecretKey secretKey = generalKey();
String jsonString = JSON.toJSONString(dataMap);
JwtBuilder builder = Jwts.builder().setId(String.valueOf(nowMillis)).setSubject(jsonString) // 主题
.setIssuer("user") // 签发者
.setIssuedAt(now) // 签发时间
.signWith(signatureAlgorithm, secretKey); // 签名算法以及密匙
long expMillis = nowMillis + TOKEN_TIMEOUT_MILLIS;
Date expDate = new Date(expMillis);
builder.setExpiration(expDate); // 过期时间
return builder.compact();
}
private static SecretKey generalKey() {
byte[] encodedKey = Base64.decode(JWT_SECRET);
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
return key;
}
/**
*
* 解析JWT字符串
*
* @param jwt
* @return
* @throws Exception
*/
public static Map<String, Object> parseJWT(String jwt) {
SecretKey secretKey = generalKey();
try {
Claims claims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(jwt).getBody();
if (claims != null){
String subject = claims.getSubject();
if (subject != null){
return (Map<String, Object>)JSON.parseObject(subject,Map.class);
}
}
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
server:
port: 9600
context-path: /authcenter
logging:
config: classpath:log4j.xml
spring:
application:
name: eden-authcenter-agent
......@@ -24,158 +26,7 @@ spring:
multipart:
max-file-size: 200MB
max-request-size: 300MB
oauth:
items:
dianjiaoguan: #电教馆
# oauthUrl: https://castest.edu.sh.cn/CAS
# clientId: testClentId
# clientSecret: testClientSecret
oauthUrl: https://cas2.edu.sh.cn/CAS
clientId: clientid
clientSecret: clientSecret
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
edenoperation: #运营中心
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://operator-api.sh-genius.cn/cas/
clientId: testClentId
clientSecret: testClientSecret
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
qpjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cmjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
fxjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
sjjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jsjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jdjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
bsjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
mhjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
pdjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ypjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hkjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ptjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jajy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cnjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
xhjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hpjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
admin-user:
account: ac_admin
password: AC_PWD_2022
oauthclient:
clients:
- clientName: 数字教材
clientId: testClentId
clientSecret: testClientSecret
# - clientName: 接入样例
# clientId: testClentId2
# clientSecret: testClientSecret2
- clientName: 资源评价系统
clientId: xhzyClientId
clientSecret: xhzyClientSecret
- clientName: 阅览室
clientId: readingroomClientId
clientSecret: readingroomClientSecret
- clientName: 空中课堂
clientId: cloudcourse
clientSecret: cloudcourseSecret
- clientName: 自适应学习
clientId: adaptive-learning
clientSecret: adaptive-learningSecret
- clientName: 教学平台
clientId: ai-study-client
clientSecret: 4fa6jt85XeqoSC67
\ No newline at end of file
server:
port: 9600
context-path: /authcenter
logging:
config: classpath:log4j.xml
spring:
application:
name: eden-authcenter-agent
......@@ -24,158 +26,9 @@ spring:
multipart:
max-file-size: 200MB
max-request-size: 300MB
oauth:
items:
dianjiaoguan: #电教馆
# oauthUrl: https://castest.edu.sh.cn/CAS
# clientId: testClentId
# clientSecret: testClientSecret
oauthUrl: https://cas2.edu.sh.cn/CAS
clientId: clientid
clientSecret: clientSecret
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
edenoperation: #运营中心
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://operator-api.sh-genius.cn/cas/
clientId: testClentId
clientSecret: testClientSecret
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
qpjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cmjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
fxjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
sjjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jsjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jdjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
bsjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
mhjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
pdjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ypjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hkjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ptjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jajy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cnjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
xhjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hpjy: #idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl: https://sp.etextbook.cn/authcenter/auth
clientId: dsClentId
clientSecret: VjyqUkkM5Znu
loginSuccessUrl: https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl: https://ds.etextbook.cn/authcenter/auth/logoutsuccess
admin-user:
account: ac_admin
password: AC_PWD_2022
oauthclient:
clients:
- clientName: 数字教材
clientId: testClentId
clientSecret: testClientSecret
# - clientName: 接入样例
# clientId: testClentId2
# clientSecret: testClientSecret2
- clientName: 资源评价系统
clientId: xhzyClientId
clientSecret: xhzyClientSecret
- clientName: 阅览室
clientId: readingroomClientId
clientSecret: readingroomClientSecret
- clientName: 空中课堂
clientId: cloudcourse
clientSecret: cloudcourseSecret
- clientName: 自适应学习
clientId: adaptive-learning
clientSecret: adaptive-learningSecret
- clientName: 教学平台
clientId: ai-study-client
clientSecret: 4fa6jt85XeqoSC67
<?xml version="1.0" encoding="UTF-8"?>
<!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出-->
<!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
<configuration monitorInterval="5">
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<!--变量配置-->
<Properties>
<!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<!-- 定义日志存储的路径 -->
<property name="FILE_PATH" value="/data/ds/logs/" />
<property name="FILE_NAME" value="info" />
<property name="BUSINESS_FILE_NAME" value="business_info" />
</Properties>
<appenders>
<console name="Console" target="SYSTEM_OUT">
<!--输出日志的格式-->
<PatternLayout pattern="${LOG_PATTERN}"/>
<!--控制台只输出level及其以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</console>
<!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,适合临时测试用-->
<File name="Filelog" fileName="${FILE_PATH}/test.log" append="false">
<PatternLayout pattern="${LOG_PATTERN}"/>
</File>
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileInfo" fileName="${FILE_PATH}/info.log" filePattern="${FILE_PATH}/${FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次,1 天-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="300"/>
</RollingFile>
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingBusinessFileInfo" fileName="${FILE_PATH}/business_info.log" filePattern="${FILE_PATH}/${BUSINESS_FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%msg%n"/>
<Policies>
<!--interval属性用来指定多久滚动一次,1 天-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="300"/>
</RollingFile>
<!-- 这个会打印出所有的warn及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileWarn" fileName="${FILE_PATH}/warn.log" filePattern="${FILE_PATH}/${FILE_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次,1天-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="300"/>
</RollingFile>
<!-- 这个会打印出所有的error及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileError" fileName="${FILE_PATH}/error.log" filePattern="${FILE_PATH}/${FILE_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次,1天-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="300"/>
</RollingFile>
</appenders>
<!--Logger节点用来单独指定日志的形式,比如要为指定包下的class指定不同的日志级别等。-->
<!--然后定义loggers,只有定义了logger并引入的appender,appender才会生效-->
<loggers>
<!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
<logger name="org.mongodb" level="info" additivity="false">
<AppenderRef ref="Console"/>
</logger>
<!-- 启动日志打到控制台 -->
<Logger name="org.springframework" level="info" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<!--监控系统信息-->
<!--若是additivity设为false,则 子Logger 只会在自己的appender里输出,而不会在 父Logger 的appender里输出。-->
<Logger name="com.chineseall.eden.authcenter.log.util.BusinessLogUtils" level="info" additivity="true">
<AppenderRef ref="RollingBusinessFileInfo"/>
</Logger>
<root level="info">
<appender-ref ref="Console"/>
<appender-ref ref="Filelog"/>
<appender-ref ref="RollingFileInfo"/>
<appender-ref ref="RollingFileWarn"/>
<appender-ref ref="RollingFileError"/>
</root>
</loggers>
</configuration>
......@@ -19,7 +19,7 @@ body {
}
.statistics-content-item {
background-color: white;
margin: 10px 5px;
margin: 10px 5px 0;
overflow: hidden;
}
.item-height {
......@@ -31,6 +31,11 @@ body {
.statistics-content-item-title {
padding: 12px 0 0 20px;
font-size: 14px;
font-weight: bold;
}
.statistics-content-item-title-sub {
padding: 5px 0 0 20px;
font-size: 12px;
color: #777c82;
}
.statistics-content-item-title-remark {
......
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<html class="no-js" xmlns:th="http://www.w3.org/1999/xhtml">
<!--<![endif]-->
<head>
<meta charset="utf-8" />
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta content="" name="description" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>统一认证登录配置</title>
<link rel="stylesheet" th:href="@{/static/css/main_0216.css}" />
<link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}" />
<link rel="stylesheet" th:href="@{/static/css/normalize.css}" />
<script type="text/javascript" th:src="@{/static/js/jquery-1.10.2.min.js}"></script>
<!--<script src="../js/vendor/modernizr-2.6.2.min.js"></script>-->
</head>
<body style="background-color: #4e97f7 !important;">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div class="bg">
</div>
<script th:inline="javascript">
/*<![CDATA[*/
var ctxPath = /*[[@{/}]]*/ '';
/*]]>*/
</script>
<script type="text/javascript">
window.location.href = ctxPath + 'config/authclient/list'
</script>
</body>
</html>
\ No newline at end of file
......@@ -9,7 +9,7 @@
<script type="text/javascript" th:src="@{/static/js/browser.js}"></script>
<script th:inline="javascript">
/*<![CDATA[*/
var dianjiaoguanLoinUrl = [[${dianjiaoguanLoinUrl}]];
var dianjiaoguanLoinUrl = [[${dianjiaoguanLoginUrl}]];
var edenoperationLoginUrl = [[${edenoperationLoginUrl}]];
var logId = [[${logId}]];
var loginType = [[${loginType}]];
......
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<html class="no-js" xmlns:th="http://www.w3.org/1999/xhtml"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta content="" name="description" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>统一认证登录配置</title>
<link rel="stylesheet" th:href="@{/static/css/main_0216.css}"/>
<link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/static/css/normalize.css}"/>
<script type="text/javascript" th:src="@{/static/js/jquery-1.10.2.min.js}"></script>
<!--<script src="../js/vendor/modernizr-2.6.2.min.js"></script>-->
</head>
<body style="background-color: #4e97f7 !important;">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div class="bg">
<div class="bg-form">
<div class="loginContainer">
<div class="login-box text-center">
<form class="form" method="post">
<h2 class="text-center" style="margin-top: 30px;">统一认证登录配置</h2>
<div class="bg-form" style="width: 80%;margin: 50px auto">
<div class="form-group text-left" style="float: left">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span aria-hidden="true" class="glyphicon glyphicon-user"></span></span>
<input aria-describedby="basic-addon1" autocomplete="off" class="form-control" id="account" placeholder="请输入管理员账号" size="25" tabindex="1" type="text" name="account" value="" />
</div>
</div>
<div class="form-group text-left" style="float: left">
<div class="input-group">
<span class="input-group-addon " id="basic-addon2"> <span aria-hidden="true" class="glyphicon glyphicon-lock"></span></span>
<input aria-describedby="basic-addon1" autocomplete="off" class="form-control" id="password" placeholder="请输入管理员密码" size="25" tabindex="2" type="password" name="password" />
</div>
</div>
<button accesskey="l" class="btn btn-primary btn-block" id="login-button" style="outline: 0" tabindex="6" type="button" onclick="toLogin()">登录
</button>
</div>
</form>
</div>
<!-- <div class="login-box">
<button onclick="toLogin(1)" accesskey="l" class="login-btn" id="login-button" name="button" style="outline: 0" type="button">登录
</button>
</div> -->
</div>
</div>
</div>
<script th:inline="javascript">
/*<![CDATA[*/
var ctxPath = /*[[@{/}]]*/ '';
/*]]>*/
</script>
<script type="text/javascript">
function toLogin () {
var action = ctxPath + "login/login";
$("form").attr("action", action);
$("form").submit();
}
</script>
</body></html>
\ No newline at end of file
......@@ -15,6 +15,21 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
......@@ -79,6 +94,12 @@
<type>jar</type>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
</dependencies>
......
package com.chineseall.eden.authcenter.config.dao;
import cn.sh.chineseall.framework.core.util.StringUtils;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao;
import com.chineseall.eden.authcenter.config.entity.AuthClient;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class AuthClientDao extends StaticCacheDimensionDocumentMongoDao<AuthClient, String> {
public List<AuthClient> loadAll(){
Criteria criteria = Criteria.where("deleted").is(false);
return query(new Query(criteria));
}
public AuthClient loadByKey(String key){
if(StringUtils.isBlank(key)){
return null;
}
Criteria criteria = Criteria.where("key").is(key).and("deleted").is(false);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.eden.authcenter.config.dao;
import cn.sh.chineseall.framework.core.util.StringUtils;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao;
import com.chineseall.eden.authcenter.config.entity.AuthSource;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class AuthSourceDao extends StaticCacheDimensionDocumentMongoDao<AuthSource, String> {
public List<AuthSource> loadAll(){
Criteria criteria = Criteria.where("deleted").is(false);
return query(new Query(criteria));
}
public AuthSource loadByKey(String key){
if(StringUtils.isBlank(key)){
return null;
}
Criteria criteria = Criteria.where("key").is(key).and("deleted").is(false);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.eden.authcenter.config.entity;
import cn.sh.chineseall.framework.dao.core.CacheDimensionDocument;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentCreateTimestamp;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentUpdateTimestamp;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
/**
* 认证客户端
*/
@Getter
@Setter
@DocumentConnection(configName = "mongo")
@DocumentDatabase(database = "dslog")
@DocumentCollection(collection = "auth_client")
public class AuthClient implements CacheDimensionDocument {
@DocumentId
private String id;
private String key;
private String name;
private String secret;
private String whiteRule; // 白名单规则
private Integer status; // 状态 1:启用 2:停用
private Boolean deleted; // 是否已删除
private Date deletedTime; // 删除时间
@DocumentCreateTimestamp
private Date createdTime;
@DocumentUpdateTimestamp
private Date updatedTime;
@Override
public String[] generateCacheDimensions() {
return new String[0];
}
}
package com.chineseall.eden.authcenter.config.entity;
import cn.sh.chineseall.framework.dao.core.CacheDimensionDocument;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentCreateTimestamp;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentUpdateTimestamp;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
/**
* 认证源
*/
@Getter
@Setter
@DocumentConnection(configName = "mongo")
@DocumentDatabase(database = "dslog")
@DocumentCollection(collection = "auth_source")
public class AuthSource implements CacheDimensionDocument {
@DocumentId
private String id;
private String key; // 标识
private String name;
private Integer authType; // 认证方式: 1:oauth 2: idp
private String oauthUrl;
private String clientId;
private String clientSecret;
private String loginSuccessUrl;
private String logoutSuccessUrl;
private Integer status; // 状态 1:启用 2:停用
private Boolean deleted; // 是否已删除
private Date deletedTime; // 删除时间
@DocumentCreateTimestamp
private Date createdTime;
@DocumentUpdateTimestamp
private Date updatedTime;
@Override
public String[] generateCacheDimensions() {
return new String[0];
}
}
package com.chineseall.eden.authcenter.config.service;
import com.chineseall.eden.authcenter.config.entity.AuthClient;
import java.util.List;
public interface AuthClientService {
List<AuthClient> listAll();
boolean saveAuthClient(AuthClient data);
AuthClient getAuthClientByKey(String key);
boolean changeStatus(String key, Integer status);
boolean deleteByKey(String key);
}
package com.chineseall.eden.authcenter.config.service;
import com.chineseall.eden.authcenter.config.entity.AuthSource;
import java.util.List;
public interface AuthSourceService {
List<AuthSource> listAll();
boolean saveAuthSource(AuthSource data);
AuthSource getAuthSourceByKey(String key);
boolean changeStatus(String key, Integer status);
boolean deleteByKey(String key);
}
package com.chineseall.eden.authcenter.config.service.impl;
import cn.sh.chineseall.framework.core.util.StringUtils;
import com.chineseall.eden.authcenter.config.dao.AuthClientDao;
import com.chineseall.eden.authcenter.config.entity.AuthClient;
import com.chineseall.eden.authcenter.config.service.AuthClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class AuthClientServiceImpl implements AuthClientService {
@Autowired
private AuthClientDao authClientDao;
@Override
public List<AuthClient> listAll() {
return authClientDao.loadAll();
}
@Override
public boolean saveAuthClient(AuthClient data) {
if(data == null || StringUtils.isEmpty(data.getKey())){
return false;
}
AuthClient entity = authClientDao.loadByKey(data.getKey());
if(entity == null){
entity = new AuthClient();
entity.setKey(data.getKey());
entity.setDeleted(false);
}
entity.setName(data.getName());
entity.setSecret(data.getSecret());
entity.setWhiteRule(data.getWhiteRule());
entity.setStatus(data.getStatus());
authClientDao.upsert(entity);
return true;
}
@Override
public AuthClient getAuthClientByKey(String key) {
if(StringUtils.isBlank(key)){
return null;
}
return authClientDao.loadByKey(key);
}
@Override
public boolean changeStatus(String key, Integer status) {
AuthClient entity = authClientDao.loadByKey(key);
if(entity != null){
entity.setStatus(status);
authClientDao.upsert(entity);
}
return true;
}
@Override
public boolean deleteByKey(String key) {
AuthClient entity = authClientDao.loadByKey(key);
if(entity != null){
entity.setDeleted(true);
entity.setDeletedTime(new Date());
authClientDao.upsert(entity);
}
return true;
}
}
package com.chineseall.eden.authcenter.config.service.impl;
import cn.sh.chineseall.framework.core.util.StringUtils;
import com.chineseall.eden.authcenter.config.dao.AuthSourceDao;
import com.chineseall.eden.authcenter.config.entity.AuthSource;
import com.chineseall.eden.authcenter.config.service.AuthSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class AuthSourceServiceImpl implements AuthSourceService {
@Autowired
private AuthSourceDao authSourceDao;
@Override
public List<AuthSource> listAll() {
return authSourceDao.loadAll();
}
@Override
public boolean saveAuthSource(AuthSource data) {
if(data == null || StringUtils.isEmpty(data.getKey())){
return false;
}
AuthSource entity = authSourceDao.loadByKey(data.getKey());
if(entity == null){
entity = new AuthSource();
entity.setKey(data.getKey());
entity.setDeleted(false);
}
entity.setName(data.getName());
entity.setAuthType(data.getAuthType());
entity.setOauthUrl(data.getOauthUrl());
entity.setClientId(data.getClientId());
entity.setClientSecret(data.getClientSecret());
entity.setLoginSuccessUrl(data.getLoginSuccessUrl());
entity.setLogoutSuccessUrl(data.getLogoutSuccessUrl());
entity.setStatus(data.getStatus());
authSourceDao.upsert(entity);
return true;
}
@Override
public AuthSource getAuthSourceByKey(String key) {
if(StringUtils.isBlank(key)){
return null;
}
return authSourceDao.loadByKey(key);
}
@Override
public boolean changeStatus(String key, Integer status) {
AuthSource entity = authSourceDao.loadByKey(key);
if(entity != null){
entity.setStatus(status);
authSourceDao.upsert(entity);
}
return true;
}
@Override
public boolean deleteByKey(String key) {
AuthSource entity = authSourceDao.loadByKey(key);
if(entity != null){
entity.setDeleted(true);
entity.setDeletedTime(new Date());
authSourceDao.upsert(entity);
}
return true;
}
}
......@@ -3,14 +3,30 @@ package com.chineseall.eden.authcenter.log.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.core.util.CollectionUtils;
import cn.sh.chineseall.framework.core.util.StringUtils;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao;
import cn.sh.chineseall.framework.dao.mongo.hql.MongoCriteriaTranslator;
import cn.sh.chineseall.framework.lang.calendar.DateUtils;
import com.chineseall.eden.authcenter.log.model.AuthLog;
import com.chineseall.eden.authcenter.log.model.AuthLogHourCount;
import com.mongodb.MongoClient;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.*;
import com.mongodb.util.JSON;
import org.bson.BsonDocument;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, String> {
......@@ -34,11 +50,17 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
criteria.and("logUserInfo.userType").is(params.get("userType").toString());
}
if(params.get("beginTime")!=null){
criteria.and("createTime").gte((Date) params.get("beginTime"));
List<String> days = getDayList((Date) params.get("beginTime"));
if(CollectionUtils.isNotEmpty(days)){
criteria.and("yearMonthDay").in(days);
}
}
if(params.get("endTime")!=null){
criteria.lte((Date) params.get("endTime"));
}
if(params.get("clientId") != null){
criteria.and("clientId").is(params.get("clientId").toString());
}
Query query = Query.query(criteria);
return count(query);
}
......@@ -60,6 +82,39 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return super.distinct(key,new Query(criteria),String.class);
}
public List<String> distinct(String key, Map<String, Object> params, Date beginTime){
Criteria criteria = new Criteria();
if (null != params && params.size() > 0){
params.forEach((k,v)->{
criteria.and(k).is(v);
});
}
if(beginTime!=null){
List<String> days = getDayList(beginTime);
if(CollectionUtils.isNotEmpty(days)){
criteria.and("yearMonthDay").in(days);
}
}
return super.distinct(key,new Query(criteria),String.class);
}
private List<String> getDayList(Date beginTime){
Calendar nextDay = Calendar.getInstance();
nextDay.add(Calendar.DATE, 1);
Calendar calendar = Calendar.getInstance();
calendar.setTime(beginTime);
Set<String> days = new HashSet<>();
while (calendar.before(nextDay)){
days.add(DateUtils.dateToString(calendar.getTime(), "yyyy-MM-dd"));
calendar.add(Calendar.DATE, 1);
}
return new ArrayList<>(days);
}
public long count(Map<String, Object> params){
Criteria criteria = new Criteria();
if (null != params && params.size() > 0){
......@@ -71,6 +126,44 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return count(query);
}
public long count(Map<String, Object> params, Date beginTime){
Criteria criteria = new Criteria();
if (null != params && params.size() > 0){
params.forEach((k,v)->{
criteria.and(k).is(v);
});
}
if(beginTime!=null){
List<String> days = getDayList(beginTime);
if(CollectionUtils.isNotEmpty(days)){
criteria.and("yearMonthDay").in(days);
}
}
Query query = Query.query(criteria);
return count(query);
}
public long count(Map<String, Object> params, List<String> notInBrowserList, Date beginTime){
Criteria criteria = new Criteria();
if (null != params && params.size() > 0){
params.forEach((k,v)->{
criteria.and(k).is(v);
});
}
if(CollectionUtils.isNotEmpty(notInBrowserList)){
criteria.and("browser").nin(notInBrowserList);
}
if(beginTime!=null){
List<String> days = getDayList(beginTime);
if(CollectionUtils.isNotEmpty(days)){
criteria.and("yearMonthDay").in(days);
}
}
Query query = Query.query(criteria);
return count(query);
}
public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams) {
Criteria criteria = new Criteria();
if (null != prams && prams.size() > 0){
......@@ -83,4 +176,59 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
Pageable pageable = new PageRequest(pageNo-1, pageSize, sort);
return query(query.with(pageable));
}
public List<AuthLogHourCount> hourMaxCount(Map<String, Object> matchParams, Date beginTime, int topN){
DocumentDatabase documentDatabase = (DocumentDatabase)this.getDocumentClass().getAnnotation(DocumentDatabase.class);
DocumentCollection documentCollection = (DocumentCollection)this.getDocumentClass().getAnnotation(DocumentCollection.class);
MongoClient mongoClient = super.getMongoClient();
MongoDatabase database = mongoClient.getDatabase(documentDatabase.database());
MongoCollection<BsonDocument> collection = database.getCollection(documentCollection.collection(), BsonDocument.class);
Criteria criteria = new Criteria();
if (null != matchParams && matchParams.size() > 0){
matchParams.forEach((k,v)->{
criteria.and(k).is(v);
});
}
if(beginTime!=null){
List<String> days = getDayList(beginTime);
if(CollectionUtils.isNotEmpty(days)){
criteria.and("yearMonthDay").in(days);
}
}
List<Bson> aggregateList = new ArrayList<>();
BsonDocument matchDocument = MongoCriteriaTranslator.INSTANCE.translate(criteria);
aggregateList.add(Aggregates.match(matchDocument));
Document groupBy = new Document().append("yearMonthDay", "$yearMonthDay").append("hour", "$hour");
aggregateList.add(Aggregates.group(groupBy, Accumulators.sum("count", 1)));
Document project = new Document().append("_id", 0).append("yearMonthDay", "$_id.yearMonthDay").append("hour", "$_id.hour").append("count", "$count");
aggregateList.add(Aggregates.project(project));
aggregateList.add(Aggregates.sort(Sorts.descending("count")));
aggregateList.add(Aggregates.limit(topN));
AggregateIterable<BsonDocument> iterable = collection.aggregate(aggregateList);
List<AuthLogHourCount> dataList = new ArrayList<>();
for(BsonDocument item : iterable){
AuthLogHourCount data = new AuthLogHourCount();
if(item.containsKey("yearMonthDay")){
data.setYearMonthDay(item.getString("yearMonthDay").getValue());
}
if(item.containsKey("hour") ){
data.setHour(item.getInt32("hour").getValue());
}
if(item.containsKey("count")){
double count = item.getInt32("count").getValue();
data.setCount(Double.valueOf(count).longValue());
}
dataList.add(data);
}
return dataList;
}
}
......@@ -79,6 +79,8 @@ public class AuthLog implements CacheDimensionDocument {
@DocumentField
private String yearMonthDay;
private Integer hour;
@Override
public String[] generateCacheDimensions() {
return new String[0];
......
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