Skip to content

Commit

Permalink
Merge pull request #10 from Frodez/0.2-alpha
Browse files Browse the repository at this point in the history
0.2 alpha
  • Loading branch information
Frodez authored Mar 20, 2019
2 parents efd60ae + fd4a738 commit ace91cc
Show file tree
Hide file tree
Showing 70 changed files with 1,827 additions and 438 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>

<!-- mysql-connector-java -->
<dependency>
Expand Down Expand Up @@ -171,7 +179,6 @@
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.16.0</version>
</dependency>

</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion src/main/generator/jdt/EnhanceSourceCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class EnhanceSourceCodeGenerator {

private static final String PATH =
"file:/D:/Code/Eclipse/workspace/BlogManagePlatform/src/main/java/frodez/dao/param/user/AddPermissionParam.java";
"file:/D:/Code/Eclipse/workspace/BlogManagePlatform/src/main/java/frodez/dao/param/task/AddTask.java";

public static void main(String[] args) throws URISyntaxException, IOException, MalformedTreeException,
BadLocationException {
Expand Down
8 changes: 4 additions & 4 deletions src/main/generator/mybatis/generator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
</javaTypeResolver>

<!-- model包路径 -->
<javaModelGenerator targetPackage="frodez.dao.model.user"
<javaModelGenerator targetPackage="frodez.dao.model.task"
targetProject="BlogManagePlatform/src/main/java" />
<!-- mapper.xml包路径 -->
<sqlMapGenerator targetPackage="frodez.dao.mapper.user"
<sqlMapGenerator targetPackage="frodez.dao.mapper.task"
targetProject="BlogManagePlatform/src/main/java" />
<!-- mapper包路径 -->
<javaClientGenerator targetPackage="frodez.dao.mapper.user"
<javaClientGenerator targetPackage="frodez.dao.mapper.task"
targetProject="BlogManagePlatform/src/main/java" type="XMLMAPPER" />
<!-- 表配置 -->
<table tableName="tb_role_permission" domainObjectName="RolePermission">
<table tableName="tb_spring_task" domainObjectName="Task">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
</context>
Expand Down
9 changes: 4 additions & 5 deletions src/main/generator/security/InitPermissionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import frodez.util.http.URLMatcher;
import frodez.util.json.JSONUtil;
import frodez.util.reflect.ReflectUtil;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.properties.PropertyUtil;
import frodez.util.spring.ContextUtil;
import frodez.util.spring.PropertyUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
Expand All @@ -32,18 +32,17 @@ public class InitPermissionService {
public static void main(String[] args) {
SpringApplication.run(BlogManagePlatformApplication.class, args);
PermissionMapper permissionMapper = ContextUtil.get(PermissionMapper.class);
String errorPath = PropertyUtil.get(PropertyKey.Web.BASE_PATH) + "/error";
List<Permission> permissionList = new ArrayList<>();
Date date = new Date();
BeanFactoryUtils.beansOfTypeIncludingAncestors(ContextUtil.context(), HandlerMapping.class, true, false)
.values().stream().filter((iter) -> {
return iter instanceof RequestMappingHandlerMapping;
}).map((iter) -> {
return RequestMappingHandlerMapping.class.cast(iter).getHandlerMethods().entrySet();
return ((RequestMappingHandlerMapping) iter).getHandlerMethods().entrySet();
}).flatMap(Collection::stream).forEach((entry) -> {
String requestUrl = PropertyUtil.get(PropertyKey.Web.BASE_PATH) + entry.getKey().getPatternsCondition()
.getPatterns().stream().findFirst().get();
if (!URLMatcher.needVerify(requestUrl) || requestUrl.equals(errorPath)) {
if (!URLMatcher.needVerify(requestUrl)) {
return;
}
requestUrl = requestUrl.substring(PropertyUtil.get(PropertyKey.Web.BASE_PATH).length());
Expand Down
47 changes: 22 additions & 25 deletions src/main/java/frodez/BlogManagePlatformApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
import org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration;
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
Expand All @@ -73,7 +71,6 @@
import org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration;
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
Expand All @@ -87,26 +84,27 @@
import org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration;
import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration;
import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration;
import org.springframework.jms.annotation.EnableJms;
import tk.mybatis.spring.annotation.MapperScan;

/**
* 启动类(根据情况精简了加载类)
* @author Frodez
* @date 2019-01-07
*/
@MapperScan(basePackages = "frodez.dao.mapper")
@SpringBootApplication(exclude = { ActiveMQAutoConfiguration.class, ArtemisAutoConfiguration.class,
BatchAutoConfiguration.class, CacheAutoConfiguration.class, CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class, CassandraReactiveDataAutoConfiguration.class,
CassandraReactiveRepositoriesAutoConfiguration.class, CassandraRepositoriesAutoConfiguration.class,
ClientHttpConnectorAutoConfiguration.class, CloudServiceConnectorsAutoConfiguration.class,
CouchbaseAutoConfiguration.class, CouchbaseDataAutoConfiguration.class,
CouchbaseReactiveDataAutoConfiguration.class, CouchbaseReactiveRepositoriesAutoConfiguration.class,
CouchbaseRepositoriesAutoConfiguration.class, XADataSourceAutoConfiguration.class,
WebSocketServletAutoConfiguration.class, WebSocketMessagingAutoConfiguration.class,
WebSocketReactiveAutoConfiguration.class, WebServicesAutoConfiguration.class,
WebServiceTemplateAutoConfiguration.class, WebFluxAutoConfiguration.class, WebClientAutoConfiguration.class,
ThymeleafAutoConfiguration.class, TaskSchedulingAutoConfiguration.class, SessionAutoConfiguration.class,
@EnableJms
@MapperScan(basePackages = { "frodez.dao.mapper" })
@SpringBootApplication(exclude = { ArtemisAutoConfiguration.class, BatchAutoConfiguration.class,
CacheAutoConfiguration.class, CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
CassandraReactiveDataAutoConfiguration.class, CassandraReactiveRepositoriesAutoConfiguration.class,
CassandraRepositoriesAutoConfiguration.class, ClientHttpConnectorAutoConfiguration.class,
CloudServiceConnectorsAutoConfiguration.class, CouchbaseAutoConfiguration.class,
CouchbaseDataAutoConfiguration.class, CouchbaseReactiveDataAutoConfiguration.class,
CouchbaseReactiveRepositoriesAutoConfiguration.class, CouchbaseRepositoriesAutoConfiguration.class,
XADataSourceAutoConfiguration.class, WebSocketServletAutoConfiguration.class,
WebSocketMessagingAutoConfiguration.class, WebSocketReactiveAutoConfiguration.class,
WebServicesAutoConfiguration.class, WebServiceTemplateAutoConfiguration.class, WebFluxAutoConfiguration.class,
WebClientAutoConfiguration.class, ThymeleafAutoConfiguration.class, SessionAutoConfiguration.class,
SolrAutoConfiguration.class, SolrRepositoriesAutoConfiguration.class, SendGridAutoConfiguration.class,
UserDetailsServiceAutoConfiguration.class, RepositoryRestMvcAutoConfiguration.class,
RestClientAutoConfiguration.class, ReactiveWebServerFactoryAutoConfiguration.class,
Expand All @@ -120,15 +118,14 @@
MessageSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class, LdapRepositoriesAutoConfiguration.class,
LdapAutoConfiguration.class, KafkaAutoConfiguration.class, JtaAutoConfiguration.class, JsonbAutoConfiguration.class,
JpaRepositoriesAutoConfiguration.class, JooqAutoConfiguration.class, JndiDataSourceAutoConfiguration.class,
JndiConnectionFactoryAutoConfiguration.class, JmsAutoConfiguration.class, JestAutoConfiguration.class,
JerseyAutoConfiguration.class, JdbcRepositoriesAutoConfiguration.class, IntegrationAutoConfiguration.class,
InfluxDbAutoConfiguration.class, HypermediaAutoConfiguration.class, HttpHandlerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, HazelcastJpaDependencyAutoConfiguration.class,
HazelcastAutoConfiguration.class, H2ConsoleAutoConfiguration.class, GsonAutoConfiguration.class,
GroovyTemplateAutoConfiguration.class, FreeMarkerAutoConfiguration.class, FlywayAutoConfiguration.class,
ErrorWebFluxAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class, EmbeddedLdapAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class,
ElasticsearchAutoConfiguration.class })
JndiConnectionFactoryAutoConfiguration.class, JestAutoConfiguration.class, JerseyAutoConfiguration.class,
JdbcRepositoriesAutoConfiguration.class, IntegrationAutoConfiguration.class, InfluxDbAutoConfiguration.class,
HypermediaAutoConfiguration.class, HttpHandlerAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
HazelcastJpaDependencyAutoConfiguration.class, HazelcastAutoConfiguration.class, H2ConsoleAutoConfiguration.class,
GsonAutoConfiguration.class, GroovyTemplateAutoConfiguration.class, FreeMarkerAutoConfiguration.class,
FlywayAutoConfiguration.class, ErrorWebFluxAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class,
EmbeddedLdapAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class, ElasticsearchAutoConfiguration.class })
public class BlogManagePlatformApplication {

public static void main(String[] args) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frodez/config/aop/request/LimitUserAOP.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frodez.util.aop.AspectUtil;
import frodez.util.beans.result.Result;
import frodez.util.constant.setting.DefTime;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.MVCUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.aspectj.lang.ProceedingJoinPoint;
Expand All @@ -27,7 +27,7 @@ public class LimitUserAOP {
@Around("@annotation(frodez.config.aop.request.annotation.Limit)")
public Object limit(ProceedingJoinPoint point) throws Throwable {
Limit limit = AspectUtil.annotation(point, Limit.class);
RateLimiter limiter = limitCache.computeIfAbsent(ContextUtil.request().getRequestURI(), i -> RateLimiter.create(
RateLimiter limiter = limitCache.computeIfAbsent(MVCUtil.request().getRequestURI(), i -> RateLimiter.create(
limit.value()));
if (!limiter.tryAcquire(limit.timeout(), DefTime.UNIT)) {
return Result.busy();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frodez/config/aop/request/RepeatAOP.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frodez.util.aop.AspectUtil;
import frodez.util.beans.result.Result;
import frodez.util.http.ServletUtil;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.MVCUtil;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class RepeatAOP {
*/
@Around("@annotation(frodez.config.aop.request.annotation.RepeatLock)")
public Object process(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = ContextUtil.request();
HttpServletRequest request = MVCUtil.request();
String key = KeyGenerator.servletKey(AspectUtil.fullMethodName(point), request);
try {
if (checker.check(key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frodez/config/aop/request/TimeoutAOP.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import frodez.util.aop.AspectUtil;
import frodez.util.beans.result.Result;
import frodez.util.http.ServletUtil;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.MVCUtil;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class TimeoutAOP {
*/
@Around("@annotation(frodez.config.aop.request.annotation.TimeoutLock)")
public Object process(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = ContextUtil.request();
HttpServletRequest request = MVCUtil.request();
TimeoutLock timeoutLock = AspectUtil.annotation(point, TimeoutLock.class);
String key = KeyGenerator.servletKey(AspectUtil.fullMethodName(point), request);
if (checker.check(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import frodez.config.aop.request.checker.facade.AutoChecker;
import frodez.config.cache.CacheProperties;
import frodez.util.constant.setting.DefTime;
import frodez.util.spring.context.ContextUtil;
import java.util.Objects;
import frodez.util.spring.ContextUtil;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
* 自动超时型重复请求检查GUAVACACHE实现
Expand All @@ -26,7 +26,7 @@ public class AutoGuavaChecker implements AutoChecker {
private void init() {
cache = CacheBuilder.newBuilder().expireAfterAccess(ContextUtil.get(CacheProperties.class).getAutoGuavaChecker()
.getTimeout(), DefTime.UNIT).build();
Objects.requireNonNull(cache);
Assert.notNull(cache, "cache must not be null");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import frodez.config.aop.request.checker.facade.ManualChecker;
import frodez.config.cache.CacheProperties;
import frodez.util.constant.setting.DefTime;
import frodez.util.spring.context.ContextUtil;
import java.util.Objects;
import frodez.util.spring.ContextUtil;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
* 阻塞型重复请求检查HASHMAP实现
Expand All @@ -26,7 +26,7 @@ public class ManualGuavaChecker implements ManualChecker {
private void init() {
cache = CacheBuilder.newBuilder().expireAfterAccess(ContextUtil.get(CacheProperties.class)
.getManualGuavaChecker().getTimeout(), DefTime.UNIT).build();
Objects.requireNonNull(cache);
Assert.notNull(cache, "cache must not be null");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import frodez.config.security.settings.SecurityProperties;
import frodez.util.common.EmptyUtil;
import frodez.util.http.URLMatcher;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.ContextUtil;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.DependsOn;
Expand All @@ -20,6 +19,7 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.FilterInvocation;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
* 权限匹配管理器
Expand All @@ -36,7 +36,7 @@ public class AuthorityManager implements AccessDecisionManager {
private void init() {
SecurityProperties properties = ContextUtil.get(SecurityProperties.class);
defaultDeniedRoles = Arrays.asList(new SecurityConfig(properties.getAuth().getDeniedRole()));
Objects.requireNonNull(defaultDeniedRoles);
Assert.notNull(defaultDeniedRoles, "defaultDeniedRoles must not be null");
}

/**
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/frodez/config/security/auth/AuthoritySource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import frodez.dao.mapper.user.PermissionMapper;
import frodez.dao.model.user.Permission;
import frodez.util.constant.user.PermissionTypeEnum;
import frodez.util.spring.context.ContextUtil;
import frodez.util.spring.ContextUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -13,17 +13,16 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpMethod;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
* 获取权限资源
Expand All @@ -35,11 +34,8 @@
public class AuthoritySource implements FilterInvocationSecurityMetadataSource {

/**
* 用户授权服务
* 默认无权限角色
*/
@Autowired
private PermissionMapper permissionMapper;

private Collection<ConfigAttribute> defaultDeniedRoles;

/**
Expand Down Expand Up @@ -79,10 +75,10 @@ public void refresh() {
*/
@PostConstruct
private void init() {
SecurityProperties properties = ContextUtil.get(SecurityProperties.class);
defaultDeniedRoles = Arrays.asList(new SecurityConfig(properties.getAuth().getDeniedRole()));
defaultDeniedRoles = Arrays.asList(new SecurityConfig(ContextUtil.get(SecurityProperties.class).getAuth()
.getDeniedRole()));
if (allCache == null) {
List<Permission> permissions = permissionMapper.selectAll();
List<Permission> permissions = ContextUtil.get(PermissionMapper.class).selectAll();
allCache = permissions.stream().map((iter) -> {
return new SecurityConfig(iter.getName());
}).collect(Collectors.toList());
Expand Down Expand Up @@ -124,10 +120,10 @@ private void init() {
urlTypeCache.put(url, typeMap);
}
}
Objects.requireNonNull(defaultDeniedRoles);
Objects.requireNonNull(allCache);
Objects.requireNonNull(urlCache);
Objects.requireNonNull(urlTypeCache);
Assert.notNull(defaultDeniedRoles, "defaultDeniedRoles must not be null");
Assert.notNull(allCache, "allCache must not be null");
Assert.notNull(urlCache, "urlCache must not be null");
Assert.notNull(urlTypeCache, "urlTypeCache must not be null");
}

/**
Expand Down
Loading

0 comments on commit ace91cc

Please sign in to comment.