Commit 7b37b6fa by stylefeng

更新结构和注释

parent 52131ee4
package com.stylefeng.guns;
import com.stylefeng.guns.config.properties.GunsProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* SpringBoot方式启动类
......@@ -16,23 +12,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
* @Date 2017/5/21 12:06
*/
@SpringBootApplication
public class GunsApplication extends WebMvcConfigurerAdapter {
public class GunsApplication {
protected final static Logger logger = LoggerFactory.getLogger(GunsApplication.class);
@Autowired
GunsProperties gunsProperties;
/**
* 增加swagger的支持
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (gunsProperties.getSwaggerOpen()) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
private final static Logger logger = LoggerFactory.getLogger(GunsApplication.class);
public static void main(String[] args) {
SpringApplication.run(GunsApplication.class, args);
......
......@@ -15,5 +15,4 @@ public class GunsServletInitializer extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(GunsApplication.class);
}
}
package com.stylefeng.guns.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.stylefeng.guns.common.constant.DatasourceEnum;
import com.stylefeng.guns.core.datascope.DataScopeInterceptor;
......@@ -105,10 +104,10 @@ public class MybatisPlusConfig {
return new DataScopeInterceptor();
}
/**
* 乐观锁mybatis插件
*/
@Bean
public OptimisticLockerInterceptor optimisticLockerInterceptor() { return new OptimisticLockerInterceptor(); }
///**
// * 乐观锁mybatis插件
// */
//@Bean
//public OptimisticLockerInterceptor optimisticLockerInterceptor() { return new OptimisticLockerInterceptor(); }
}
......@@ -7,17 +7,21 @@ import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.stylefeng.guns.config.properties.GunsProperties;
import com.stylefeng.guns.core.listener.ConfigListener;
import com.stylefeng.guns.core.xss.XssFilter;
import org.springframework.aop.Advisor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.Arrays;
import java.util.Properties;
......@@ -29,7 +33,21 @@ import java.util.Properties;
* @date 2016年11月12日 下午5:03:32
*/
@Configuration
public class WebConfig {
public class WebConfig extends WebMvcConfigurerAdapter {
@Autowired
private GunsProperties gunsProperties;
/**
* 增加swagger的支持
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (gunsProperties.getSwaggerOpen()) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
/**
* druidServlet注册
......@@ -43,18 +61,17 @@ public class WebConfig {
/**
* druid监控 配置URI拦截策略
* @return
*/
@Bean
public FilterRegistrationBean druidStatFilter(){
public FilterRegistrationBean druidStatFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
//添加过滤规则.
filterRegistrationBean.addUrlPatterns("/*");
//添加不需要忽略的格式信息.
filterRegistrationBean.addInitParameter(
"exclusions","/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*");
"exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*");
//用于session监控页面的用户名显示 需要登录后主动将username注入到session里
filterRegistrationBean.addInitParameter("principalSessionName","username");
filterRegistrationBean.addInitParameter("principalSessionName", "username");
return filterRegistrationBean;
}
......@@ -67,7 +84,7 @@ public class WebConfig {
}
@Bean
public JdkRegexpMethodPointcut druidStatPointcut(){
public JdkRegexpMethodPointcut druidStatPointcut() {
JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut();
String patterns = "com.stylefeng.guns.modular.*.service.*";
//可以set多个
......@@ -88,6 +105,7 @@ public class WebConfig {
/**
* druid 为druidStatPointcut添加拦截
*
* @return
*/
@Bean
......@@ -101,7 +119,7 @@ public class WebConfig {
@Bean
public FilterRegistrationBean xssFilterRegistration() {
XssFilter xssFilter = new XssFilter();
xssFilter.setUrlExclusion(Arrays.asList("/notice/update","/notice/add"));
xssFilter.setUrlExclusion(Arrays.asList("/notice/update", "/notice/add"));
FilterRegistrationBean registration = new FilterRegistrationBean(xssFilter);
registration.addUrlPatterns("/*");
return registration;
......
......@@ -39,8 +39,6 @@ public class GlobalExceptionHandler {
/**
* 拦截业务异常
*
* @author fengshuonan
*/
@ExceptionHandler(GunsException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
......@@ -53,9 +51,7 @@ public class GlobalExceptionHandler {
}
/**
* 用户未登录
*
* @author fengshuonan
* 用户未登录异常
*/
@ExceptionHandler(AuthenticationException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
......@@ -65,9 +61,7 @@ public class GlobalExceptionHandler {
}
/**
* 账号被冻结
*
* @author fengshuonan
* 账号被冻结异常
*/
@ExceptionHandler(DisabledAccountException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
......@@ -79,9 +73,7 @@ public class GlobalExceptionHandler {
}
/**
* 账号密码错误
*
* @author fengshuonan
* 账号密码错误异常
*/
@ExceptionHandler(CredentialsException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
......@@ -93,9 +85,7 @@ public class GlobalExceptionHandler {
}
/**
* 验证码错误
*
* @author fengshuonan
* 验证码错误异常
*/
@ExceptionHandler(InvalidKaptchaException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
......@@ -107,9 +97,7 @@ public class GlobalExceptionHandler {
}
/**
* 无权访问该资源
*
* @author fengshuonan
* 无权访问该资源异常
*/
@ExceptionHandler(UndeclaredThrowableException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
......@@ -117,13 +105,11 @@ public class GlobalExceptionHandler {
public ErrorTip credentials(UndeclaredThrowableException e) {
getRequest().setAttribute("tip", "权限异常");
log.error("权限异常!", e);
return new ErrorTip(BizExceptionEnum.NO_PERMITION.getCode(),BizExceptionEnum.NO_PERMITION.getMessage());
return new ErrorTip(BizExceptionEnum.NO_PERMITION.getCode(), BizExceptionEnum.NO_PERMITION.getMessage());
}
/**
* 拦截未知的运行时异常
*
* @author fengshuonan
*/
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
......@@ -132,6 +118,6 @@ public class GlobalExceptionHandler {
LogManager.me().executeLog(LogTaskFactory.exceptionLog(ShiroKit.getUser().getId(), e));
getRequest().setAttribute("tip", "服务器未知运行时异常");
log.error("运行时异常:", e);
return new ErrorTip(BizExceptionEnum.SERVER_ERROR.getCode(),BizExceptionEnum.SERVER_ERROR.getMessage());
return new ErrorTip(BizExceptionEnum.SERVER_ERROR.getCode(), BizExceptionEnum.SERVER_ERROR.getMessage());
}
}
......@@ -4,15 +4,18 @@ import com.stylefeng.guns.core.util.KaptchaUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
/**
* beetl拓展配置,绑定一些工具类,方便在模板中直接调用
*
* @author stylefeng
* @Date 2018/2/22 21:03
*/
public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
@Override
public void initOther() {
groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
groupTemplate.registerFunctionPackage("tool", new ToolUtil());
groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil());
}
}
......@@ -24,7 +24,6 @@ public class SessionHolderInterceptor extends BaseController {
@Around("cutService()")
public Object sessionKit(ProceedingJoinPoint point) throws Throwable {
HttpSessionHolder.put(super.getHttpServletRequest().getSession());
try {
return point.proceed();
......
......@@ -21,6 +21,12 @@ import javax.servlet.ServletContextListener;
import java.util.HashMap;
import java.util.Map;
/**
* ServletContext监听器
*
* @author stylefeng
* @Date 2018/2/22 21:07
*/
public class ConfigListener implements ServletContextListener {
private static Map<String, String> conf = new HashMap<>();
......@@ -37,8 +43,11 @@ public class ConfigListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext sc = evt.getServletContext();
// 项目路径
//项目发布,当前运行环境的绝对路径
conf.put("realPath", sc.getRealPath("/").replaceFirst("/", ""));
//servletContextPath,默认""
conf.put("contextPath", sc.getContextPath());
}
......
......@@ -17,9 +17,6 @@ public class LogFactory {
/**
* 创建操作日志
*
* @author fengshuonan
* @Date 2017/3/30 18:45
*/
public static OperationLog createOperationLog(LogType logType, Integer userId, String bussinessName, String clazzName, String methodName, String msg, LogSucceed succeed) {
OperationLog operationLog = new OperationLog();
......@@ -36,11 +33,8 @@ public class LogFactory {
/**
* 创建登录日志
*
* @author fengshuonan
* @Date 2017/3/30 18:46
*/
public static LoginLog createLoginLog(LogType logType, Integer userId, String msg,String ip) {
public static LoginLog createLoginLog(LogType logType, Integer userId, String msg, String ip) {
LoginLog loginLog = new LoginLog();
loginLog.setLogname(logType.getMessage());
loginLog.setUserid(userId);
......
......@@ -15,22 +15,18 @@
*/
package com.stylefeng.guns.core.shiro.check;
/**
* 检查用接口
* 检查用接口
*/
public interface ICheck {
/**
* 检查指定角色
* @param permissions
* @return boolean
* 检查当前登录用户是否拥有指定的角色访问当
*/
boolean check(Object[] permissions);
/**
* 检查全体角色
* @return boolean
* 检查当前登录用户是否拥有当前请求的servlet的权限
*/
boolean checkAll();
}
......@@ -18,7 +18,7 @@ package com.stylefeng.guns.core.shiro.check;
import com.stylefeng.guns.core.util.SpringContextHolder;
/**
* 权限检查工厂
* 权限检查管理器(入口)
*/
public class PermissionCheckManager {
private final static PermissionCheckManager me = new PermissionCheckManager();
......
......@@ -2,12 +2,12 @@ package com.stylefeng.guns.core.shiro.factory;
import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.modular.system.dao.MenuDao;
import com.stylefeng.guns.modular.system.dao.UserMgrDao;
import com.stylefeng.guns.common.persistence.model.User;
import org.apache.shiro.authc.CredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
......@@ -56,13 +56,13 @@ public class ShiroFactroy implements IShiro {
public ShiroUser shiroUser(User user) {
ShiroUser shiroUser = new ShiroUser();
shiroUser.setId(user.getId()); // 账号id
shiroUser.setAccount(user.getAccount());// 账号
shiroUser.setDeptId(user.getDeptid()); // 部门id
shiroUser.setDeptName(ConstantFactory.me().getDeptName(user.getDeptid()));// 部门名称
shiroUser.setName(user.getName()); // 用户名称
shiroUser.setId(user.getId());
shiroUser.setAccount(user.getAccount());
shiroUser.setDeptId(user.getDeptid());
shiroUser.setDeptName(ConstantFactory.me().getDeptName(user.getDeptid()));
shiroUser.setName(user.getName());
Integer[] roleArray = Convert.toIntArray(user.getRoleid());// 角色集合
Integer[] roleArray = Convert.toIntArray(user.getRoleid());
List<Integer> roleList = new ArrayList<Integer>();
List<String> roleNameList = new ArrayList<String>();
for (int roleId : roleArray) {
......@@ -77,8 +77,7 @@ public class ShiroFactroy implements IShiro {
@Override
public List<String> findPermissionsByRoleId(Integer roleId) {
List<String> resUrls = menuDao.getResUrlsByRoleId(roleId);
return resUrls;
return menuDao.getResUrlsByRoleId(roleId);
}
@Override
......@@ -89,6 +88,7 @@ public class ShiroFactroy implements IShiro {
@Override
public SimpleAuthenticationInfo info(ShiroUser shiroUser, User user, String realmName) {
String credentials = user.getPassword();
// 密码加盐处理
String source = user.getSalt();
ByteSource credentialsSalt = new Md5Hash(source);
......
......@@ -15,7 +15,6 @@ import java.util.List;
*/
public class ApiMenuFilter extends MenuNode {
public static List<MenuNode> build(List<MenuNode> nodes) {
//如果关闭了接口文档,则不显示接口文档菜单
......
......@@ -9,9 +9,6 @@ public class KaptchaUtil {
/**
* 获取验证码开关
*
* @author stylefeng
* @Date 2017/5/23 22:34
*/
public static Boolean getKaptchaOnOff() {
return SpringContextHolder.getBean(GunsProperties.class).getKaptchaOpen();
......
......@@ -55,7 +55,6 @@ spring:
mybatis-plus:
mapper-locations: classpath*:com/stylefeng/guns/**/mapping/*.xml
typeAliasesPackage: com.stylefeng.guns.common.persistence.model
typeEnumsPackage: com.stylefeng.guns.common.constant.enums
global-config:
id-type: 0 #0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
db-column-underline: false
......
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