Skip to content

Commit

Permalink
Merge pull request #94 from hs-web/3.0.x
Browse files Browse the repository at this point in the history
3.0.2
  • Loading branch information
zhou-hao committed Oct 12, 2018
2 parents 0382d9b + 55d6468 commit 8a4cfab
Show file tree
Hide file tree
Showing 170 changed files with 929 additions and 341 deletions.
5 changes: 2 additions & 3 deletions hsweb-authorization/hsweb-authorization-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -42,8 +42,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<artifactId>javax.servlet-api</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
Expand Down
25 changes: 16 additions & 9 deletions hsweb-authorization/hsweb-authorization-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
2. 实现数据权限控制
3. 可动态进行权限配置设置

默认仅提供了aop方式的权限控制,控制逻辑如下:

## 授权
使用`hsweb-authorization-api`提供的监听器,类`UserOnSignIn`监听用户授权事件`AuthorizationSuccessEvent`
当用户完成授权(授权方式可自行实现或者使用框架默认的授权方式,主要触发该事件即可).授权通过后会触发该事件.流程如下
1. 完成授权,触发`AuthorizationSuccessEvent`
2. `UserOnSignIn` 收到`AuthorizationSuccessEvent`事件,获取参数`token_type`(默认为`sessionId`),以及授权信息
3. 根据`token_type` 生成token.
4. 将token和授权信息中的userId注册到`UserTokenManager`
5. 将token返回给授权接口

![授权](./img/autz-flow.png "授权")


## 权限控制
1. `AopAuthorizingController` aop拦截所有controller方法(注解了:`Controller`或者`RestController`的类的方法)
2. 在客户端发起请求的时候,将拦截到的方法信息(`MethodInterceptorContext`)传给权限定义解析器(`AopMethodAuthorizeDefinitionParser`)
进行解析
Expand All @@ -14,15 +27,9 @@
5. 默认的权限控制实现`DefaultAuthorizingHandler`,将分别进行RBAC,数据权限,表达式方式的权限控制.
6. 如果授权未通过,则抛出`AccessDenyException`异常

## 授权
使用`hsweb-authorization-api`提供的监听器,类`UserOnSignIn`监听用户授权事件`AuthorizationSuccessEvent`
当用户完成授权(授权方式可自行实现或者使用框架默认的授权方式,主要触发该事件即可).授权通过后会触发该事件.流程如下
![权限控制](./img/autz-handle-flow.png "权限控制")


1. 完成授权,触发`AuthorizationSuccessEvent`
2. `UserOnSignIn` 收到`AuthorizationSuccessEvent`事件,获取参数`token_type`(默认为`sessionId`),以及授权信息
3. 根据`token_type` 生成token.
4. 将token和授权信息中的userId注册到`UserTokenManager`
5. 将token返回给授权接口

## 注销
与授权同理,类`UserOnSignOut`监听`AuthorizationExitEvent` ,当触发事件后,调用`UserTokenManager`移除当前登录的token信息
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions hsweb-authorization/hsweb-authorization-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -81,8 +81,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class DefaultAopMethodAuthorizeDefinitionParser implements AopMethodAutho

private Map<CacheKey, AuthorizeDefinition> cache = new ConcurrentHashMap<>();

private List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomers;
private List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomizers;

private static Set<String> excludeMethodName = new HashSet<>(Arrays.asList("toString", "clone", "hashCode", "getClass"));

@Autowired(required = false)
public void setParserCustomers(List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomers) {
this.parserCustomers = parserCustomers;
public void setParserCustomizers(List<AopMethodAuthorizeDefinitionCustomizerParser> parserCustomizers) {
this.parserCustomizers = parserCustomizers;
}

@Override
Expand All @@ -59,9 +59,9 @@ public AuthorizeDefinition parse(Class target, Method method, MethodInterceptorC
return definition;
}
//使用自定义
if (!CollectionUtils.isEmpty(parserCustomers)) {
definition = parserCustomers.stream()
.map(customer -> customer.parse(target, method, context))
if (!CollectionUtils.isEmpty(parserCustomizers)) {
definition = parserCustomizers.stream()
.map(customizer -> customizer.parse(target, method, context))
.filter(Objects::nonNull)
.findAny().orElse(null);
if (definition instanceof EmptyAuthorizeDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public ResponseMessage<Map<String, Object>> authorize(@RequestParam @ApiParam("
return doLogin(username, password, WebUtil.getParameters(request));
}

/**
* <img src="https://raw.githubusercontent.com/hs-web/hsweb-framework/3.0.x/hsweb-authorization/hsweb-authorization-basic/img/autz-flow.png">
*/
@SneakyThrows
protected ResponseMessage<Map<String, Object>> doLogin(String username, String password, Map<String, ?> parameter) {
Assert.hasLength(username, "用户名不能为空");
Expand Down
5 changes: 2 additions & 3 deletions hsweb-authorization/hsweb-authorization-jwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -35,8 +35,7 @@

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -44,8 +44,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<artifactId>javax.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<!--<relativePath>../../pom.xml</relativePath>-->
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/hsweb-authorization-oauth2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-framework</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-aop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-excel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-ftp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-framework</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-bean/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.hswebframework.ezorm.rdb.render.dialect.Dialect;
import org.hswebframework.web.dao.Dao;
import org.hswebframework.web.dao.mybatis.mapper.SqlTermCustomer;
import org.hswebframework.web.dao.mybatis.mapper.SqlTermCustomizer;
import org.hswebframework.web.dao.mybatis.mapper.dict.DictInTermTypeMapper;
import org.hswebframework.web.dao.mybatis.mapper.dict.DictTermTypeMapper;
import org.mybatis.spring.annotation.MapperScan;
Expand All @@ -34,7 +34,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.Set;

@Configuration
@ComponentScan("org.hswebframework.web.dao.mybatis")
Expand Down Expand Up @@ -65,7 +64,7 @@ public DictInTermTypeMapper dictNotInTermTypeMapper() {
}

@Bean
public BeanPostProcessor SqlTermCustomerRegister() {
public BeanPostProcessor sqlTermCustomizerRegister() {

List<Dialect> dialects = Arrays.asList(
Dialect.H2
Expand All @@ -82,14 +81,14 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof SqlTermCustomer) {
SqlTermCustomer customer = ((SqlTermCustomer) bean);
if (customer.forDialect() != null) {
for (Dialect dialect : customer.forDialect()) {
dialect.setTermTypeMapper(customer.getTermType(), customer);
if (bean instanceof SqlTermCustomizer) {
SqlTermCustomizer customizer = ((SqlTermCustomizer) bean);
if (customizer.forDialect() != null) {
for (Dialect dialect : customizer.forDialect()) {
dialect.setTermTypeMapper(customizer.getTermType(), customizer);
}
} else {
dialects.forEach(dialect -> dialect.setTermTypeMapper(customer.getTermType(), customer));
dialects.forEach(dialect -> dialect.setTermTypeMapper(customizer.getTermType(), customizer));
}
}
return bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author zhouhao
* @since 3.0
*/
public interface MybatisMapperCustomer {
public interface MybatisMapperCustomizer {
String[] getExcludes();

String[] getIncludes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public class MybatisProperties extends org.mybatis.spring.boot.autoconfigure.Myb
*/
private boolean useJpa = true;

private List<MybatisMapperCustomer> mybatisMappers;
private List<MybatisMapperCustomizer> mybatisMappers;

@Autowired(required = false)
public void setMybatisMappers(List<MybatisMapperCustomer> mybatisMappers) {
public void setMybatisMappers(List<MybatisMapperCustomizer> mybatisMappers) {
this.mybatisMappers = mybatisMappers;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public Resource[] resolveMapperLocations() {

if (mybatisMappers != null) {
mybatisMappers.stream()
.map(MybatisMapperCustomer::getIncludes)
.map(MybatisMapperCustomizer::getIncludes)
.flatMap(Arrays::stream)
.forEach(locations::add);
}
Expand All @@ -125,7 +125,7 @@ public Resource[] resolveMapperLocations() {
Set<String> excludes = new HashSet<>();
if (mybatisMappers != null) {
mybatisMappers.stream()
.map(MybatisMapperCustomer::getExcludes)
.map(MybatisMapperCustomizer::getExcludes)
.flatMap(Arrays::stream)
.forEach(excludes::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @since 3.0.0-RC
*/
@AllArgsConstructor
public abstract class AbstractSqlTermCustomer implements SqlTermCustomer {
public abstract class AbstractSqlTermCustomizer implements SqlTermCustomizer {

@Getter
protected final String termType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author zhouhao
* @since 3.0.0-RC
*/
public interface SqlTermCustomer extends Dialect.TermTypeMapper {
public interface SqlTermCustomizer extends Dialect.TermTypeMapper {
String getTermType();

Dialect[] forDialect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
* @since 3.0.0-RC
*/
@Slf4j
public abstract class TreeStructureSqlTermCustomer extends AbstractSqlTermCustomer {
public abstract class TreeStructureSqlTermCustomizer extends AbstractSqlTermCustomizer {
boolean not = false;

boolean parent = false;

public TreeStructureSqlTermCustomer(String termType, boolean not,boolean parent) {
public TreeStructureSqlTermCustomizer(String termType, boolean not, boolean parent) {
super(termType);
this.not = not;
}
Expand Down
Loading

0 comments on commit 8a4cfab

Please sign in to comment.