diff --git a/src/main/java/io/qyi/e5/config/security/SecurityConfig.java b/src/main/java/io/qyi/e5/config/security/SecurityConfig.java index 5f11284..d322843 100644 --- a/src/main/java/io/qyi/e5/config/security/SecurityConfig.java +++ b/src/main/java/io/qyi/e5/config/security/SecurityConfig.java @@ -45,30 +45,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { System.out.println("HttpSecurity http"); - /*http.authorizeRequests().antMatchers("/").permitAll(); - http.authorizeRequests().anyRequest().authenticated(); - http.logout().permitAll(); - http.formLogin() - .loginPage("/login") - .loginProcessingUrl("/login1") - .successHandler(securityAuthenticationHandler) - .failureHandler(securityAuthenticationHandler) -// .loginProcessingUrl("api/getInfo") - .permitAll() - .and() - .logout() - .logoutUrl("logout") - .logoutSuccessHandler( securityAuthenticationHandler);*/ http.addFilterBefore(new LinkTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); http.csrf().disable() .apply(usernamePasswordAuthenticationConfig); /*关闭创建session*/ http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); - http.formLogin() + /*formLogin() .loginPage("/user/login")// 登陆页面 .loginProcessingUrl("/user/loginFrom")// 登陆表单提交请求 - .and() - .authorizeRequests().antMatchers("/user/login", "/user/loginFrom", "/auth2/getGithubUrl").permitAll()// 指定相应的请求 不需要验证 + .and()*/ + http.authorizeRequests().antMatchers("/user/login", "/user/loginFrom", "/auth2/getGithubUrl").permitAll()// 指定相应的请求 不需要验证 // .and() // .authorizeRequests().antMatchers("/quartz/**").permitAll()//测试 .anyRequest()// 任何请求 diff --git a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java index 4a567a8..8665ab4 100644 --- a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java +++ b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java @@ -52,7 +52,7 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter { HttpServletResponse response = httpServletResponse; response.setHeader("Access-Control-Allow-Origin","*"); response.setHeader("Access-Control-Allow-Credentials", "true"); - response.setHeader("Access-Control-Allow-Methods", "\"GET, HEAD, POST"); + response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token"); /*如果是OPTIONS则结束请求*/ diff --git a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java index e6381fc..cb6adc5 100644 --- a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java +++ b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java @@ -12,4 +12,6 @@ import lombok.Data; public class OutlookVo { private String clientId; private String clientSecret; + private int cronTimeRandomStart; + private int cronTimeRandomEnd; } diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index 25feff2..786aedb 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -139,7 +139,7 @@ public class OutlookServiceImpl extends ServiceImpl impl String code = json.getJSONObject("error").getString("code"); String message = json.getJSONObject("error").getString("message"); if (!errorCheck(message)) { - outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:3", "0", message); + outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:3", 0, message); return false; } // CompactToken validation failed with reason code: 80049228 @@ -152,11 +152,11 @@ public class OutlookServiceImpl extends ServiceImpl impl s = MailList(token); json = JSON.parseObject(s); if (json.containsKey("error")) { - outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:2", "0", json.getJSONObject("error").getString("message")); + outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:2", 1, json.getJSONObject("error").getString("message")); return false; } } - outlookLogService.addLog(outlook.getGithubId(), "ok", "1", ""); + outlookLogService.addLog(outlook.getGithubId(), "ok", 1, ""); return true; } catch (Exception e) { e.printStackTrace(); @@ -191,7 +191,7 @@ public class OutlookServiceImpl extends ServiceImpl impl JSONObject jsonObject = JSON.parseObject(s); if (!jsonObject.containsKey("access_token")) { logger.info("返回的access_token字段不存在"); - outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌! 需要重新授权!", "0", s); + outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌! 需要重新授权!", 0, s); // 字段不存在 return null; } @@ -202,14 +202,14 @@ public class OutlookServiceImpl extends ServiceImpl impl queryWrapper.eq("client_id", outlook.getClientId()); if (baseMapper.update(outlook, queryWrapper) != 1) { logger.info("返更新行数不为1"); - outlookLogService.addLog(outlook.getGithubId(), "更新数据库时发现有重复的key", "0", ""); + outlookLogService.addLog(outlook.getGithubId(), "更新数据库时发现有重复的key", 0, ""); return null; } return outlook.getAccessToken(); // 更新数据库 } catch (Exception e) { e.printStackTrace(); - outlookLogService.addLog(outlook.getGithubId(), e.getMessage(), "0", e.getMessage()); + outlookLogService.addLog(outlook.getGithubId(), e.getMessage(), 0, e.getMessage()); return null; } } diff --git a/src/main/java/io/qyi/e5/outlook_log/bena/LogVo.java b/src/main/java/io/qyi/e5/outlook_log/bena/LogVo.java new file mode 100644 index 0000000..600ed62 --- /dev/null +++ b/src/main/java/io/qyi/e5/outlook_log/bena/LogVo.java @@ -0,0 +1,18 @@ +package io.qyi.e5.outlook_log.bena; + +import lombok.Data; + +/** + * 返回给浏览器的字段 + * @program: e5 + * @description: + * @author: 落叶随风 + * @create: 2020-04-14 15:05 + **/ +@Data +public class LogVo { + private int callTime; + private int result; + private String msg; + private String originalMsg; +} diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index 57a17bc..ae44b84 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -6,10 +6,13 @@ import com.google.gson.Gson; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; +import io.qyi.e5.outlook_log.bena.LogVo; import io.qyi.e5.outlook_log.entity.OutlookLog; import io.qyi.e5.outlook_log.service.IOutlookLogService; +import org.apache.commons.lang.time.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; @@ -19,6 +22,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; /** @@ -48,15 +53,23 @@ public class OutlookLogController { @GetMapping("/findLog") @ResponseBody - public String findLog(Model model){ + public String findLog(){ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("github_id", github_id); List list = outlookLogService.list(queryWrapper); + Iterator iterator = list.iterator(); + List logVo = new LinkedList<>(); + while (iterator.hasNext()) { + OutlookLog next = iterator.next(); + LogVo vo = new LogVo(); + BeanUtils.copyProperties(next,vo); + logVo.add(vo); + } Gson gson = new Gson(); - return gson.toJson(list); + return gson.toJson(logVo); } @GetMapping("/exec111111") diff --git a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java index c07f856..c845f31 100644 --- a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java +++ b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java @@ -33,12 +33,12 @@ public class OutlookLog implements Serializable { /** * 调用时间 */ - private String callTime; + private Integer callTime; /** * 调用结果 */ - private String result; + private Integer result; /** * 如果有错误原因则记录 diff --git a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java index 8fc026b..6adddd3 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java @@ -12,6 +12,6 @@ import com.baomidou.mybatisplus.extension.service.IService; * @since 2020-03-03 */ public interface IOutlookLogService extends IService { - void addLog(int githubId, String msg,String result,String original_msg); + void addLog(int githubId, String msg,int result,String original_msg); } diff --git a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java index 8c62ba4..6ee9857 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java @@ -17,11 +17,11 @@ import org.springframework.stereotype.Service; @Service public class OutlookLogServiceImpl extends ServiceImpl implements IOutlookLogService { @Override - public void addLog(int githubId, String msg, String result,String original_msg) { + public void addLog(int githubId, String msg, int result,String original_msg) { OutlookLog outlookLog = new OutlookLog(); outlookLog.setGithubId(githubId) - .setResult(result.equals("1") ? "1" : "0") - .setCallTime(String.valueOf(System.currentTimeMillis() / 1000)) + .setResult(result) + .setCallTime((int) (System.currentTimeMillis() / 1000)) .setMsg(msg) .setOriginalMsg(original_msg); diff --git a/src/main/java/io/qyi/e5/util/DateUtil.java b/src/main/java/io/qyi/e5/util/DateUtil.java new file mode 100644 index 0000000..3dbdd7a --- /dev/null +++ b/src/main/java/io/qyi/e5/util/DateUtil.java @@ -0,0 +1,42 @@ +package io.qyi.e5.util; +import java.text.SimpleDateFormat; +import java.util.Date; +/** + * @program: e5 + * @description: + * @author: 落叶随风 + * @create: 2020-04-14 15:26 + **/ +public class DateUtil { + /** + * 时间戳转换成日期格式字符串 + * @param seconds 精确到秒的字符串 + * @param format 格式 + * @return + */ + public static String timeStamp2Date(String seconds,String format) { + if(seconds == null || seconds.isEmpty() || seconds.equals("null")){ + return ""; + } + if(format == null || format.isEmpty()){ + format = "yyyy-MM-dd HH:mm:ss"; + } + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(new Date(Long.valueOf(seconds+"000"))); + } + /** + * 日期格式字符串转换成时间戳 + * @param date_str 字符串日期 + * @param format 如:yyyy-MM-dd HH:mm:ss + * @return + */ + public static String date2TimeStamp(String date_str,String format){ + try { + SimpleDateFormat sdf = new SimpleDateFormat(format); + return String.valueOf(sdf.parse(date_str).getTime()/1000); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } +}