mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-13 09:01:27 +08:00
优化...
This commit is contained in:
@@ -55,7 +55,7 @@ public interface GenericEntityController<E extends GenericEntity<PK>, PK, Q exte
|
||||
@ApiResponse(code = 403, message = "无权限"),
|
||||
@ApiResponse(code = 409, message = "存在重复的资源")
|
||||
})
|
||||
default ResponseMessage saveOrUpdate(@PathVariable PK id, @RequestBody M data) {
|
||||
default ResponseMessage<PK> saveOrUpdate(@PathVariable PK id, @RequestBody M data) {
|
||||
E entity = getService().createEntity();
|
||||
entity.setId(id);
|
||||
return ResponseMessage.ok(getService().saveOrUpdate(modelToEntity(data, entity)));
|
||||
|
||||
@@ -55,5 +55,10 @@
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework</groupId>
|
||||
<artifactId>hsweb-expands-script</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.hswebframework.web;
|
||||
|
||||
import org.hswebframework.expands.script.engine.DynamicScriptEngine;
|
||||
import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
|
||||
import org.hswebframework.expands.script.engine.ExecuteResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 表达式工具,用户解析表达式为字符串
|
||||
*
|
||||
* @author zhouhao
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ExpressionUtils {
|
||||
|
||||
//表达式提取正则 ${.+?}
|
||||
private static final Pattern PATTERN = Pattern.compile("(?<=\\$\\{)(.+?)(?=})");
|
||||
|
||||
/**
|
||||
* 获取默认的表达式变量
|
||||
*
|
||||
* @return 变量集合
|
||||
*/
|
||||
public static Map<String, Object> getDefaultVar() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认的表达式变量并将制定的变量合并在一起
|
||||
*
|
||||
* @param var 要合并的变量集合
|
||||
* @return 变量集合
|
||||
*/
|
||||
public static Map<String, Object> getDefaultVar(Map<String, Object> var) {
|
||||
Map<String, Object> vars = getDefaultVar();
|
||||
vars.putAll(var);
|
||||
return vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认的变量解析表达式
|
||||
*
|
||||
* @param expression 表达式字符串
|
||||
* @param language 表达式语言
|
||||
* @return 解析结果
|
||||
* @throws Exception 解析错误
|
||||
* @see ExpressionUtils#analytical(String, Map, String)
|
||||
*/
|
||||
public static String analytical(String expression, String language) throws Exception {
|
||||
return analytical(expression, new HashMap<>(), language);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析表达式,表达式使用{@link ExpressionUtils#PATTERN}进行提取<br>
|
||||
* 如调用 analytical("http://${3+2}/test",var,"spel")<br>
|
||||
* 支持的表达式语言:
|
||||
* <ul>
|
||||
* <li>freemarker</li>
|
||||
* <li>spel</li>
|
||||
* <li>ognl</li>
|
||||
* <li>groovy</li>
|
||||
* <li>js</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param expression 表达式字符串
|
||||
* @param vars 变量
|
||||
* @param language 表达式语言
|
||||
* @return 解析结果
|
||||
* @throws Exception 解析错误
|
||||
*/
|
||||
public static String analytical(String expression, Map<String, Object> vars, String language) throws Exception {
|
||||
Matcher matcher = PATTERN.matcher(expression);
|
||||
DynamicScriptEngine engine = DynamicScriptEngineFactory.getEngine(language);
|
||||
if (engine == null) return expression;
|
||||
vars = new HashMap<>(vars);
|
||||
vars.putAll(getDefaultVar());
|
||||
while (matcher.find()) {
|
||||
String real_expression = matcher.group();
|
||||
String e_id = String.valueOf(real_expression.hashCode());
|
||||
if (!engine.compiled(e_id)) {
|
||||
engine.compile(e_id, real_expression);
|
||||
}
|
||||
ExecuteResult result = engine.execute(e_id, vars);
|
||||
if (!result.isSuccess())
|
||||
throw new RuntimeException(result.getMessage(), result.getException());
|
||||
String obj = String.valueOf(result.get());
|
||||
// expression = matcher.replaceFirst(obj);
|
||||
expression = expression.replace("${" + real_expression + "}", obj);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.hswebframework.web;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TODO 完成注释
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
public class RegexUtils {
|
||||
static Set<Character> SPECIAL_WORDS = new HashSet<>(Arrays.asList('\\', '$', '(', ')', '*', '+', '.', '[', ']', '?', '^', '{', '}', '|'));
|
||||
|
||||
public static String escape(String regex) {
|
||||
if (regex == null || regex.isEmpty()) return regex;
|
||||
char[] chars = regex.toCharArray();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (SPECIAL_WORDS.contains(chars[i])) {
|
||||
builder.append('\\');
|
||||
}
|
||||
builder.append(chars[i]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.hsweb.ezorm.rdb.executor.AbstractJdbcSqlExecutor;
|
||||
import org.hsweb.ezorm.rdb.executor.SqlExecutor;
|
||||
import org.hswebframework.web.authorization.Permission;
|
||||
import org.hswebframework.web.authorization.access.DataAccessConfig;
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.commons.entity.factory.EntityFactory;
|
||||
import org.hswebframework.web.dao.datasource.DataSourceHolder;
|
||||
import org.hswebframework.web.dao.datasource.DatabaseType;
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.hsweb.ezorm.rdb.executor.SqlExecutor;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.Permission;
|
||||
import org.hswebframework.web.authorization.access.DataAccessConfig;
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.commons.entity.factory.EntityFactory;
|
||||
import org.hswebframework.web.dao.oauth2.OAuth2ClientDao;
|
||||
import org.hswebframework.web.dao.datasource.DataSourceHolder;
|
||||
|
||||
@@ -111,10 +111,10 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
||||
@Override
|
||||
@CacheEvict(value = USER_CACHE_NAME, key = "#userEntity.id")
|
||||
public String insert(UserEntity userEntity) {
|
||||
//判断用户是否已经存在
|
||||
tryValidateProperty(null == selectByUsername(userEntity.getUsername()), UserEntity.username, "{username_exists}");
|
||||
//用户名合法性验证
|
||||
tryValidateProperty(usernameValidator, UserEntity.username, userEntity.getUsername());
|
||||
//判断用户是否已经存在
|
||||
tryValidateProperty(null == selectByUsername(userEntity.getUsername()), UserEntity.username, "{username_exists}");
|
||||
//密码强度验证
|
||||
tryValidateProperty(passwordStrengthValidator, UserEntity.password, userEntity.getPassword());
|
||||
userEntity.setCreateTime(System.currentTimeMillis());
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
<artifactId>hsweb-authorization-oauth2-auth-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-system-oauth2-server-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
|
||||
@@ -23,8 +23,6 @@ import io.swagger.annotations.ApiOperation;
|
||||
import org.hswebframework.web.AuthorizeException;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
import org.hswebframework.web.authorization.oauth2.api.OAuth2ServerService;
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2AccessEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
|
||||
import org.hswebframework.web.authorization.oauth2.server.support.OAuth2Granter;
|
||||
import org.hswebframework.web.authorization.oauth2.server.support.code.AuthorizationCodeRequest;
|
||||
|
||||
@@ -23,13 +23,8 @@ import io.swagger.annotations.ApiOperation;
|
||||
import org.hswebframework.web.AuthorizeException;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.AuthenticationHolder;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
import org.hswebframework.web.authorization.oauth2.api.OAuth2ServerService;
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2AccessEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
|
||||
import org.hswebframework.web.authorization.oauth2.server.token.AccessTokenService;
|
||||
import org.hswebframework.web.oauth2.model.AuthorizationCodeModel;
|
||||
import org.hswebframework.web.oauth2.model.ImplicitAccessTokenModel;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-authorization-oauth2-auth-server</artifactId>
|
||||
<artifactId>hsweb-system-oauth2-server-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package org.hswebframework.web.dao.oauth2;
|
||||
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.AuthorizationCodeEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.AuthorizationCodeEntity;
|
||||
import org.hswebframework.web.dao.InsertDao;
|
||||
import org.hswebframework.web.dao.dynamic.DeleteByEntityDao;
|
||||
import org.hswebframework.web.dao.dynamic.QueryByEntityDao;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package org.hswebframework.web.dao.oauth2;
|
||||
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2AccessEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2AccessEntity;
|
||||
import org.hswebframework.web.dao.InsertDao;
|
||||
import org.hswebframework.web.dao.dynamic.DeleteByEntityDao;
|
||||
import org.hswebframework.web.dao.dynamic.QueryByEntityDao;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package org.hswebframework.web.dao.oauth2;
|
||||
|
||||
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2ClientEntity;
|
||||
import org.hswebframework.web.dao.CrudDao;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="org.hswebframework.web.dao.oauth2.OAuth2AccessDao">
|
||||
<resultMap id="OAuth2AccessResultMap" type="org.hswebframework.web.authorization.oauth2.api.entity.SimpleOAuth2AccessEntity">
|
||||
<resultMap id="OAuth2AccessResultMap" type="org.hswebframework.web.authorization.oauth2.server.entity.SimpleOAuth2AccessEntity">
|
||||
<result property="clientId" column="client_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="ownerId" column="owner_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="accessToken" column="access_token" javaType="String" jdbcType="VARCHAR"/>
|
||||
@@ -39,7 +39,7 @@
|
||||
<bind name="tableName" value="'s_oauth2_access'"/>
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="org.hswebframework.web.authorization.oauth2.api.entity.SimpleOAuth2ClientEntity">
|
||||
<insert id="insert" parameterType="org.hswebframework.web.commons.entity.Entity">
|
||||
<include refid="config"/>
|
||||
<include refid="BasicMapper.buildInsertSql"/>
|
||||
</insert>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="org.hswebframework.web.dao.oauth2.OAuth2ClientDao">
|
||||
<resultMap id="OAuth2ClientResultMap" type="org.hswebframework.web.authorization.oauth2.api.entity.SimpleOAuth2ClientEntity">
|
||||
<resultMap id="OAuth2ClientResultMap" type="org.hswebframework.web.authorization.oauth2.server.entity.SimpleOAuth2ClientEntity">
|
||||
<id property="id" column="u_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="secret" column="secret" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
|
||||
@@ -43,7 +43,7 @@
|
||||
<bind name="tableName" value="'s_oauth2_client'"/>
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="org.hswebframework.web.authorization.oauth2.api.entity.SimpleOAuth2ClientEntity">
|
||||
<insert id="insert" parameterType="org.hswebframework.web.commons.entity.Entity">
|
||||
<include refid="config"/>
|
||||
<include refid="BasicMapper.buildInsertSql"/>
|
||||
</insert>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="org.hswebframework.web.dao.oauth2.AuthorizationCodeDao">
|
||||
<resultMap id="AuthorizationCodeResultMap" type="org.hswebframework.web.authorization.oauth2.api.entity.SimpleAuthorizationCodeEntity">
|
||||
<resultMap id="AuthorizationCodeResultMap" type="org.hswebframework.web.authorization.oauth2.server.entity.SimpleAuthorizationCodeEntity">
|
||||
<result property="clientId" column="client_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="userId" column="user_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="code" column="code" javaType="String" jdbcType="VARCHAR"/>
|
||||
@@ -37,7 +37,7 @@
|
||||
<bind name="tableName" value="'s_oauth2_auth_code'"/>
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="org.hswebframework.web.authorization.oauth2.api.entity.SimpleOAuth2ClientEntity">
|
||||
<insert id="insert" parameterType="org.hswebframework.web.commons.entity.Entity">
|
||||
<include refid="config"/>
|
||||
<include refid="BasicMapper.buildInsertSql"/>
|
||||
</insert>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 http://www.hswebframework.org
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>hsweb-system-oauth2-server</artifactId>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>hsweb-system-oauth2-server-entity</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-authorization-oauth2-auth-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
package org.hswebframework.web.oauth2.server.simple;
|
||||
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.OAuth2AccessEntity;
|
||||
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2AccessEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
|
||||
import org.hswebframework.web.authorization.oauth2.server.token.AccessTokenService;
|
||||
import org.hswebframework.web.commons.entity.factory.EntityFactory;
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package org.hswebframework.web.oauth2.server.simple;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.hswebframework.web.authorization.oauth2.api.entity.AuthorizationCodeEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.entity.AuthorizationCodeEntity;
|
||||
import org.hswebframework.web.authorization.oauth2.server.support.code.AuthorizationCode;
|
||||
import org.hswebframework.web.authorization.oauth2.server.support.code.AuthorizationCodeRequest;
|
||||
import org.hswebframework.web.authorization.oauth2.server.support.code.AuthorizationCodeService;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<module>hsweb-system-oauth2-server-starter</module>
|
||||
<module>hsweb-system-oauth2-server-dao</module>
|
||||
<module>hsweb-system-oauth2-server-model</module>
|
||||
<module>hsweb-system-oauth2-server-entity</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>hsweb-system-oauth2-server</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user