listUserDataFiltersByOptIdAndMethod
27 | (String topUnit, String sUserCode, String sOptid, String sOptMethod);
28 |
29 | /**
30 | * 创建用户数据范围过滤器,和上面的方法结合使用
31 | * @param userInfo JSONObject 用户信息
32 | * @param topUnit 用户租户代码
33 | * @param currentUnit 用户当前机构
34 | * @return DataPowerFilter
35 | */
36 | DataPowerFilter createUserDataPowerFilter(UserInfo userInfo, String topUnit, String currentUnit);
37 |
38 | /**
39 | * 创建用户数据范围过滤器,和上面的方法结合使用
40 | * @param userDetails CentitUserDetails
41 | * @return DataPowerFilter
42 | */
43 | DataPowerFilter createUserDataPowerFilter(CentitUserDetails userDetails);
44 | }
45 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/common/GlobalConstValue.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | public abstract class GlobalConstValue {
4 | //'all'代表返回所有租户的内容,这是topunit这个属性作为租户可以有其他的解释
5 | public static final String NO_TENANT_TOP_UNIT = "all";
6 | //用户没有登录获取不到租户
7 | public static final String UNKNOW_TENANT_TOP_UNIT = "none";
8 | //系统管理员、系统维护相关业务的租户为 system;称为系统租户代码
9 | public static final String SYSTEM_TENANT_TOP_UNIT = "system";
10 | //全局应用归属租户
11 | public static final String GLOBAL_TENANT_TOP_UNIT = "global";
12 |
13 | //用户类型数据字典
14 | public static final String DATA_CATALOG_UESR_TYPE = "UserType";
15 | //在多租户系统中用户类型数据字典为 租户代码+这个后缀
16 | public static final String DATA_CATALOG_UESR_TYPE_SUFFIX = "-UT";
17 | //机构类型数据字典
18 | public static final String DATA_CATALOG_UNIT_TYPE = "UnitType";
19 | //在多租户系统中机构类型数据字典为 租户代码+这个后缀
20 | public static final String DATA_CATALOG_UNIT_TYPE_SUFFIX = "-DT";
21 |
22 | //用户职务数据字典
23 | public static final String DATA_CATALOG_RANK = "RankType";
24 | //在多租户系统中用户职务数据字典为 租户代码+这个后缀
25 | public static final String DATA_CATALOG_RANK_SUFFIX = "-RT";
26 | //用户岗位数据字典
27 | public static final String DATA_CATALOG_STATION = "StationType";
28 | //在多租户系统中用户岗位数据字典为 租户代码+这个后缀
29 | public static final String DATA_CATALOG_STATION_SUFFIX = "-ST";
30 | //用户职级字典
31 | public static final String DATA_CATALOG_POSTRANK = "PostRank";
32 | //在多租户系统中用户职级字典为 租户代码+这个后缀
33 | public static final String DATA_CATALOG_POSTRANK_SUFFIX = "-PR";
34 | }
35 |
--------------------------------------------------------------------------------
/framework-security/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | framework-parent
7 | com.centit.framework
8 | ${revision}
9 |
10 | 4.0.0
11 |
12 | framework-security
13 | com.centit.framework:framework-security
14 | jar
15 | 框架安全配置类
16 |
17 |
18 |
19 | com.centit.framework
20 | framework-core
21 | ${project.version}
22 |
23 |
24 |
25 |
26 | org.springframework.security
27 | spring-security-config
28 |
29 |
30 |
31 | org.springframework.security
32 | spring-security-taglibs
33 |
34 |
35 |
36 | javax.servlet
37 | javax.servlet-api
38 | provided
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/framework-session-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | framework-parent
7 | com.centit.framework
8 | ${revision}
9 |
10 | 4.0.0
11 |
12 | framework-session-core
13 | com.centit.framework:framework-session-core
14 | jar
15 | 框架的Session管理包
16 |
17 |
18 | com.centit.support
19 | centit-database
20 | ${project.version}
21 |
22 |
23 |
24 | org.springframework.session
25 | spring-session-core
26 |
27 |
28 |
29 | com.centit.framework
30 | framework-core
31 | ${project.version}
32 |
33 |
34 |
35 | javax.servlet
36 | javax.servlet-api
37 | provided
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/framework-session-jdbc/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | framework-parent
7 | com.centit.framework
8 | ${revision}
9 |
10 | 4.0.0
11 |
12 | framework-session-jdbc
13 |
14 |
15 |
16 | com.centit.framework
17 | framework-session-core
18 | ${project.version}
19 |
20 |
21 |
22 | org.springframework.session
23 | spring-session-jdbc
24 |
25 |
26 |
27 | com.mysql
28 | mysql-connector-j
29 | compile
30 |
31 |
32 |
33 |
34 | com.oracle
35 | ojdbc6
36 | provided
37 |
38 |
39 |
40 | com.h2database
41 | h2
42 | provided
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/framework-core-web/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | D:/Projects/RunData/webim_home/logs
6 | mylog
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 1
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/operationlog/RecordOperationLog.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.operationlog;
2 |
3 | import com.centit.framework.model.basedata.OperationLog;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | @Target(ElementType.METHOD)
11 | @Retention(RetentionPolicy.RUNTIME)
12 | public @interface RecordOperationLog {
13 | /**
14 | *
15 | * @return 记录操作内容表达式,理论上这个不能为空
16 | */
17 | String content() default "";
18 |
19 | /**
20 | *
21 | * @return 日志等级
22 | */
23 | String level() default OperationLog.LEVEL_INFO;
24 |
25 | /**
26 | *
27 | * @return 业务编码
28 | */
29 | String operation() default "";
30 |
31 | /**
32 | *
33 | * @return 操作方法
34 | */
35 | String method() default "";
36 | /**
37 | *
38 | * @return 操作对象主键 表达式
39 | */
40 | String tag() default "";
41 |
42 | /**
43 | * 优先级高于 appendRequest
44 | * @return 更改后对象
45 | */
46 | String newValue() default "";
47 | /**
48 | * 优先级高于 returnValueAsOld
49 | * @return 更改前对象
50 | */
51 | String oldValue() default "";
52 |
53 | /**
54 | * 是否记录操作时间
55 | * @return boolean
56 | */
57 | boolean timing() default false;
58 |
59 | /**
60 | * 是否将HttpRequest中的参数放入newValue中,
61 | * 一般查询都需要将这个 参数设置为true
62 | * @return boolean
63 | */
64 | boolean appendRequest() default false;
65 |
66 | /**
67 | * 将方法的返回值放到 old 字段
68 | * @return boolean
69 | */
70 | boolean returnValueAsOld() default false;
71 | }
72 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/filter/AssertUserLoginFilter.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.filter;
2 |
3 | import com.centit.framework.common.JsonResultUtils;
4 | import com.centit.framework.common.ResponseData;
5 | import com.centit.framework.common.WebOptUtils;
6 | import com.centit.framework.model.basedata.UserInfo;
7 |
8 | import javax.servlet.*;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 |
13 | public class AssertUserLoginFilter implements Filter {
14 |
15 | @Override
16 | public void init(FilterConfig filterConfig) throws ServletException {
17 |
18 | }
19 |
20 | @Override
21 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
22 | ServletException {
23 | if(request!=null && response!=null) {
24 | if(request instanceof HttpServletRequest) {
25 | HttpServletRequest httpRequest = (HttpServletRequest)request;
26 | String requestUrl = httpRequest.getRequestURI();
27 | if(!requestUrl.contains("no-auth")) {
28 | UserInfo userInfo = WebOptUtils.getCurrentUserInfo(httpRequest);
29 | if (userInfo == null) {
30 | JsonResultUtils.writeHttpErrorMessage(ResponseData.ERROR_UNAUTHORIZED,
31 | ResponseData.ERROR_NOT_LOGIN_MSG, (HttpServletResponse) response);
32 | return;
33 | }
34 | }
35 | }
36 | if(chain!=null) {
37 | chain.doFilter(request, response);
38 | }
39 | }
40 | }
41 |
42 | @Override
43 | public void destroy() {
44 |
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/basedata/WorkGroupParameter.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.basedata;
2 |
3 | import io.swagger.annotations.ApiModelProperty;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Embeddable;
7 | import javax.validation.constraints.NotBlank;
8 |
9 | /**
10 | * create by scaffold 2020-08-18 13:38:15
11 | *
12 | * @author codefan@sina.com
13 | *
14 | * 项目组成员
15 | */
16 | @Embeddable
17 | public class WorkGroupParameter implements java.io.Serializable {
18 | private static final long serialVersionUID = 1L;
19 |
20 | @ApiModelProperty(value = "组id")
21 | @Column(name = "group_id")
22 | @NotBlank
23 | private String groupId;
24 |
25 | @ApiModelProperty(value = "用户代码")
26 | @NotBlank
27 | @Column(name = "user_code")
28 | private String userCode;
29 |
30 | @ApiModelProperty(value = "角色代码")
31 | @NotBlank
32 | @Column(name = "role_code")
33 | private String roleCode;
34 |
35 | public WorkGroupParameter() {
36 | }
37 |
38 | public WorkGroupParameter(String groupId, String userCode, String roleCode) {
39 | this.groupId = groupId;
40 | this.userCode = userCode;
41 | this.roleCode = roleCode;
42 | }
43 |
44 | public String getGroupId() {
45 | return groupId;
46 | }
47 |
48 | public void setGroupId(String groupId) {
49 | this.groupId = groupId;
50 | }
51 |
52 | public String getUserCode() {
53 | return userCode;
54 | }
55 |
56 | public void setUserCode(String userCode) {
57 | this.userCode = userCode;
58 | }
59 |
60 | public String getRoleCode() {
61 | return roleCode;
62 | }
63 |
64 | public void setRoleCode(String roleCode) {
65 | this.roleCode = roleCode;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/core/controller/SmartDateFormat.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.core.controller;
2 |
3 | import com.centit.support.algorithm.DatetimeOpt;
4 | import org.apache.commons.lang3.StringUtils;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.text.DateFormatSymbols;
9 | import java.text.ParsePosition;
10 | import java.text.SimpleDateFormat;
11 | import java.util.Date;
12 | import java.util.Locale;
13 |
14 | public class SmartDateFormat extends SimpleDateFormat{
15 |
16 | private static final long serialVersionUID = 1L;
17 | private static Logger logger = LoggerFactory.getLogger(SmartDateFormat.class);
18 | public SmartDateFormat() {
19 | super();
20 | }
21 |
22 | public SmartDateFormat(String pattern)
23 | {
24 | super(pattern);
25 | }
26 |
27 |
28 | public SmartDateFormat(String pattern, Locale locale)
29 | {
30 | super(pattern,locale);
31 | }
32 |
33 | public SmartDateFormat(String pattern, DateFormatSymbols formatSymbols)
34 | {
35 | super(pattern,formatSymbols);
36 | }
37 |
38 | @Override
39 | public Date parse(String source, ParsePosition pos){
40 | if (StringUtils.isBlank(source)) {
41 | return null;
42 | }
43 |
44 | int start = pos.getIndex();
45 | int errorIndex = pos.getErrorIndex();
46 | Date parseDate = null;
47 | try{
48 | parseDate = super.parse(source, pos);
49 | }catch(RuntimeException e){
50 | logger.error(e.getMessage(),e);
51 | parseDate = null;
52 | }
53 | if(parseDate!=null)
54 | return parseDate;
55 |
56 | pos.setErrorIndex(errorIndex);
57 |
58 | int nlen = source.length();
59 | pos.setIndex(start + nlen);
60 | return DatetimeOpt.smartPraseDate(source);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/components/impl/TextOperationLogWriterImpl.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.components.impl;
2 |
3 | import com.centit.framework.components.OperationLogCenter;
4 | import com.centit.framework.model.adapter.OperationLogWriter;
5 | import com.centit.framework.model.basedata.OperationLog;
6 | import com.centit.support.algorithm.DatetimeOpt;
7 | import com.centit.support.file.TxtLogFile;
8 |
9 | import java.util.List;
10 |
11 | public class TextOperationLogWriterImpl implements OperationLogWriter{
12 |
13 | //@PostConstruct
14 | public void init(){
15 | OperationLogCenter.initOperationLogWriter(this);
16 | //OperationLogCenter.registerOperationLogWriter(this);
17 | }
18 |
19 | private String optLogHomePath;
20 |
21 | public void setOptLogHomePath(String optLogPath){
22 | if(optLogPath.endsWith("/") || optLogPath.endsWith("\\")){
23 | this.optLogHomePath = optLogPath.substring(0,optLogPath.length()-1);
24 | }else {
25 | this.optLogHomePath = optLogPath;
26 | }
27 | }
28 |
29 | public String getCurrentLogPath(){
30 | return optLogHomePath+"/D"
31 | +DatetimeOpt.convertDateToString(
32 | DatetimeOpt.currentUtilDate(),"yyyyMMdd")+".log";
33 | }
34 |
35 | @Override
36 | public void save(OperationLog optLog) {
37 | TxtLogFile.writeLog(getCurrentLogPath(), optLog.toString(),
38 | true,true);
39 | }
40 |
41 | @Override
42 | public void save(List optLogs) {
43 | String logFilePath = getCurrentLogPath();
44 | TxtLogFile logger = new TxtLogFile();
45 | logger.openLogFile(logFilePath);
46 | for(OperationLog optLog : optLogs) {
47 | logger.writeLog(optLog.toString(),
48 | true, true);
49 | }
50 | logger.closeLogFile();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/basedata/OptMethodUrlMap.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.basedata;
2 |
3 | import org.hibernate.validator.constraints.Length;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.Id;
8 | import javax.persistence.Table;
9 |
10 | @Entity
11 | @Table(name = "F_V_OPTDEF_URL_MAP")
12 | public class OptMethodUrlMap implements java.io.Serializable {
13 |
14 | private static final long serialVersionUID = 396021378825483579L;
15 |
16 | @Id
17 | @Column(name = "OPT_CODE")
18 | //@GeneratedValue(generator = "assignedGenerator")
19 | private String optCode;// 操作代码
20 |
21 | @Column(name = "OPT_DEF_URL")
22 | @Length(max = 50)
23 | private String optDefUrl; // 操作名称
24 |
25 | @Column(name = "OPT_REQ")
26 | @Length(max = 6)
27 | private String optReq;
28 |
29 |
30 | public OptMethodUrlMap() {
31 | }
32 |
33 | /**
34 | * minimal constructor
35 | * @param optcode String
36 | */
37 | public OptMethodUrlMap(String optcode) {
38 | this.optCode = optcode;
39 | }
40 |
41 |
42 |
43 | public OptMethodUrlMap(String optcode, String optdefurl, String optmethod) {
44 | this.optCode = optcode;
45 | this.optDefUrl = optdefurl;
46 | this.optReq = optmethod;
47 | }
48 |
49 | public String getOptCode() {
50 | return optCode;
51 | }
52 |
53 | public void setOptCode(String optCode) {
54 | this.optCode = optCode;
55 | }
56 |
57 | public String getOptDefUrl() {
58 | return optDefUrl;
59 | }
60 |
61 | public void setOptDefUrl(String optDefUrl) {
62 | this.optDefUrl = optDefUrl;
63 | }
64 |
65 | public String getOptReq() {
66 | return optReq;
67 | }
68 |
69 | public void setOptReq(String optReq) {
70 | this.optReq = optReq;
71 | }
72 |
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/security/CentitPasswordEncoder.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.security;
2 |
3 |
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | /**
7 | * Created by codefan on 17-1-20.
8 | */
9 | @SuppressWarnings("deprecation")
10 | public interface CentitPasswordEncoder {
11 |
12 | /**
13 | *
14 | * @param password 密码
15 | * @param minLength 最小长度
16 | * @return 返回值 < 0 不符合要求, 1~4 之间为密码强度
17 | */
18 | static int checkPasswordStrength(String password, int minLength){
19 | if(StringUtils.isBlank(password)){
20 | return -1;
21 | }
22 | int passwrodLen = password.length();
23 | int mathLength = passwrodLen>=minLength? 1 : -1;
24 | int hasDigit = 0, hasLowLetter = 0, hasUpLetter = 0, hasOtherLetter = 0;
25 | for(int i=0; i='0' && c<='9'){
28 | hasDigit = 1;
29 | } else if(c>='a' && c<='z'){
30 | hasLowLetter = 1;
31 | } else if(c>='A' && c<='Z'){
32 | hasUpLetter = 1;
33 | } else {
34 | hasOtherLetter = 1;
35 | }
36 | }
37 | return mathLength * (hasDigit + hasLowLetter + hasUpLetter + hasOtherLetter);
38 | }
39 |
40 | static int checkPasswordStrength(String password){
41 | return checkPasswordStrength(password, 8);
42 | }
43 |
44 | String encodePassword(String rawPass, Object salt);
45 | /**
46 | * 在 encodePassword 前疊加 预处理
47 | * @param rawPass 明文原始密码
48 | * @param salt 盐
49 | * @return 密文
50 | */
51 | String createPassword(String rawPass, Object salt);
52 |
53 | boolean isPasswordValid(String encodedPassword, String rawPass, Object salt);
54 |
55 | default boolean isCorrectPasswordFormat(String password){
56 | return true;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/framework-session-jdbc/src/main/java/com/centit/framework/session/jdbc/CentitSessionJdbcRepo.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.session.jdbc;
2 |
3 | import com.centit.framework.session.CentitSessionRepo;
4 | import org.apache.commons.lang3.StringUtils;
5 | import org.springframework.session.FindByIndexNameSessionRepository;
6 | import org.springframework.session.Session;
7 |
8 | import java.util.Map;
9 |
10 | public class CentitSessionJdbcRepo implements CentitSessionRepo {
11 |
12 | private FindByIndexNameSessionRepository sessionRepository;
13 |
14 | public CentitSessionJdbcRepo(FindByIndexNameSessionRepository sessionRepository){
15 | this.sessionRepository = sessionRepository;
16 | }
17 |
18 | @Override
19 | public void kickSessionByName(String loginName, String escapeSessionId) {
20 | Map mapSession = this.sessionRepository.findByPrincipalName(loginName);
21 | if(mapSession!=null) {
22 | for (Map.Entry ent : mapSession.entrySet()) {
23 | if(!StringUtils.equals(escapeSessionId, ent.getValue().getId())) {
24 | this.sessionRepository.deleteById(ent.getValue().getId());
25 | }
26 | }
27 | }
28 | }
29 |
30 | @Override
31 | public void kickSessionByName(String loginName) {
32 | Map mapSession = this.sessionRepository.findByPrincipalName(loginName);
33 | if(mapSession!=null) {
34 | for (Map.Entry ent : mapSession.entrySet()) {
35 | this.sessionRepository.deleteById(ent.getValue().getId());
36 | }
37 | }
38 | }
39 |
40 | @Override
41 | public void kickSessionByPrincipal(String principalName) {
42 | kickSessionByName(principalName);
43 | }
44 |
45 | @Override
46 | public Session findById(String id) {
47 | return this.sessionRepository.findById(id);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/framework-session-redis/src/main/java/com/centit/framework/session/redis/CentitSessionRedisRepo.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.session.redis;
2 |
3 | import com.centit.framework.session.CentitSessionRepo;
4 | import org.apache.commons.lang3.StringUtils;
5 | import org.springframework.session.Session;
6 | import org.springframework.session.data.redis.RedisIndexedSessionRepository;
7 |
8 | import java.util.Map;
9 |
10 | public class CentitSessionRedisRepo implements CentitSessionRepo {
11 |
12 | private RedisIndexedSessionRepository sessionRepository;
13 | public CentitSessionRedisRepo(RedisIndexedSessionRepository sessionRepository){
14 | this.sessionRepository = sessionRepository;
15 | }
16 |
17 | @Override
18 | public void kickSessionByName(String loginName, String escapeSessionId) {
19 | Map mapSession = this.sessionRepository.findByPrincipalName(loginName);
20 | if(mapSession!=null) {
21 | for (Map.Entry ent : mapSession.entrySet()) {
22 | if(!StringUtils.equals(escapeSessionId, ent.getValue().getId())) {
23 | this.sessionRepository.deleteById(ent.getValue().getId());
24 | }
25 | }
26 | }
27 | }
28 |
29 | @Override
30 | public void kickSessionByName(String loginName) {
31 | Map mapSession = this.sessionRepository.findByPrincipalName(loginName);
32 | if(mapSession!=null) {
33 | for (Map.Entry ent : mapSession.entrySet()) {
34 | this.sessionRepository.deleteById(ent.getValue().getId());
35 | }
36 | }
37 | }
38 |
39 | @Override
40 | public void kickSessionByPrincipal(String principalName) {
41 | kickSessionByName(principalName);
42 | }
43 |
44 | @Override
45 | public Session findById(String id) {
46 | return this.sessionRepository.findById(id);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/core/controller/ObjectAppendProperties.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.core.controller;
2 |
3 | import com.centit.framework.common.ResponseData;
4 | import com.centit.framework.common.ToResponseData;
5 | import com.centit.support.algorithm.CollectionsOpt;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 |
9 | import java.util.Map;
10 |
11 | /**
12 | * 功能,在返回结果对象中添加额外的属性,比如数据字典映射值等等
13 | * @param 模板对象,可以是任何类型
14 | */
15 | @ApiModel(description = "在返回结果对象中添加额外的属性,比如数据字典映射值等等")
16 | public class ObjectAppendProperties implements ToResponseData {
17 |
18 | @ApiModelProperty(value = "结果对象")
19 | private T object;
20 | @ApiModelProperty(value = "额外属性")
21 | private Map extendProperties;
22 |
23 | /**
24 | * 在返回结果对象中添加额外的属性,比如数据字典映射值等等
25 | * @param obj 对象
26 | * @param extendProperties 额外属性
27 | */
28 | public ObjectAppendProperties(T obj, Map extendProperties){
29 | this.object = obj;
30 | this.extendProperties = extendProperties;
31 | }
32 |
33 | /**
34 | * 在返回结果对象中添加额外的属性,比如数据字典映射值等等
35 | * @param obj 对象
36 | * @param extendProperties 额外属性
37 | * @param 对象类型
38 | * @return ToResponseData 用于 WarpUpResponseBody 的处理
39 | */
40 | public static ObjectAppendProperties
41 | create(D obj, Map extendProperties){
42 | return new ObjectAppendProperties(obj, extendProperties);
43 | }
44 |
45 | @Override
46 | public ResponseData toResponseData(){
47 | if(object==null){
48 | return ResponseData.makeResponseData(extendProperties);
49 | }
50 | Map objectMap = CollectionsOpt.objectToMap(object);
51 | if(extendProperties!=null && extendProperties.size()>0) {
52 | objectMap.putAll(extendProperties);
53 | }
54 | return ResponseData.makeResponseData(objectMap);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/common/ResponseSingleData.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | /**
4 | * 响应 http 请求 返回的单个数据
5 | */
6 | public class ResponseSingleData implements ResponseData{
7 |
8 | private static final long serialVersionUID = 1L;
9 | /**
10 | * 返回代码,0 表示正确,其他的为错误代码
11 | */
12 | private int code;
13 |
14 | /**
15 | * 返回消息提示 ,code为0时是提示,其他为 错误提示
16 | */
17 | private String message;
18 |
19 | /**
20 | * 返回的详细数据, 可能是需要回显的参数,也可能是验证的错误提示
21 | */
22 | protected Object data;
23 |
24 | public ResponseSingleData() {
25 | this.code = RESULT_OK;
26 | this.message = "OK";
27 | }
28 |
29 | public ResponseSingleData(int nCode) {
30 | this.code = nCode;
31 | this.message = nCode==RESULT_OK ? "OK" : "ERROR";
32 | }
33 |
34 | public ResponseSingleData(String message) {
35 | this.code = RESULT_OK;
36 | this.message = message;
37 | }
38 |
39 | public ResponseSingleData(int nCode, String message) {
40 | this.code = nCode;
41 | this.message = message;
42 | }
43 |
44 | public static ResponseSingleData makeResponseData(Object objValue){
45 | ResponseSingleData resData = new ResponseSingleData();
46 | resData.setData(objValue);
47 | return resData;
48 | }
49 |
50 | public int getCode() {
51 | return code;
52 | }
53 |
54 | public void setCode(int resCode) {
55 | this.code = resCode;
56 | }
57 |
58 | public String getMessage() {
59 | return message;
60 | }
61 |
62 | public void setMessage(String resMessage) {
63 | this.message = resMessage;
64 | }
65 |
66 | public Object getData() {
67 | return data;
68 | }
69 |
70 | public Object setData(Object objValue) {
71 | Object oldObj = this.data;
72 | this.data = objValue;
73 | return oldObj;
74 | }
75 |
76 | @Override
77 | public String toString(){
78 | return toJSONString();
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/security/CentitUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.security;
2 |
3 | import org.springframework.security.core.GrantedAuthority;
4 | import org.springframework.security.core.userdetails.UserDetailsService;
5 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
6 |
7 | import java.util.Collection;
8 |
9 | public interface CentitUserDetailsService
10 | extends UserDetailsService
11 | /*AuthenticationUserDetailsService*/{
12 | /**
13 | * 获取用户 权限,角色名数组
14 | * @param loginname loginname
15 | * @return 用户 权限,角色名数组
16 | * @throws UsernameNotFoundException UsernameNotFoundException
17 | */
18 | Collection extends GrantedAuthority> loadUserAuthorities(String loginname) throws UsernameNotFoundException;
19 |
20 | /**
21 | * 获取用户信息 by loginname,用户的登录名
22 | * @param loginname loginname
23 | * @return 用户信息
24 | */
25 | CentitUserDetails loadDetailsByLoginName(String loginname);
26 |
27 | /**
28 | * 获取用户信息 by userCode,用户的主键
29 | * @param userCode userCode
30 | * @return 用户信息
31 | */
32 | CentitUserDetails loadDetailsByUserCode(String userCode);
33 |
34 | /**
35 | * 获取用户信息 by RegEmail,用户的主键
36 | * @param regEmail regEmail
37 | * @return 用户信息
38 | */
39 | CentitUserDetails loadDetailsByRegEmail(String regEmail);
40 |
41 | /**
42 | * 获取用户信息 by RegCellPhone,用户的主键
43 | * @param regCellPhone regCellPhone
44 | * @return 用户信息
45 | */
46 | CentitUserDetails loadDetailsByRegCellPhone(String regCellPhone);
47 | /**
48 | * 设置用户参数 (用户登录时 回写表单中的附加信息,比如用户选择的站点、语言等等信息)
49 | * @param userCode userCode
50 | * @param paramCode paramCode
51 | * @param paramValue paramValue
52 | * @param paramClass paramClass
53 | * @param paramName paramName
54 | */
55 | void saveUserSetting(String userCode, String paramCode,String paramValue,
56 | String paramClass, String paramName);
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/framework-security/src/main/java/com/centit/framework/security/AjaxAuthenticationEntryPoint.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.security;
2 |
3 | import com.centit.framework.common.JsonResultUtils;
4 | import com.centit.framework.common.ResponseData;
5 | import com.centit.framework.common.ResponseSingleData;
6 | import com.centit.framework.common.WebOptUtils;
7 | import org.springframework.http.HttpStatus;
8 | import org.springframework.security.core.AuthenticationException;
9 | import org.springframework.security.web.AuthenticationEntryPoint;
10 | import org.springframework.security.web.authentication.HttpStatusEntryPoint;
11 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
12 |
13 | import javax.servlet.ServletException;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 | import java.io.IOException;
17 |
18 | public class AjaxAuthenticationEntryPoint implements AuthenticationEntryPoint {
19 | private AuthenticationEntryPoint browse;
20 | private AuthenticationEntryPoint api;
21 |
22 | public AjaxAuthenticationEntryPoint(String loginFormUrl) {
23 | this.browse = new LoginUrlAuthenticationEntryPoint(loginFormUrl);
24 | this.api = new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED);
25 | }
26 |
27 | @Override
28 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
29 | throws IOException, ServletException {
30 | if(WebOptUtils.isAjax(request)){
31 | if(WebOptUtils.exceptionNotAsHttpError) {
32 | ResponseSingleData responseData =
33 | new ResponseSingleData(ResponseData.ERROR_UNAUTHORIZED,
34 | "未登录!");
35 | JsonResultUtils.writeResponseDataAsJson(responseData, response);
36 | } else {
37 | api.commence(request, response, authException);
38 | }
39 | }else {
40 | browse.commence(request, response, authException);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/framework-filter/src/main/java/com/centit/framework/filter/GZIPFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2003 Jayson Falkner (jayson@jspinsider.com)
3 | * This code is from "Servlets and JavaServer pages; the J2EE Web Tier",
4 | * http://www.jspbook.com. You may freely use the code both commercially
5 | * and non-commercially. If you like the code, please pick up a copy of
6 | * the book and help support the authors, development of more free code,
7 | * and the JSP/Servlet/J2EE community.
8 | */
9 | package com.centit.framework.filter;
10 |
11 | import javax.servlet.*;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.io.IOException;
15 |
16 | /**
17 | * 网站常使用GZIP压缩算法对网页内容进行压缩,然后传给浏览器,以减小数据传输量,提高响应速度。浏览器接收到GZIP压缩数据后会自动解压并正确显示。
18 | * GZIP加速常用于解决网速慢的瓶颈。
19 | *
20 | * 压缩Filter中需要先判断客户浏览器时候支持GZip自动解压,如果支持,则进行GZIP压缩,否则不压缩。判断的依据是浏览器提供的Header信息
21 | *
22 | *
23 | * @author hx
24 | * 2015-8-4
25 | */
26 | public class GZIPFilter implements Filter {
27 |
28 | public void doFilter(ServletRequest req, ServletResponse res,
29 | FilterChain chain) throws IOException, ServletException {
30 | if (req instanceof HttpServletRequest) {
31 | HttpServletRequest request = (HttpServletRequest) req;
32 | HttpServletResponse response = (HttpServletResponse) res;
33 | //支持的编码方式
34 | String ae = request.getHeader("accept-encoding");
35 | //如果客户浏览器支持GZIP格式,则使用GZIP压缩数据
36 | if (ae != null && ae.indexOf("gzip") != -1) {
37 | // System.out.println("GZIP supported, compressing.");
38 | GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(
39 | response);
40 | chain.doFilter(req, wrappedResponse);//doFilter,使用自定义的response
41 | wrappedResponse.finishResponse();//输出压缩数据
42 | return;
43 | }
44 | chain.doFilter(req, res);//否则不压缩
45 | }
46 | }
47 |
48 | public void init(FilterConfig filterConfig) {
49 | // noop
50 | }
51 |
52 | public void destroy() {
53 | // noop
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/common/ResponseMapData.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * 响应 http 请求 返回的数据,可以用Map返回多个数据
8 | */
9 | @SuppressWarnings("unused")
10 | public class ResponseMapData extends ResponseSingleData {
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | public ResponseMapData() {
15 | super();
16 | }
17 |
18 | public ResponseMapData(int nCode) {
19 | super(nCode);
20 | }
21 |
22 | public ResponseMapData(String message) {
23 | super(message);
24 | }
25 |
26 | public ResponseMapData(int nCode, String message) {
27 | super(nCode, message);
28 | }
29 |
30 | public static ResponseMapData makeResponseData(Map resMapData){
31 | ResponseMapData resData = new ResponseMapData();
32 | resData.setData(resMapData);
33 | return resData;
34 | }
35 |
36 | public Map getData() {
37 | return (Map) data;
38 | }
39 |
40 | @Deprecated
41 | public Object setData(Object objValue) {
42 | if(! (objValue instanceof Map)){
43 | throw new RuntimeException("参数必须式 Map 类型");
44 | }
45 | Object oldObj = this.data;
46 | this.data = objValue;
47 | return oldObj;
48 | }
49 |
50 | public Map setData(Map objValue) {
51 | Object oldObj = data;
52 | this.data = objValue;
53 | return (Map)oldObj;
54 | }
55 |
56 | public void addResponseData(String sKey, Object objValue) {
57 | if(data == null ){
58 | data = new LinkedHashMap<>();
59 | }
60 | ((Map) data).put(sKey, objValue);
61 | }
62 |
63 | public Object getResponseData(String sKey) {
64 | if( this.data == null){
65 | return null;
66 | }
67 | return ((Map) data).get(sKey);
68 | }
69 |
70 | @Override
71 | public String toString(){
72 | return toJSONString();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/components/impl/UserUnitMapTranslate.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.components.impl;
2 |
3 | import com.centit.framework.model.adapter.UserUnitVariableTranslate;
4 | import com.centit.support.algorithm.ReflectionOpt;
5 | import com.centit.support.network.HtmlFormUtils;
6 |
7 | import java.util.HashSet;
8 | import java.util.Map;
9 | import java.util.Set;
10 |
11 | public class UserUnitMapTranslate implements UserUnitVariableTranslate {
12 |
13 | private Map varMap;
14 | //public
15 | public UserUnitMapTranslate(){
16 | varMap = null;
17 | }
18 |
19 | public UserUnitMapTranslate(Map varMap) {
20 | this.varMap = varMap;
21 | }
22 |
23 | /**
24 | * 返回权限表达式中的自定义变量对应的用户组
25 | *
26 | * @param varName 自定义变量
27 | * @return 权限表达式中的自定义变量对应的用户组
28 | */
29 | public Set getUsersVariable(String varName){
30 | if(varMap==null)
31 | return null;
32 |
33 | Object res = ReflectionOpt.attainExpressionValue(varMap, varName);
34 | String [] us = HtmlFormUtils.getParameterStringArray(res);
35 | if(us==null)
36 | return null;
37 | Set uSet = new HashSet<>();
38 | for (String s : us){
39 | uSet.add(s);
40 | }
41 | return uSet;
42 | }
43 |
44 | /**
45 | * 返回机构表达式中的自定义变量对应的机构组
46 | *
47 | * @param varName 自定义变量
48 | * @return 机构表达式中的自定义变量对应的机构组
49 | */
50 | public Set getUnitsVariable(String varName){
51 | return getUsersVariable(varName);
52 | }
53 |
54 | /**
55 | * 变量名--变量值的转变
56 | * 变量 是用 ${变量名}
57 | * 如果这个变量不存在,返回空字符串 "''"
58 | *
59 | * @param varName varName
60 | * @return 变量值的转变
61 | */
62 | @Override
63 | public Object getVarValue(String varName) {
64 | if(varMap==null)
65 | return null;
66 | return ReflectionOpt.attainExpressionValue(varMap, varName);
67 | //return StringBaseOpt.objectToString(res);
68 | }
69 |
70 | public Map getVarMap() {
71 | return varMap;
72 | }
73 |
74 | public void setVarMap(Map varMap) {
75 | this.varMap = varMap;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/core/aop/ResubmitLock.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.core.aop;
2 |
3 | import org.apache.commons.codec.digest.DigestUtils;
4 |
5 | import java.util.Objects;
6 | import java.util.concurrent.ConcurrentHashMap;
7 | import java.util.concurrent.ScheduledThreadPoolExecutor;
8 | import java.util.concurrent.ThreadPoolExecutor;
9 | import java.util.concurrent.TimeUnit;
10 |
11 | /**
12 | * 重复提交锁
13 | */
14 | public final class ResubmitLock {
15 |
16 |
17 | private static final ConcurrentHashMap LOCK_CACHE = new ConcurrentHashMap<>(200);
18 | private static final ScheduledThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(5, new ThreadPoolExecutor.DiscardPolicy());
19 |
20 |
21 | // private static final Cache CACHES = CacheBuilder.newBuilder()
22 | // 最大缓存 100 个
23 | // .maximumSize(1000)
24 | // 设置写缓存后 5 秒钟过期
25 | // .expireAfterWrite(5, TimeUnit.SECONDS)
26 | // .build();
27 |
28 |
29 | private ResubmitLock() {
30 | }
31 |
32 | /**
33 | * 静态内部类 单例模式
34 | *
35 | * @return
36 | */
37 | private static class SingletonInstance {
38 | private static final ResubmitLock INSTANCE = new ResubmitLock();
39 | }
40 |
41 | public static ResubmitLock getInstance() {
42 | return SingletonInstance.INSTANCE;
43 | }
44 |
45 |
46 | public static String handleKey(String param) {
47 | return DigestUtils.md5Hex(param == null ? "" : param);
48 | }
49 |
50 | /**
51 | * 加锁 putIfAbsent 是原子操作保证线程安全
52 | *
53 | * @param key 对应的key
54 | * @param value
55 | * @return
56 | */
57 | public boolean lock(final String key, Object value) {
58 | return Objects.isNull(LOCK_CACHE.putIfAbsent(key, value));
59 | }
60 |
61 | /**
62 | * 延时释放锁 用以控制短时间内的重复提交
63 | *
64 | * @param lock 是否需要解锁
65 | * @param key 对应的key
66 | * @param delaySeconds 延时时间
67 | */
68 | public void unLock(final boolean lock, final String key, final int delaySeconds) {
69 | if (lock) {
70 | EXECUTOR.schedule(() -> {
71 | LOCK_CACHE.remove(key);
72 | }, delaySeconds, TimeUnit.SECONDS);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/security/CentitSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.security;
2 |
3 | import org.springframework.security.access.ConfigAttribute;
4 | import org.springframework.security.access.SecurityConfig;
5 | import org.springframework.util.Assert;
6 | import org.springframework.util.StringUtils;
7 |
8 | import java.io.Serializable;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class CentitSecurityConfig implements ConfigAttribute, Serializable {
13 | private final String attrib;
14 |
15 | // ~ Constructors
16 | // ===================================================================================================
17 | public CentitSecurityConfig(){
18 | attrib="";
19 | }
20 | public CentitSecurityConfig(String config) {
21 | this.attrib = config;
22 | }
23 |
24 | // ~ Methods
25 | // ========================================================================================================
26 |
27 | @Override
28 | public boolean equals(Object obj) {
29 | if (obj instanceof ConfigAttribute) {
30 | ConfigAttribute attr = (ConfigAttribute) obj;
31 |
32 | return this.attrib.equals(attr.getAttribute());
33 | }
34 |
35 | return false;
36 | }
37 |
38 | @Override
39 | public String getAttribute() {
40 | return this.attrib;
41 | }
42 |
43 | @Override
44 | public int hashCode() {
45 | return this.attrib.hashCode();
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return this.attrib;
51 | }
52 |
53 | public static List createListFromCommaDelimitedString(String access) {
54 | return createList(StringUtils.commaDelimitedListToStringArray(access));
55 | }
56 |
57 | public static List createList(String... attributeNames) {
58 | Assert.notNull(attributeNames, "You must supply an array of attribute names");
59 | List attributes = new ArrayList<>(
60 | attributeNames.length);
61 |
62 | for (String attribute : attributeNames) {
63 | attributes.add(new SecurityConfig(attribute.trim()));
64 | }
65 |
66 | return attributes;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/framework-security/src/main/java/com/centit/framework/security/HostIpFilterDecisionManager.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.security;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.security.access.AccessDecisionManager;
6 | import org.springframework.security.access.AccessDeniedException;
7 | import org.springframework.security.access.ConfigAttribute;
8 | import org.springframework.security.authentication.InsufficientAuthenticationException;
9 | import org.springframework.security.core.Authentication;
10 | import org.springframework.security.web.FilterInvocation;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 | import java.util.Collection;
14 |
15 | /**
16 | *
17 | * 这个过滤器仅对请求的IP进行过滤,对符合条件的IP的所有请求放行
18 | *
19 | * @author codefan
20 | * 2015年11月30日
21 | */
22 | //@Component("hostIpFilterDecisionManagerBean")
23 | public class HostIpFilterDecisionManager implements AccessDecisionManager {
24 | protected static final Logger logger = LoggerFactory.getLogger(HostIpFilterDecisionManager.class);
25 |
26 | // In this method, need to compare authentication with configAttributes.
27 | // 1, A object is a URL, a filter was find permission configuration by this
28 | // URL, and pass to here.
29 | // 2, Check authentication has attribute in permission configuration
30 | // (configAttributes)
31 | // 3, If not match corresponding authentication, throw a
32 | // AccessDeniedException.
33 | @Override
34 | public void decide(Authentication authentication, Object object, Collection configAttributes)
35 | throws AccessDeniedException, InsufficientAuthenticationException {
36 |
37 | if(configAttributes!=null && configAttributes.size()>0)
38 | return;
39 |
40 | //没有权限,组织提示信息。
41 | FilterInvocation fi = (FilterInvocation) object;
42 | HttpServletRequest request = fi.getHttpRequest();
43 | String urlIp = request.getRemoteHost();
44 | logger.error(urlIp+" 是不允许访问这个服务的。");
45 | throw new AccessDeniedException(urlIp+" 是不允许访问这个服务的。");
46 | }
47 |
48 | public boolean supports(ConfigAttribute arg0) {
49 | return true;
50 | }
51 |
52 | public boolean supports(Class> arg0) {
53 | return true;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/common/ValidatorUtils.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | import com.centit.support.common.ObjectException;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import javax.validation.ConstraintViolation;
7 | import javax.validation.Validation;
8 | import javax.validation.Validator;
9 | import javax.validation.ValidatorFactory;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.Set;
13 | /**
14 | * 常用验证工具,适用于控制器及业务层中判断主键或关键对象且需要中断执行流程
15 | */
16 | public class ValidatorUtils {
17 |
18 | private static Validator validator = null;
19 |
20 | private static synchronized Validator getDefaultValidator(){
21 | if(validator==null){
22 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
23 | validator = factory.getValidator();
24 | }
25 | return validator;
26 | }
27 | /**
28 | * 判断空对象
29 | *
30 | * @param object 任意对象
31 | * @param errorText 返回错误信息
32 | */
33 | public static void validatorNullObject(Object object, String errorText) {
34 | if (null == object) {
35 | throw new ObjectException(ObjectException.NULL_EXCEPTION,errorText);
36 | }
37 | }
38 |
39 | /**
40 | * 判断空白字符串
41 | *
42 | * @param str 字符串
43 | * @param errorText 返回错误信息
44 | */
45 | public static void validatorBlank(String str, String errorText) {
46 | if (StringUtils.isBlank(str)) {
47 | throw new ObjectException(ObjectException.BLANK_EXCEPTION,errorText);
48 | }
49 | }
50 |
51 | /**
52 | * 调用Hibernate注解进行验证
53 | * @param 持久对象
54 | * @param po 持久对象
55 | * @return Map 错误信息
56 | */
57 | public static Map validatorEntityPo(Po po) {
58 | Validator validator = getDefaultValidator();
59 |
60 | Set> constraintViolations = validator.validate(po);
61 | Map errMsg = new HashMap<>();
62 | for(ConstraintViolation constraintViolation : constraintViolations) {
63 | errMsg.put(String.valueOf(constraintViolation.getPropertyPath()),
64 | constraintViolation.getMessage());
65 | }
66 | return errMsg;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/framework-security/src/main/java/com/centit/framework/security/DaoInvocationSecurityMetadataSource.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.security;
2 |
3 | import org.springframework.security.access.ConfigAttribute;
4 | import org.springframework.security.web.FilterInvocation;
5 | import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 | import java.util.Collection;
9 |
10 | //@Component("centitSecurityMetadataSource")
11 | public class DaoInvocationSecurityMetadataSource
12 | implements FilterInvocationSecurityMetadataSource {
13 | //private static final Logger logger = LoggerFactory.getLogger(DaoInvocationSecurityMetadataSource.class);
14 | //private static boolean logDebug = logger.isDebugEnabled();
15 | @Override
16 | public boolean supports(Class> clazz) {
17 | if (FilterInvocation.class.isAssignableFrom(clazz)) {
18 | return true;
19 | }
20 | return false;
21 | }
22 |
23 | @Override
24 | public Collection getAllConfigAttributes() {
25 | return null;
26 | }
27 |
28 | @Override
29 | // According to a URL, Find out permission configuration of this URL.
30 | public Collection getAttributes(Object object) throws IllegalArgumentException {
31 | // guess object is a URL.
32 | if ((object == null) || !this.supports(object.getClass())) {
33 | throw new IllegalArgumentException("对不起,目标对象不是类型");
34 | }
35 | FilterInvocation fi = (FilterInvocation) object;
36 | HttpServletRequest request = fi.getHttpRequest();
37 | String requestUrl = fi.getRequestUrl();
38 | /* if (logDebug) {
39 | logger.debug("通过权限过滤器 请求url = " + requestUrl + " 请求类型 = " + request.getMethod());
40 | }*/
41 | return CentitSecurityMetadata.matchUrlToRole(requestUrl, request);
42 | /* Collection needRoles = CentitSecurityMetadata.matchUrlToRole(requestUrl,request);
43 | if(needRoles==null && requestUrl.contains("/mainframe/logincas")){
44 | needRoles = new ArrayList<>(1);
45 | needRoles.add(new SecurityConfig(CentitSecurityMetadata.ROLE_PREFIX + SecurityContextUtils.PUBLIC_ROLE_CODE));
46 | }
47 | return needRoles;*/
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/common/OptionItem.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | import com.centit.support.algorithm.StringBaseOpt;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import java.io.Serializable;
7 |
8 | public class OptionItem implements Serializable {
9 | private static final long serialVersionUID = 1L;
10 |
11 | private String name;
12 |
13 | private Serializable value;
14 | private Serializable group;
15 |
16 | public OptionItem(){
17 |
18 | }
19 | public OptionItem(String name){
20 | this.name = name;
21 | this.value = name;
22 | }
23 |
24 | public OptionItem(String name,Serializable value){
25 | this.name = name;
26 | this.value = value;
27 | }
28 |
29 | public OptionItem(String name,Serializable value,Serializable group){
30 | this.name = name;
31 | this.value = value;
32 | this.group = group;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public Serializable getValue() {
44 | return value;
45 | }
46 |
47 | public void setValue(Serializable value) {
48 | this.value = value;
49 | }
50 |
51 | public Serializable getGroup() {
52 | return group;
53 | }
54 |
55 | public void setGroup(Serializable group) {
56 | this.group = group;
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | if(name==null)
62 | return 0;
63 | return name.hashCode();
64 | }
65 |
66 | @Override
67 | public boolean equals(Object obj) {
68 | if(this==obj || value==obj)
69 | return true;
70 | if(obj==null)
71 | return false;
72 |
73 | if(obj instanceof String){
74 | return StringUtils.equals(StringBaseOpt.objectToString(value),
75 | (String)obj);
76 | }
77 |
78 | if(obj instanceof OptionItem){
79 | return StringUtils.equals(StringBaseOpt.objectToString(value),
80 | StringBaseOpt.objectToString(((OptionItem)obj).getValue()));
81 | }
82 |
83 | return StringUtils.equals(StringBaseOpt.objectToString(value),
84 | StringBaseOpt.objectToString(obj));
85 | }
86 |
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/adapter/MessageSender.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.adapter;
2 |
3 | import com.centit.framework.common.ResponseData;
4 | import com.centit.framework.model.basedata.NoticeMessage;
5 | import com.centit.support.common.DoubleAspect;
6 |
7 | import java.util.Collection;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * 系统消息发送接口
13 | * 系统的内置的两个发送消息的实现,可以通过以下代码引入
14 | Resource(name = "innerMessageManager")
15 | NotNull
16 | private MessageSender innerMessageSender;
17 |
18 | Resource(name = "emailMessageSender")
19 | NotNull
20 | private MessageSender emailMessageSender;
21 | 注意:去掉@后的空格
22 | * @author codefan
23 | */
24 | public interface MessageSender {
25 |
26 | /**
27 | * 发送内部系统消息
28 | *
29 | * @param sender 发送人内部用户编码
30 | * @param receiver 接收人内部用户编码
31 | * @param message 消息主体
32 | * @return "OK" 表示成功,其他的为错误信息
33 | */
34 | ResponseData sendMessage(String sender, String receiver, NoticeMessage message);
35 |
36 | /**
37 | * 批量发送内部系统消息
38 | *
39 | * @param sender 发送人内部用户编码
40 | * @param receivers 接收人内部用户编码
41 | * @param message 消息主体
42 | * @return "OK" 表示成功,其他的为错误信息
43 | */
44 | default ResponseData sendMessage(String sender, Collection receivers, NoticeMessage message){
45 | int error = 0; int success = 0;
46 | Map result = new HashMap<>();
47 | for (String receiver : receivers){
48 | ResponseData response = sendMessage(sender, receiver, message);
49 | if(response.getCode() !=0){
50 | error ++;
51 | result.put(receiver, response.getMessage());
52 | } else {
53 | success ++;
54 | }
55 | }
56 | String msgStr = "一共发送" + (error+success) + "条消息,成功"+success+"条,失败"+error+"条。";
57 | int resCode = error == 0? 0:(success==0?2:3);
58 | return ResponseData.makeErrorMessageWithData(result, resCode, msgStr);
59 | }
60 |
61 | /**
62 | * 广播信息
63 | * @param sender 发送人内部用户编码
64 | * @param message 消息主体
65 | * @param userInline DoubleAspec.ON 在线用户 OFF 离线用户 BOTH 所有用户
66 | * @return 默认没有实现
67 | */
68 | default ResponseData broadcastMessage(String sender, NoticeMessage message, DoubleAspect userInline){
69 | return ResponseData.errorResponse;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/framework-filter/src/main/java/com/centit/framework/filter/CacheResponseWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2003 Jayson Falkner (jayson@jspinsider.com)
3 | * This code is from "Servlets and JavaServer pages; the J2EE Web Tier",
4 | * http://www.jspbook.com. You may freely use the code both commercially
5 | * and non-commercially. If you like the code, please pick up a copy of
6 | * the book and help support the authors, development of more free code,
7 | * and the JSP/Servlet/J2EE community.
8 | */
9 | package com.centit.framework.filter;
10 |
11 | import javax.servlet.ServletOutputStream;
12 | import javax.servlet.http.HttpServletResponse;
13 | import javax.servlet.http.HttpServletResponseWrapper;
14 | import java.io.IOException;
15 | import java.io.OutputStream;
16 | import java.io.OutputStreamWriter;
17 | import java.io.PrintWriter;
18 |
19 | public class CacheResponseWrapper
20 | extends HttpServletResponseWrapper {
21 | protected HttpServletResponse origResponse = null;
22 | protected ServletOutputStream stream = null;
23 | protected PrintWriter writer = null;
24 | protected OutputStream cache = null;
25 |
26 | public CacheResponseWrapper(HttpServletResponse response,
27 | OutputStream cache) {
28 | super(response);
29 | origResponse = response;
30 | this.cache = cache;
31 | }
32 |
33 | public ServletOutputStream createOutputStream()
34 | throws IOException {
35 | return (new CacheResponseStream(origResponse, cache));
36 | }
37 |
38 | public void flushBuffer() throws IOException {
39 | stream.flush();
40 | }
41 |
42 | public ServletOutputStream getOutputStream()
43 | throws IOException {
44 | if (writer != null) {
45 | throw new IllegalStateException(
46 | "getWriter() has already been called!");
47 | }
48 |
49 | if (stream == null)
50 | stream = createOutputStream();
51 | return (stream);
52 | }
53 |
54 | public PrintWriter getWriter() throws IOException {
55 | if (writer != null) {
56 | return (writer);
57 | }
58 |
59 | if (stream != null) {
60 | throw new IllegalStateException(
61 | "getOutputStream() has already been called!");
62 | }
63 |
64 | stream = createOutputStream();
65 | writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
66 | return (writer);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/framework-filter/src/test/resources/xss_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 | true
7 |
8 | true
9 |
10 | true
11 |
12 | true
13 |
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | .*[S|s][C|c][R|r][I|i][P|p][T|t]>.*]]>
43 |
44 |
45 |
46 |
47 |
48 | .*[S|s][C|c][R|r][I|i][P|p][T|t]>[[.&[^a]]|[|a|\n|\r\n|\r|\u0085|\u2028|\u2029]]*]]>
49 |
50 |
--------------------------------------------------------------------------------
/framework-core/src/test/java/com/centit/framework/test/TestPasswordEncoder.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.test;
2 |
3 | import com.centit.framework.security.StandardPasswordEncoderImpl;
4 | import org.junit.Test;
5 |
6 | /**
7 | * Created by codefan on 17-6-29.
8 | */
9 | public class TestPasswordEncoder {
10 | @Test
11 | public void testCentitCrypt() {
12 | //093ce7e6c0476c39ce4a46ce53dbcc98b53c30c6baf92e98
13 | System.out.println(new StandardPasswordEncoderImpl().encodePassword("000000", "salt"));
14 | //System.out.println(CentitCrypt.cryptPassword2("000000", "salt", 11));
15 | }
16 |
17 | public void testPE() {
18 | StandardPasswordEncoderImpl pe = new StandardPasswordEncoderImpl();
19 | String password = pe.encodePassword("000000",null);
20 | System.out.println(password);
21 |
22 | password = pe.encodePassword("000000",null);
23 | System.out.println(password);
24 | password = pe.encodePassword("000000",null);
25 | System.out.println(password);
26 | password = pe.encodePassword("000000",null);
27 | System.out.println(password);
28 | password = pe.encodePassword("000000",null);
29 | System.out.println(password);
30 | password = pe.encodePassword("000000",null);
31 | System.out.println(password);
32 |
33 | System.out.println(
34 | pe.matches("000000","$2a$11$xLOqxWXU6laDFfbiHP/vmOCEHGXzawFJ5ZSRARTvA1ipUwS5m9lPS"));
35 | System.out.println(
36 | pe.matches("000000","$2a$11$DbyFNhHeCES5CKoMuM5sXepY7GM35sZkUSqQbjYJnFTzJ2GDIYGLK"));
37 | System.out.println(
38 | pe.matches("000000","$2a$11$u8YDC0UY.kfnpBanUOQaRO01bxFgOkvK.82QhMCaGJSsakrf3On9G"));
39 | System.out.println(
40 | pe.matches("000000","$2a$11$BXXUjbJqkhqcu4CvBRljhOwws/85qgGUqKrvZPsVnKCsrsemaKmEG"));
41 | System.out.println(
42 | pe.matches("000000","$2a$11$1vXImmiBQaiMss9UeHp8JeCKKwnqu5A0TfezczPomAtW6YeLylUKy"));
43 | System.out.println(
44 | pe.matches("000000","$2a$11$BM5bvHpT56ekl/i/Qw7v1u70a4hdJh9xCrn7.8bg.yF1vQRSFSLO."));
45 | }
46 | }
47 | /*
48 | $2a$11$xLOqxWXU6laDFfbiHP/vmOCEHGXzawFJ5ZSRARTvA1ipUwS5m9lPS
49 | $2a$11$DbyFNhHeCES5CKoMuM5sXepY7GM35sZkUSqQbjYJnFTzJ2GDIYGLK
50 | $2a$11$u8YDC0UY.kfnpBanUOQaRO01bxFgOkvK.82QhMCaGJSsakrf3On9G
51 | $2a$11$BXXUjbJqkhqcu4CvBRljhOwws/85qgGUqKrvZPsVnKCsrsemaKmEG
52 | $2a$11$1vXImmiBQaiMss9UeHp8JeCKKwnqu5A0TfezczPomAtW6YeLylUKy
53 | $2a$11$BM5bvHpT56ekl/i/Qw7v1u70a4hdJh9xCrn7.8bg.yF1vQRSFSLO.
54 | */
55 |
--------------------------------------------------------------------------------
/framework-filter/src/main/resources/securityconfig/xss_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 | true
7 |
8 | true
9 |
10 | true
11 |
12 | true
13 |
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | .*[S|s][C|c][R|r][I|i][P|p][T|t]>.*]]>
43 |
44 |
45 |
46 |
47 |
48 | .*[S|s][C|c][R|r][I|i][P|p][T|t]>[[.&[^a]]|[|a|\n|\r\n|\r|\u0085|\u2028|\u2029]]*]]>
49 |
50 |
--------------------------------------------------------------------------------
/framework-adapter/src/test/java/com/centit/framework/test/TestJson.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.test;
2 |
3 | import com.centit.framework.appclient.HttpReceiveJSON;
4 | import com.centit.framework.model.security.CentitPasswordEncoder;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by codefan on 17-8-4.
10 | */
11 | public class TestJson {
12 | public static void main(String[] args) {
13 | /*ResponseMapData resData = new ResponseMapData();
14 | resData.addResponseData("hello","world");
15 | resData.addResponseData("hello2","world");
16 | System.out.println(resData.toJSONString());
17 | System.out.println(JSON.toJSONString(true));
18 | */
19 | System.out.println(CentitPasswordEncoder.checkPasswordStrength("zs@SN123",8));
20 | String jsonStr = "{\"code\":0,\"message\":\"ok\"," +
21 | "\"data\":{\"hello\":\"Say Hello to\", \"world\":\" json world!\"," +
22 | "\"int\":1024, \"bool\":false, \"intArr\":[1,2,3,4]}}";
23 | HttpReceiveJSON json = HttpReceiveJSON.valueOfJson(jsonStr);
24 | System.out.println(json.getDataAsString());
25 | System.out.println(json.getDataAsString("hello")+ json.getDataAsString("world"));
26 | System.out.println(json.getDataAsObject("int", Integer.class));
27 | System.out.println(json.getDataAsObject("bool", Boolean.class));
28 | System.out.println(json.getDataAsArray("intArr", Integer.class));
29 | System.out.println(json.getOriginalJSON());
30 |
31 | json = HttpReceiveJSON.valueOfJson( "[1,2,3,4,5]");
32 | //Integer ints = json.getDataAsObject(Integer.class);
33 | List intList = json.getDataAsArray(Integer.class);
34 | for(Integer i:intList){
35 | System.out.println(i);
36 | }
37 | json = HttpReceiveJSON.valueOfJson("102");
38 | System.out.println(json.getDataAsObject(Integer.class));
39 |
40 | json = HttpReceiveJSON.valueOfJson("true");
41 | Boolean bo = json.getDataAsObject(Boolean.class);
42 | System.out.println(bo);
43 |
44 | jsonStr = "{\"c\":0,\"m\":\"ok\"," +
45 | "\"d\":[1,'hello',3,4,5]}";
46 | json = HttpReceiveJSON.valueOfJson(jsonStr);
47 | System.out.println(json.getDataAsString());
48 | System.out.println(json.getMessage());
49 |
50 | System.out.println(json.getDataAsString("d"));
51 |
52 | List strList = json.getDataAsArray("d", String.class);
53 | for(String s:strList){
54 | System.out.println(s);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/basedata/FVUserOptListId.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.basedata;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Embeddable;
5 |
6 | /**
7 | * FVUseroptlistId entity.
8 | *
9 | * @author MyEclipse Persistence Tools
10 | */
11 | //用户业务操作 view的主键
12 | @Embeddable
13 | public class FVUserOptListId implements java.io.Serializable {
14 |
15 | // Fields
16 | private static final long serialVersionUID = 1L;
17 | @Column(name = "USER_CODE")
18 | private String userCode; //用户代码
19 |
20 | @Column(name = "OPT_CODE")
21 | private String optcode; //业务代码
22 |
23 | // Constructors
24 |
25 | /**
26 | * default constructor
27 | */
28 | public FVUserOptListId() {
29 | }
30 |
31 | /**
32 | * minimal constructor
33 | * @param userCode String
34 | * @param optcode String
35 | */
36 | public FVUserOptListId(String userCode, String optcode) {
37 | this.userCode = userCode;
38 | this.optcode = optcode;
39 |
40 | }
41 |
42 |
43 | // Property accessors
44 |
45 | public String getUserCode() {
46 | return this.userCode;
47 | }
48 |
49 | public void setUserCode(String userCode) {
50 | this.userCode = userCode;
51 | }
52 |
53 | public String getOptcode() {
54 | return this.optcode;
55 | }
56 |
57 | public void setOptcode(String optcode) {
58 | this.optcode = optcode;
59 | }
60 |
61 | public boolean equals(Object other) {
62 | if ((this == other))
63 | return true;
64 | if ((other == null))
65 | return false;
66 | if (!(other instanceof FVUserOptListId))
67 | return false;
68 | FVUserOptListId castOther = (FVUserOptListId) other;
69 |
70 | return ((this.getUserCode() == castOther.getUserCode()) || (this
71 | .getUserCode() != null
72 | && castOther.getUserCode() != null && this.getUserCode()
73 | .equals(castOther.getUserCode())))
74 | && ((this.getOptcode() == castOther.getOptcode()) || (this
75 | .getOptcode() != null
76 | && castOther.getOptcode() != null && this.getOptcode()
77 | .equals(castOther.getOptcode())));
78 | }
79 |
80 | public int hashCode() {
81 | int result = 17;
82 |
83 | result = 37 * result
84 | + (getUserCode() == null ? 0 : this.getUserCode().hashCode());
85 | result = 37 * result
86 | + (getOptcode() == null ? 0 : this.getOptcode().hashCode());
87 | return result;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/security/SM3PasswordEncoderImpl.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.security;
2 |
3 | import com.centit.framework.model.security.CentitPasswordEncoder;
4 | import com.centit.support.security.SM3Util;
5 | import org.apache.commons.codec.binary.Base64;
6 | import org.apache.commons.codec.binary.StringUtils;
7 | import org.springframework.security.crypto.password.PasswordEncoder;
8 |
9 | import java.util.function.Function;
10 |
11 | /**
12 | * Created by codefan on 17-1-20.
13 | * 采用Spring 推荐的 BCryptPasswordEncoder 加密方式
14 | */
15 | public class SM3PasswordEncoderImpl
16 | implements CentitPasswordEncoder, PasswordEncoder {
17 |
18 | private Function passwordPreteat;
19 |
20 | public SM3PasswordEncoderImpl(){
21 | passwordPreteat = null;
22 | }
23 |
24 | @Override
25 | public String encodePassword(String rawPass, Object salt) {
26 | return new String(Base64.encodeBase64URLSafe(
27 | SM3Util.hash(rawPass.getBytes())));
28 | }
29 |
30 | @Override
31 | public String createPassword(String rawPass, Object salt){
32 | return encodePassword(
33 | passwordPreteat != null ? passwordPreteat.apply(rawPass) : rawPass,
34 | salt);
35 | }
36 |
37 | @Override
38 | public boolean isPasswordValid(String encodedPassword, String rawPass, Object salt) {
39 | return StringUtils.equals(
40 | encodedPassword, encodePassword(rawPass, salt));
41 | }
42 |
43 | /**
44 | * Encode the raw password. Generally, a good encoding algorithm applies a SHA-1 or
45 | * greater hash combined with an 8-byte or greater randomly generated salt.
46 | *
47 | * @param rawPassword 明文密码
48 | */
49 | @Override
50 | public String encode(CharSequence rawPassword) {
51 | return encodePassword(String.valueOf(rawPassword), null);
52 | }
53 |
54 | /**
55 | * Verify the encoded password obtained from storage matches the submitted raw
56 | * password after it too is encoded. Returns true if the passwords match, false if
57 | * they do not. The stored password itself is never decoded.
58 | *
59 | * @param rawPassword 明文密码 the raw password to encode and match
60 | * @param encodedPassword the encoded password from storage to compare with
61 | * @return true if the raw password, after encoding, matches the encoded password from
62 | * storage ; 这个接口不支持 salt
63 | */
64 | @Override
65 | public boolean matches(CharSequence rawPassword, String encodedPassword) {
66 | return isPasswordValid(String.valueOf(encodedPassword),
67 | String.valueOf(rawPassword), null);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/basedata/RolePowerId.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.basedata;
2 |
3 | import org.hibernate.validator.constraints.NotBlank;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Embeddable;
7 |
8 | /**
9 | * FRolepowerId entity.
10 | *
11 | * @author MyEclipse Persistence Tools
12 | */
13 | @Embeddable
14 | public class RolePowerId implements java.io.Serializable {
15 |
16 | // Fields
17 |
18 | private static final long serialVersionUID = 1L;
19 | @Column(name = "ROLE_CODE")
20 | @NotBlank
21 | private String roleCode; //角色代码
22 |
23 | @Column(name = "OPT_CODE")
24 | @NotBlank
25 | private String optCode; //操作代码
26 |
27 | // Constructors
28 |
29 | /**
30 | * default constructor
31 | */
32 | public RolePowerId() {
33 | }
34 |
35 | /**
36 | * full constructor
37 | * @param rolecode String
38 | * @param optcode String
39 | */
40 | public RolePowerId(String rolecode, String optcode) {
41 | this.roleCode = rolecode;
42 | this.optCode = optcode;
43 | }
44 |
45 | // Property accessors
46 |
47 | public String getRoleCode() {
48 | return this.roleCode;
49 | }
50 |
51 | public void setRoleCode(String rolecode) {
52 | this.roleCode = rolecode;
53 | }
54 |
55 | public String getOptCode() {
56 | return this.optCode;
57 | }
58 |
59 | public void setOptCode(String optcode) {
60 | this.optCode = optcode;
61 | }
62 |
63 | public boolean equals(Object other) {
64 | if ((this == other))
65 | return true;
66 | if ((other == null))
67 | return false;
68 | if (!(other instanceof RolePowerId))
69 | return false;
70 | RolePowerId castOther = (RolePowerId) other;
71 |
72 | return ((this.getRoleCode() == castOther.getRoleCode()) || (this
73 | .getRoleCode() != null
74 | && castOther.getRoleCode() != null && this.getRoleCode()
75 | .equals(castOther.getRoleCode())))
76 | && ((this.getOptCode() == castOther.getOptCode()) || (this
77 | .getOptCode() != null
78 | && castOther.getOptCode() != null && this.getOptCode()
79 | .equals(castOther.getOptCode())));
80 | }
81 |
82 | public int hashCode() {
83 | int result = 17;
84 |
85 | result = 37 * result
86 | + (getRoleCode() == null ? 0 : this.getRoleCode().hashCode());
87 | result = 37 * result
88 | + (getOptCode() == null ? 0 : this.getOptCode().hashCode());
89 | return result;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/framework-adapter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | framework-parent
7 | com.centit.framework
8 | ${revision}
9 |
10 | 4.0.0
11 | framework-adapter
12 | com.centit.framework:framework-adapter
13 | jar
14 | 一组框架层的接口,用来对框架的底层服务进行替换
15 |
16 |
17 |
18 | com.centit.support
19 | centit-utils
20 | ${project.version}
21 |
22 |
23 |
24 | org.hibernate.validator
25 | hibernate-validator
26 |
27 |
28 |
29 | org.springframework.security
30 | spring-security-web
31 |
32 |
33 |
34 | javax.persistence
35 | javax.persistence-api
36 | provided
37 | true
38 |
39 |
40 |
41 | org.apache.commons
42 | commons-pool2
43 |
44 |
45 |
46 | org.springframework.security
47 | spring-security-core
48 | true
49 |
50 |
51 |
52 |
53 | javax.servlet
54 | javax.servlet-api
55 |
56 |
57 |
58 | io.swagger
59 | swagger-annotations
60 |
61 |
62 |
63 | org.projectlombok
64 | lombok
65 |
66 |
67 |
68 | com.centit.support
69 | centit-database
70 | ${project.version}
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/framework-filter/src/main/java/com/centit/framework/filter/ResponseCorsFilter.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.filter;
2 |
3 | import javax.servlet.*;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 | import java.io.IOException;
7 |
8 | /**
9 | * 允许跨站脚本访问过滤器
10 | * spring mvc 4.2 以上版本可以通过添加 @CrossOrigin 来更优雅的实现跨站访问
11 | * for-example : @CrossOrigin(origins = "*",allowCredentials="true",maxAge=86400)
12 | * @author codefan
13 | *
14 | */
15 | public class ResponseCorsFilter implements Filter {
16 | @Override
17 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
18 |
19 | HttpServletRequest request = (HttpServletRequest) servletRequest;
20 | if (servletResponse instanceof HttpServletResponse) {
21 | HttpServletResponse alteredResponse = (HttpServletResponse) servletResponse;
22 | if((request.getMethod().equals("OPTION") || request.getMethod().equals("OPTIONS")) &&
23 | request.getServletPath().equals("/login")) {
24 | //System.out.println("request path match");
25 | alteredResponse.setStatus(HttpServletResponse.SC_OK);
26 | addHeadersFor200Response(alteredResponse);
27 | return;
28 | }
29 | addHeadersFor200Response(alteredResponse);
30 | }
31 |
32 | filterChain.doFilter(servletRequest, servletResponse);
33 | }
34 |
35 | private void addHeadersFor200Response(HttpServletResponse response) {
36 | response.addHeader("Access-Control-Allow-Origin", "*");
37 | response.addHeader("Access-Control-Allow-Credentials", "true");//允许cookies
38 | response.addHeader("Access-Control-Allow-Methods", "ACL, CANCELUPLOAD, CHECKIN, CHECKOUT, COPY, DELETE, GET, HEAD, LOCK, MKCALENDAR, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, REPORT, SEARCH, UNCHECKOUT, UNLOCK, UPDATE, VERSION-CONTROL");
39 | response.addHeader("Access-Control-Allow-Headers", "useXDomain, withCredentials, Overwrite, Destination, Content-Type, Depth, User-Agent, Translate, Range, Content-Range, Timeout, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Location, Lock-Token, If");
40 | response.addHeader("Access-Control-Expose-Headers", "DAV, content-length, Allow");
41 | response.addHeader("Access-Control-Max-Age", "86400");
42 | }
43 |
44 | @Override
45 | public void destroy() {
46 | // TODO Auto-generated method stub
47 |
48 | }
49 |
50 | @Override
51 | public void init(FilterConfig arg0) throws ServletException {
52 | // TODO Auto-generated method stub
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/framework-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | framework-parent
7 | com.centit.framework
8 | ${revision}
9 |
10 | 4.0.0
11 |
12 | framework-config
13 | com.centit.framework:framework-config
14 | jar
15 | 框架配置类
16 |
17 |
18 |
19 | com.centit.framework
20 | framework-core
21 | ${project.version}
22 | provided
23 |
24 |
25 |
26 | com.centit.framework
27 | framework-security
28 | ${project.version}
29 |
30 |
31 |
32 |
33 | org.springframework.security
34 | spring-security-cas
35 |
41 |
42 |
43 |
44 | org.jasig.cas.client
45 | cas-client-core
46 |
47 |
48 | bcpkix-jdk15on
49 | org.bouncycastle
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.session
57 | spring-session-core
58 |
59 |
60 |
61 | com.h2database
62 | h2
63 | 2.2.220
64 | compile
65 |
66 |
67 |
68 | javax.servlet
69 | javax.servlet-api
70 | provided
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/framework-config/src/main/java/com/centit/framework/config/BaseSpringMvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.config;
2 |
3 | import com.centit.framework.core.controller.MvcConfigUtil;
4 | import org.springframework.beans.BeansException;
5 | import org.springframework.context.ApplicationContext;
6 | import org.springframework.context.ApplicationContextAware;
7 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
8 | import org.springframework.http.converter.HttpMessageConverter;
9 | import org.springframework.http.converter.StringHttpMessageConverter;
10 | import org.springframework.web.servlet.config.annotation.*;
11 | import org.springframework.web.servlet.view.InternalResourceViewResolver;
12 |
13 | import java.nio.charset.Charset;
14 | import java.nio.charset.StandardCharsets;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by zou_wy on 2017/3/29.
19 | */
20 | @EnableWebMvc
21 | @EnableAspectJAutoProxy(proxyTargetClass = true)
22 | public class BaseSpringMvcConfig implements WebMvcConfigurer, ApplicationContextAware {
23 |
24 | @Override
25 | public void configurePathMatch(PathMatchConfigurer configurer) {
26 | //configurer.setUseSuffixPatternMatch(false);
27 | configurer.setUseSuffixPatternMatch(false);
28 | }
29 |
30 | @Override
31 | public void configureMessageConverters(List> converters) {
32 | converters.add(MvcConfigUtil.fastJsonHttpMessageConverter());
33 | converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
34 | }
35 |
36 | @Override
37 | public void configureViewResolvers(ViewResolverRegistry registry) {
38 | InternalResourceViewResolver resolver = new InternalResourceViewResolver();
39 | resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
40 | resolver.setPrefix("/WEB-INF/jsp/");
41 | resolver.setSuffix(".jsp");
42 | registry.viewResolver(resolver);
43 | }
44 |
45 | /**
46 | * {@inheritDoc}
47 | * This implementation is empty.
48 | */
49 | @Override
50 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
51 | registry.addResourceHandler("classpath:i18n/**");
52 | }
53 |
54 | /**
55 | * 重型排序 return Value Handlers
56 | * @param applicationContext 应用环境上下文
57 | * @throws BeansException 异常
58 | */
59 | @Override
60 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
61 | MvcConfigUtil.setApplicationContext(applicationContext,
62 | MvcConfigUtil.fastJsonHttpMessageConverter());
63 | }
64 |
65 | /*@Override
66 | public void configureHandlerExceptionResolvers(List exceptionResolvers) {
67 | exceptionResolvers.add(new GlobalHandlerExceptionResolver());
68 | }*/
69 | }
70 |
--------------------------------------------------------------------------------
/framework-filter/src/main/java/com/centit/framework/filter/GZIPResponseWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2003 Jayson Falkner (jayson@jspinsider.com)
3 | * This code is from "Servlets and JavaServer pages; the J2EE Web Tier",
4 | * http://www.jspbook.com. You may freely use the code both commercially
5 | * and non-commercially. If you like the code, please pick up a copy of
6 | * the book and help support the authors, development of more free code,
7 | * and the JSP/Servlet/J2EE community.
8 | */
9 | package com.centit.framework.filter;
10 |
11 | import org.slf4j.Logger;
12 | import org.slf4j.LoggerFactory;
13 |
14 | import javax.servlet.ServletOutputStream;
15 | import javax.servlet.http.HttpServletResponse;
16 | import javax.servlet.http.HttpServletResponseWrapper;
17 | import java.io.IOException;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 |
21 | public class GZIPResponseWrapper extends HttpServletResponseWrapper {
22 | protected HttpServletResponse origResponse = null;
23 | protected ServletOutputStream stream = null;
24 | protected PrintWriter writer = null;
25 | protected Logger logger = LoggerFactory.getLogger(GZIPResponseWrapper.class);
26 | public GZIPResponseWrapper(HttpServletResponse response) {
27 | super(response);
28 | origResponse = response;
29 | }
30 |
31 | public ServletOutputStream createOutputStream() throws IOException {
32 | return (new GZIPResponseStream(origResponse));
33 | }
34 |
35 | public void finishResponse() {
36 | try {
37 | if (writer != null) {
38 | writer.close();
39 | } else {
40 | if (stream != null) {
41 | stream.close();
42 | }
43 | }
44 | } catch (IOException e) {
45 | logger.error(e.getMessage(),e);//e.printStackTrace();
46 | }
47 | }
48 |
49 | public void flushBuffer() throws IOException {
50 | stream.flush();
51 | }
52 |
53 | public ServletOutputStream getOutputStream() throws IOException {
54 | if (writer != null) {
55 | throw new IllegalStateException("getWriter() has already been called!");
56 | }
57 |
58 | if (stream == null)
59 | stream = createOutputStream();
60 | return (stream);
61 | }
62 |
63 | public PrintWriter getWriter() throws IOException {
64 | if (writer != null) {
65 | return (writer);
66 | }
67 |
68 | if (stream != null) {
69 | throw new IllegalStateException("getOutputStream() has already been called!");
70 | }
71 |
72 | stream = createOutputStream();
73 | writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
74 | return (writer);
75 | }
76 |
77 | public void setContentLength(int length) {
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/framework-adapter/src/main/java/com/centit/framework/model/basedata/UserRoleId.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.model.basedata;
2 |
3 | import com.centit.framework.core.dao.DictionaryMap;
4 | import org.hibernate.validator.constraints.NotBlank;
5 |
6 | import javax.persistence.Column;
7 | import javax.persistence.Embeddable;
8 |
9 | /**
10 | * FUserroleId entity.
11 | *
12 | * @author MyEclipse Persistence Tools
13 | */
14 | //用户角色的主键
15 | @Embeddable
16 | public class UserRoleId implements java.io.Serializable {
17 |
18 | // Fields
19 | private static final long serialVersionUID = 893187890652550538L;
20 |
21 | @Column(name = "USER_CODE")
22 | @NotBlank
23 | @DictionaryMap(value="userCode", fieldName = "userName")
24 | private String userCode;// 用户代码
25 |
26 | @Column(name = "ROLE_CODE")
27 | @NotBlank
28 | @DictionaryMap(value="roleCode", fieldName = "roleName")
29 | private String roleCode; // 角色代码
30 |
31 | // Constructors
32 |
33 | /**
34 | * default constructor
35 | */
36 | public UserRoleId() {
37 | }
38 |
39 | /**
40 | * full constructor
41 | * @param userCode String
42 | * @param roleCode String
43 | */
44 | public UserRoleId(String userCode, String roleCode) {
45 | this.userCode = userCode;
46 | this.roleCode = roleCode;
47 | }
48 |
49 | // Property accessors
50 |
51 | public String getUserCode() {
52 | return this.userCode;
53 | }
54 |
55 | public void setUserCode(String userCode) {
56 | this.userCode = userCode;
57 | }
58 |
59 | public String getRoleCode() {
60 | return this.roleCode;
61 | }
62 |
63 | public void setRoleCode(String rolecode) {
64 | this.roleCode = rolecode;
65 | }
66 |
67 |
68 | public boolean equals(Object other) {
69 | if ((this == other))
70 | return true;
71 | if ((other == null))
72 | return false;
73 | if (!(other instanceof UserRoleId))
74 | return false;
75 | UserRoleId castOther = (UserRoleId) other;
76 |
77 | return ((this.getUserCode() == castOther.getUserCode()) || (this
78 | .getUserCode() != null
79 | && castOther.getUserCode() != null && this.getUserCode()
80 | .equals(castOther.getUserCode())))
81 | && ((this.getRoleCode() == castOther.getRoleCode()) || (this
82 | .getRoleCode() != null
83 | && castOther.getRoleCode() != null && this
84 | .getRoleCode().equals(castOther.getRoleCode())));
85 | }
86 |
87 | public int hashCode() {
88 | int result = 17;
89 |
90 | result = 37 * result
91 | + (getUserCode() == null ? 0 : this.getUserCode().hashCode());
92 | result = 37 * result
93 | + (getRoleCode() == null ? 0 : this.getRoleCode().hashCode());
94 | return result;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/framework-core/src/main/java/com/centit/framework/common/HttpContextUtils.java:
--------------------------------------------------------------------------------
1 | package com.centit.framework.common;
2 |
3 | /**
4 | * @author zfg
5 | */
6 |
7 | import com.centit.framework.model.security.CentitUserDetails;
8 | import org.springframework.web.context.request.RequestContextHolder;
9 | import org.springframework.web.context.request.ServletRequestAttributes;
10 |
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpSession;
13 | import java.util.Map;
14 |
15 | public class HttpContextUtils {
16 |
17 | //用來存储RPC调用时的session相关信息
18 | public static ThreadLocal