clean org.springframework.boot:spring-boot-maven-plugin:run -q -e
5 |
6 | Copyright (c) 2017-present Mingshu Jian
9 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/ApplicationEntry.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.ServletComponentScan; 7 | import org.springframework.boot.web.support.SpringBootServletInitializer; 8 | import org.springframework.cache.annotation.EnableCaching; 9 | import org.springframework.scheduling.annotation.EnableAsync; 10 | import org.springframework.scheduling.annotation.EnableScheduling; 11 | import org.springframework.transaction.annotation.EnableTransactionManagement; 12 | 13 | @SpringBootApplication 14 | @EnableTransactionManagement 15 | @ServletComponentScan 16 | @EnableCaching 17 | @EnableScheduling 18 | @EnableAsync //for websocket 19 | public class ApplicationEntry extends SpringBootServletInitializer { 20 | 21 | @Override 22 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 23 | return builder.sources(ApplicationEntry.class); 24 | } 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(ApplicationEntry.class, args); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/controller/ActionMonitorController.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.controller; 2 | 3 | import static com.beamofsoul.bip.management.util.JSONUtils.formatAndParseObject; 4 | import static com.beamofsoul.bip.management.util.JSONUtils.newInstance; 5 | 6 | import java.util.Map; 7 | 8 | import javax.annotation.Resource; 9 | 10 | import org.springframework.data.domain.Pageable; 11 | import org.springframework.security.access.prepost.PreAuthorize; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.ResponseBody; 17 | 18 | import com.alibaba.fastjson.JSONObject; 19 | import com.beamofsoul.bip.management.util.PageUtils; 20 | import com.beamofsoul.bip.service.ActionMonitorService; 21 | 22 | @Controller 23 | @RequestMapping("/admin/actionMonitor") 24 | public class ActionMonitorController extends BaseAbstractController { 25 | 26 | @Resource 27 | private ActionMonitorService actionMonitorService; 28 | 29 | @PreAuthorize("authenticated and hasPermission('actionMonitor','actionMonitor:list')") 30 | @RequestMapping(value = "/adminList") 31 | public String adminList() { 32 | return "/action_monitor/admin_action_monitor_list"; 33 | } 34 | 35 | @PreAuthorize("authenticated and hasPermission('actionMonitor','actionMonitor:list')") 36 | @RequestMapping(value = "actionMonitorsByPage", method = RequestMethod.POST, produces = PRODUCES_APPLICATION_JSON) 37 | @ResponseBody 38 | public JSONObject getPageableActionMonitors(@RequestBody Map使用EhCache实现
10 | * @author MingshuJian 11 | */ 12 | public abstract class GlobalSharedEhCacheConfiguration { 13 | 14 | @Bean("ehcache") 15 | public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() { 16 | EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); 17 | ehCacheManagerFactoryBean.setShared(true); 18 | return ehCacheManagerFactoryBean; 19 | } 20 | 21 | /** 22 | * Spring使用的Cache 23 | */ 24 | @Bean(name = "cacheManager") 25 | public EhCacheCacheManager ehCacheCacheManager(){ 26 | EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager(); 27 | ehCacheCacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject()); 28 | return ehCacheCacheManager; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/cluster/CustomHttpSessionApplicationInitializer.java: -------------------------------------------------------------------------------- 1 | //package com.beamofsoul.bip.management.cluster; 2 | // 3 | //import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer; 4 | // 5 | //import com.beamofsoul.bip.management.security.CustomWebSecurityConfig; 6 | // 7 | ///** 8 | // * @ClassName CustomHttpSessionApplicationInitializer 9 | // * @Description This ensures that the Spring Bean by the name springSessionRepositoryFilter is registered with our Servlet Container for every request before Spring Security’s springSecurityFilterChain 10 | // * @author MingshuJian 11 | // * @Date 2017年6月7日 上午10:08:30 12 | // * @version 1.0.0 13 | // */ 14 | //public class CustomHttpSessionApplicationInitializer extends AbstractHttpSessionApplicationInitializer { 15 | // 16 | // public CustomHttpSessionApplicationInitializer() { 17 | // //确保Spring加载了安全框架的配置和自定义HttpSession的配置 18 | // super(CustomWebSecurityConfig.class, HttpSessionConfiguration.class); 19 | // } 20 | //} 21 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/cluster/HttpSessionConfiguration.java: -------------------------------------------------------------------------------- 1 | //package com.beamofsoul.bip.management.cluster; 2 | // 3 | ///** 4 | // * @ClassName HttpSessionConfiguration 5 | // * @Description 使用Redis为集群后HttpSession提供共享的配置类 6 | // * @author MingshuJian 7 | // * @Date 2017年6月7日 上午9:59:57 8 | // * @version 1.0.0 9 | // */ 10 | //@Configuration 11 | //@EnableRedisHttpSession 12 | //public class HttpSessionConfiguration { 13 | // 14 | //// /** 15 | //// * @Title: connectionFactory 16 | //// * @Description: 指定共享HttpSession的Redis服务器的客户端为Lettuce实现 17 | //// * @return LettuceConnectionFactory lettuce连接工厂类 18 | //// */ 19 | //// @Bean 20 | //// public LettuceConnectionFactory connectionFactory() { 21 | //// return new LettuceConnectionFactory(); 22 | //// } 23 | //} 24 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/control/CustomHttpServletRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.management.control; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.nio.charset.Charset; 8 | 9 | import javax.servlet.ReadListener; 10 | import javax.servlet.ServletInputStream; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletRequestWrapper; 13 | 14 | import com.beamofsoul.bip.management.util.HttpServletRequestUtils; 15 | 16 | import lombok.Getter; 17 | 18 | /** 19 | * @ClassName CostomHttpServletRequestWrapper 20 | * @Description 自定义HttpServlet请求包装器 21 | * @author MingshuJian 22 | * @Date 2017年6月2日 上午10:11:17 23 | * @version 1.0.0 24 | */ 25 | public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { 26 | 27 | @Getter 28 | private byte[] requestBody; 29 | public final static Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); 30 | 31 | public CustomHttpServletRequestWrapper(HttpServletRequest request) { 32 | super(request); 33 | requestBody = HttpServletRequestUtils.getRequestBody(request).getBytes(DEFAULT_CHARSET); 34 | } 35 | 36 | public CustomHttpServletRequestWrapper(HttpServletRequest request, String requestBody) { 37 | super(request); 38 | this.setRequestBody(requestBody); 39 | } 40 | 41 | public void setRequestBody(String requestBody) { 42 | this.requestBody = requestBody.getBytes(DEFAULT_CHARSET); 43 | } 44 | 45 | public void setRequestBody(byte[] requestBody) { 46 | this.requestBody = requestBody; 47 | } 48 | 49 | @Override 50 | public BufferedReader getReader() throws IOException { 51 | return new BufferedReader(new InputStreamReader(getInputStream())); 52 | } 53 | 54 | @Override 55 | public ServletInputStream getInputStream() throws IOException { 56 | final ByteArrayInputStream bais = new ByteArrayInputStream(requestBody); 57 | return new ServletInputStream() { 58 | @Override 59 | public boolean isFinished() { 60 | return false; 61 | } 62 | 63 | @Override 64 | public boolean isReady() { 65 | return false; 66 | } 67 | 68 | @Override 69 | public void setReadListener(ReadListener readListener) { 70 | // do nothing... 71 | } 72 | 73 | @Override 74 | public int read() throws IOException { 75 | return bais.read(); 76 | } 77 | }; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/control/CustomJSONReturnSupportFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.management.control; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.InitializingBean; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.method.support.HandlerMethodReturnValueHandler; 10 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; 11 | import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor; 12 | 13 | import lombok.extern.slf4j.Slf4j; 14 | 15 | /** 16 | * @ClassName CustomJSONReturnSupportFactoryBean 17 | * @Description 在RequestResponseBodyMethodProcessor前加入自定义的JSON返回值控制器以支持{@code @JSON}与{@code @JSONS}注解 18 | * @author MingshuJian 19 | * @Date 2017年2月17日 上午10:30:46 20 | * @version 1.0.0 21 | */ 22 | @Slf4j 23 | @Configuration 24 | public class CustomJSONReturnSupportFactoryBean implements InitializingBean { 25 | 26 | @Autowired 27 | private RequestMappingHandlerAdapter adapter; 28 | 29 | @Override 30 | public void afterPropertiesSet() throws Exception { 31 | ListTitle: authenticate
30 | *Description: 根据用户名读取用户身份信息,并提供简单的密码匹配验证
31 | * @param authentication 32 | * @return UsernamePasswordAuthenticationToken 33 | * @throws AuthenticationException 34 | * @see org.springframework.security.authentication.AuthenticationProvider#authenticate(org.springframework.security.core.Authentication) 35 | */ 36 | @Override 37 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 38 | UserDetails user = customUserDetailsService 39 | .loadUserByUsername(authentication.getName()); 40 | 41 | //此处可以增加加密验证或验证码验证等功能 42 | //先判断是否是remember-me登录 43 | if (authentication.getPrincipal() instanceof UserExtension) { 44 | if (!((UserExtension) authentication.getPrincipal()).getPassword().equals(user.getPassword())) 45 | throw new UsernameNotFoundException("密码错误"); 46 | } else if (!authentication.getCredentials().equals(user.getPassword())) { 47 | throw new UsernameNotFoundException("密码错误"); 48 | } 49 | 50 | UsernamePasswordAuthenticationToken result = 51 | new UsernamePasswordAuthenticationToken( 52 | user.getUsername(), 53 | user.getPassword(), 54 | user.getAuthorities()); 55 | result.setDetails(user); 56 | return result; 57 | } 58 | 59 | @Override 60 | public boolean supports(Class> clazz) { 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/security/CustomPermissionEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.management.security; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.security.access.PermissionEvaluator; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.stereotype.Component; 8 | 9 | import com.beamofsoul.bip.management.util.RolePermissionsMapping; 10 | 11 | /** 12 | * @ClassName CustomPermissionEvaluator 13 | * @Description 自定义权限鉴别器 14 | * @author MingshuJian 15 | * @Date 2017年1月19日 下午4:25:34 16 | * @version 1.0.0 17 | */ 18 | @Component 19 | public class CustomPermissionEvaluator implements PermissionEvaluator { 20 | 21 | /* 22 | * (非 Javadoc) 23 | *Title: hasPermission
24 | *Description: 判断用户是否拥有权限
25 | * @param authentication 26 | * @param targetDomainObject 27 | * @param permission 28 | * @return 29 | * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object) 30 | */ 31 | @Override 32 | public boolean hasPermission(Authentication authentication, 33 | Object targetDomainObject, Object permission) { 34 | return RolePermissionsMapping.actionContains(authentication.getAuthorities(), permission); 35 | } 36 | 37 | @Override 38 | public boolean hasPermission(Authentication authentication, 39 | Serializable targetId, String targetType, Object permission) { 40 | // not supported 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/security/CustomSecurityConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.management.security; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | import lombok.Getter; 7 | import lombok.Setter; 8 | 9 | /** 10 | * @ClassName CustomSecurityConfigurationProperties 11 | * @Description 自定义安全配置属性值读取器 12 | * @author MingshuJian 13 | * @Date 2017年1月19日 下午4:27:30 14 | * @version 1.0.0 15 | */ 16 | @Getter 17 | @Setter 18 | @Component 19 | @ConfigurationProperties(prefix = "project.base.security") 20 | public class CustomSecurityConfigurationProperties { 21 | 22 | private String[] adminRoleMatchers; 23 | private String[] adminRoles; 24 | private String[] nonAuthenticatedMatchers; 25 | private String loginPage; 26 | private String defaultLoginSuccessUrl; 27 | private boolean alwaysUseDefaultSuccessUrl; 28 | private String logoutUrl; 29 | private String defaultLogoutSuccessUrl; 30 | private int maximumSessions; 31 | private boolean maxSessionsPreventsLogin; 32 | private String expiredUrl; 33 | private int tokenValiditySeconds; 34 | private String rememberMeParameter; 35 | private String rememberMeCookieName; 36 | private String[] ignoringMatchers; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/beamofsoul/bip/management/util/AnnotationRepositoryNameMapping.java: -------------------------------------------------------------------------------- 1 | package com.beamofsoul.bip.management.util; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.stereotype.Repository; 7 | 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | /** 11 | * @ClassName AnnotationRepositoryClassMapping 12 | * @Description 注解'@Repository'的持久化类映射工具类 13 | * @author MingshuJian 14 | * @Date 2017年4月7日 下午2:37:33 15 | * @version 1.0.0 16 | */ 17 | @Slf4j 18 | public class AnnotationRepositoryNameMapping { 19 | 20 | public static Map