提交 629c8518 编写于 作者: ibizdev's avatar ibizdev

ibizdev提交

上级 cb442198
# 系统概览 # 系统概览 iBiz4j Spring R7 dev
...@@ -38,6 +38,11 @@ ...@@ -38,6 +38,11 @@
git clone -b master $para2 ibzou/ git clone -b master $para2 ibzou/
export NODE_OPTIONS=--max-old-space-size=4096 export NODE_OPTIONS=--max-old-space-size=4096
cd ibzou/ cd ibzou/
mvn clean package -Papi
cd ibzou-provider/ibzou-provider-api
mvn -Papi docker:build
mvn -Papi docker:push
docker -H $para1 stack deploy --compose-file=src/main/docker/ibzou-provider-api.yaml dev --with-registry-auth
</command> </command>
</hudson.tasks.Shell> </hudson.tasks.Shell>
</builders> </builders>
......
...@@ -20,6 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; ...@@ -20,6 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.beans.factory.annotation.Qualifier;
@Profile("web-prod") @Profile("web-prod")
@Configuration @Configuration
...@@ -30,6 +31,7 @@ public class webSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -30,6 +31,7 @@ public class webSecurityConfig extends WebSecurityConfigurerAdapter {
private AuthenticationEntryPoint unauthorizedHandler; private AuthenticationEntryPoint unauthorizedHandler;
@Autowired @Autowired
@Qualifier("IBZUAAUserService")
private AuthenticationUserService userDetailsService; private AuthenticationUserService userDetailsService;
/** /**
......
...@@ -19,6 +19,6 @@ zuul: ...@@ -19,6 +19,6 @@ zuul:
wfcore: wfcore:
path: /wfcore/** path: /wfcore/**
serviceId: ibzwf-api serviceId: ibzwf-api
stripPrefix: false stripPrefix: true
sensitive-headers: sensitive-headers:
- Cookie,Set-Cookie,Authorization - Cookie,Set-Cookie,Authorization
...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import java.util.Map; import java.util.HashMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import cn.ibizlab.core.ou.domain.IBZDepartment; import cn.ibizlab.core.ou.domain.IBZDepartment;
import cn.ibizlab.core.ou.filter.IBZDepartmentSearchContext; import cn.ibizlab.core.ou.filter.IBZDepartmentSearchContext;
......
...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import java.util.Map; import java.util.HashMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import cn.ibizlab.core.ou.domain.IBZEmployee; import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.core.ou.filter.IBZEmployeeSearchContext; import cn.ibizlab.core.ou.filter.IBZEmployeeSearchContext;
......
...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import java.util.Map; import java.util.HashMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import cn.ibizlab.core.ou.domain.IBZOrganization; import cn.ibizlab.core.ou.domain.IBZOrganization;
import cn.ibizlab.core.ou.filter.IBZOrganizationSearchContext; import cn.ibizlab.core.ou.filter.IBZOrganizationSearchContext;
......
...@@ -5,6 +5,7 @@ import java.util.ArrayList; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection; import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
......
...@@ -5,6 +5,7 @@ import java.util.ArrayList; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection; import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
......
...@@ -5,6 +5,7 @@ import java.util.ArrayList; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection; import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
......
...@@ -9,6 +9,6 @@ CMD echo "The application will start in ${IBZ_SLEEP}s..." && \ ...@@ -9,6 +9,6 @@ CMD echo "The application will start in ${IBZ_SLEEP}s..." && \
sleep ${IBZ_SLEEP} && \ sleep ${IBZ_SLEEP} && \
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /ibzou-provider-api.jar java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /ibzou-provider-api.jar
EXPOSE 8081 EXPOSE 40001
ADD ibzou-provider-api.jar /ibzou-provider-api.jar ADD ibzou-provider-api.jar /ibzou-provider-api.jar
...@@ -3,9 +3,11 @@ services: ...@@ -3,9 +3,11 @@ services:
ibzou-provider-api: ibzou-provider-api:
image: registry.cn-shanghai.aliyuncs.com/ibizsys/ibzou-provider-api:latest image: registry.cn-shanghai.aliyuncs.com/ibizsys/ibzou-provider-api:latest
ports: ports:
- "8081:8081" - "40001:40001"
networks: networks:
- agent_network - agent_network
environment:
SPRING_CLOUD_NACOS_DISCOVERY_IP: 172.16.180.237
deploy: deploy:
mode: replicated mode: replicated
replicas: 1 replicas: 1
......
...@@ -20,6 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; ...@@ -20,6 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.beans.factory.annotation.Qualifier;
@Profile("api-prod") @Profile("api-prod")
@Configuration @Configuration
...@@ -30,6 +31,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -30,6 +31,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
private AuthenticationEntryPoint unauthorizedHandler; private AuthenticationEntryPoint unauthorizedHandler;
@Autowired @Autowired
@Qualifier("IBZUAAUserService")
private AuthenticationUserService userDetailsService; private AuthenticationUserService userDetailsService;
/** /**
......
server: server:
port: 8081 port: 40001
\ No newline at end of file \ No newline at end of file
package cn.ibizlab.util.client; package cn.ibizlab.util.client;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
@Component @Component
public class IBZOUFallback implements IBZOUFeignClient { public class IBZOUFallback implements IBZOUFeignClient {
@Override @Override
public JSONObject getOrgInfo(String loginName) { public Map<String, Set<String>> getOUMapsByUserId(String userId) {
return null; return null;
} }
} }
package cn.ibizlab.util.client; package cn.ibizlab.util.client;
import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(value = "ibzou",fallback = IBZOUFallback.class) import java.util.Map;
import java.util.Set;
@FeignClient(value = "ibzou-api",fallback = IBZOUFallback.class)
public interface IBZOUFeignClient public interface IBZOUFeignClient
{ {
/** /**
* 从ou中获取当前上下级组织、部门信息 * 从ou中获取当前上下级组织、部门信息
* @param loginName 登录名 * @param userId
* @return * @return
*/ */
@GetMapping(value = "/ibzou/org/{loginname}") @GetMapping("/ibzemployees/{userId}/oumaps")
JSONObject getOrgInfo(@PathVariable("loginname") String loginName); Map<String, Set<String>> getOUMapsByUserId(@PathVariable("userId") String userId);
} }
package cn.ibizlab.util.client; package cn.ibizlab.util.client;
import com.alibaba.fastjson.JSONObject; import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.security.AuthorizationLogin;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
...@@ -8,13 +9,17 @@ import java.util.Map; ...@@ -8,13 +9,17 @@ import java.util.Map;
public class IBZUAAFallback implements IBZUAAFeignClient { public class IBZUAAFallback implements IBZUAAFeignClient {
@Override @Override
public JSONObject getUserPermissionData(String loginName, String systemId) { public Map<String, Object> pushSystemPermissionData(Map<String, Object> systemPermissionData, String systemId) {
return null; return null;
} }
@Override @Override
public Map<String, Object> pushSystemPermissionData(Map<String, Object> systemPermissionData, String systemId) { public AuthenticationUser login(AuthorizationLogin authorizationLogin) {
return null; return null;
} }
@Override
public AuthenticationUser loginByUsername(String username) {
return null;
}
} }
package cn.ibizlab.util.client; package cn.ibizlab.util.client;
import com.alibaba.fastjson.JSONObject; import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.security.AuthorizationLogin;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map; import java.util.Map;
@FeignClient(value = "ibzuaa",fallback = IBZUAAFallback.class) @FeignClient(value = "ibzuaa-api",fallback = IBZUAAFallback.class)
public interface IBZUAAFeignClient public interface IBZUAAFeignClient
{ {
/**
* 从uaa中获取当前用户权限
* @param loginName
* @param systemId
* @return
*/
@GetMapping(value = "/uaa/permission/{loginname}")
JSONObject getUserPermissionData(@PathVariable("loginname") String loginName, @RequestParam("systemid") String systemId);
/** /**
* 推送系统权限数据到uaa * 推送系统权限数据到uaa
* @param systemPermissionData * @param systemPermissionData
...@@ -27,4 +18,15 @@ public interface IBZUAAFeignClient ...@@ -27,4 +18,15 @@ public interface IBZUAAFeignClient
@PostMapping("/uaa/permission/save") @PostMapping("/uaa/permission/save")
Map<String,Object> pushSystemPermissionData(@RequestBody Map<String, Object> systemPermissionData, @RequestParam("systemid") String systemId); Map<String,Object> pushSystemPermissionData(@RequestBody Map<String, Object> systemPermissionData, @RequestParam("systemid") String systemId);
/**
* 用户登录
* @param authorizationLogin 登录信息
* @return
*/
@PostMapping(value = "/uaa/login")
AuthenticationUser login(@RequestBody AuthorizationLogin authorizationLogin);
@PostMapping(value = "/uaa/loginbyusername")
AuthenticationUser loginByUsername(@RequestBody String username);
} }
...@@ -14,6 +14,7 @@ import org.springframework.security.core.context.SecurityContextHolder; ...@@ -14,6 +14,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Qualifier;
@RestController @RestController
@RequestMapping("/") @RequestMapping("/")
...@@ -27,12 +28,13 @@ public class AuthenticationController ...@@ -27,12 +28,13 @@ public class AuthenticationController
private AuthTokenUtil jwtTokenUtil; private AuthTokenUtil jwtTokenUtil;
@Autowired @Autowired
@Qualifier("IBZUAAUserService")
private AuthenticationUserService userDetailsService; private AuthenticationUserService userDetailsService;
@PostMapping(value = "${ibiz.auth.path:v7/login}") @PostMapping(value = "${ibiz.auth.path:v7/login}")
public ResponseEntity<AuthenticationInfo> login(@Validated @RequestBody AuthorizationLogin authorizationLogin){ public ResponseEntity<AuthenticationInfo> login(@Validated @RequestBody AuthorizationLogin authorizationLogin){
userDetailsService.resetByUsername(authorizationLogin.getUsername()); userDetailsService.resetByUsername(authorizationLogin.getUsername());
final AuthenticationUser authuserdetail = userDetailsService.loadUserByLogin(authorizationLogin.getDomain(),authorizationLogin.getLoginname(),authorizationLogin.getPassword()); final AuthenticationUser authuserdetail = userDetailsService.loadUserByLogin(authorizationLogin.getUsername(),authorizationLogin.getPassword());
// 生成令牌 // 生成令牌
final String token = jwtTokenUtil.generateToken(authuserdetail); final String token = jwtTokenUtil.generateToken(authuserdetail);
// 返回 token // 返回 token
......
...@@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSONArray; ...@@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.QueryBuilder; import com.mongodb.QueryBuilder;
import cn.ibizlab.util.annotation.DEField; import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.domain.EntityBase; import cn.ibizlab.util.domain.EntityBase;
...@@ -13,9 +11,7 @@ import cn.ibizlab.util.enums.DEPredefinedFieldType; ...@@ -13,9 +11,7 @@ import cn.ibizlab.util.enums.DEPredefinedFieldType;
import cn.ibizlab.util.filter.QueryBuildContext; import cn.ibizlab.util.filter.QueryBuildContext;
import cn.ibizlab.util.filter.QueryWrapperContext; import cn.ibizlab.util.filter.QueryWrapperContext;
import cn.ibizlab.util.helper.DEFieldCacheMap; import cn.ibizlab.util.helper.DEFieldCacheMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery; import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
...@@ -25,13 +21,9 @@ import org.springframework.stereotype.Component; ...@@ -25,13 +21,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.swing.text.html.parser.Entity;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* spring security 权限管理类 * spring security 权限管理类
...@@ -440,13 +432,11 @@ public class AuthPermissionEvaluator implements PermissionEvaluator { ...@@ -440,13 +432,11 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
String orgDeptField=permissionField.get("orgsecfield"); String orgDeptField=permissionField.get("orgsecfield");
String createManField=permissionField.get("createmanfield"); String createManField=permissionField.get("createmanfield");
AuthenticationUser authenticationUser = AuthenticationUser.getAuthenticationUser(); AuthenticationUser authenticationUser = AuthenticationUser.getAuthenticationUser();
JSONObject userInfo = authenticationUser.getOrgInfo(); Map<String, Set<String>> userInfo = authenticationUser.getOrgInfo();
JSONObject orgObject = userInfo.getJSONObject("org"); Set<String> orgParent = userInfo.get("parentorg");
JSONArray orgParent = orgObject.getJSONArray("porg"); Set<String> orgChild = userInfo.get("suborg");
JSONArray orgChild = orgObject.getJSONArray("sorg"); Set<String> orgDeptParent = userInfo.get("parentdept");
JSONObject orgDeptObject = userInfo.getJSONObject("orgdept"); Set<String> orgDeptChild = userInfo.get("subdept");
JSONArray orgDeptParent = orgDeptObject.getJSONArray("porgdept");
JSONArray orgDeptChild = orgDeptObject.getJSONArray("sorgdept");
for(int i=0;i<oppriList.size();i++){ for(int i=0;i<oppriList.size();i++){
String permissionCond=oppriList.getString(i);//权限配置条件 String permissionCond=oppriList.getString(i);//权限配置条件
...@@ -492,13 +482,11 @@ public class AuthPermissionEvaluator implements PermissionEvaluator { ...@@ -492,13 +482,11 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
String createManField=permissionField.get("createmanfield"); String createManField=permissionField.get("createmanfield");
StringBuffer permissionSQL=new StringBuffer(); StringBuffer permissionSQL=new StringBuffer();
AuthenticationUser authenticationUser = AuthenticationUser.getAuthenticationUser(); AuthenticationUser authenticationUser = AuthenticationUser.getAuthenticationUser();
JSONObject userInfo = authenticationUser.getOrgInfo(); Map<String, Set<String>> userInfo = authenticationUser.getOrgInfo();
JSONObject orgObject = userInfo.getJSONObject("org"); Set<String> orgParent = userInfo.get("parentorg");
JSONArray orgParent = orgObject.getJSONArray("porg"); Set<String> orgChild = userInfo.get("suborg");
JSONArray orgChild = orgObject.getJSONArray("sorg"); Set<String> orgDeptParent = userInfo.get("parentdept");
JSONObject orgDeptObject = userInfo.getJSONObject("orgdept"); Set<String> orgDeptChild = userInfo.get("subdept");
JSONArray orgDeptParent = orgDeptObject.getJSONArray("porgdept");
JSONArray orgDeptChild = orgDeptObject.getJSONArray("sorgdept");
for(int i=0;i<oppriList.size();i++){ for(int i=0;i<oppriList.size();i++){
permissionSQL.append("OR"); permissionSQL.append("OR");
...@@ -607,7 +595,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator { ...@@ -607,7 +595,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
* 转换[a,b]格式字符串到 'a','b'格式 * 转换[a,b]格式字符串到 'a','b'格式
* @return * @return
*/ */
private String formatStringArr(JSONArray array) { private String formatStringArr(Set<String> array) {
String[] arr = array.toArray(new String[array.size()]); String[] arr = array.toArray(new String[array.size()]);
return "'" + String.join("','", arr) + "'"; return "'" + String.join("','", arr) + "'";
......
...@@ -12,6 +12,7 @@ import java.util.Map; ...@@ -12,6 +12,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@Data @Data
...@@ -60,14 +61,12 @@ public class AuthenticationUser implements UserDetails ...@@ -60,14 +61,12 @@ public class AuthenticationUser implements UserDetails
private Collection<GrantedAuthority> authorities; private Collection<GrantedAuthority> authorities;
@JsonIgnore @JsonIgnore
private int superuser; private int superuser;
@JsonIgnore
private JSONObject permisionList; private JSONObject permisionList;
private String orglevel;//单位级别 private String orglevel;//单位级别
private String deptlevel;//部门级别 private String deptlevel;//部门级别
@JsonIgnore @JsonIgnore
private Map<String,Object> userSessionParam;//用户自定义session值 private Map<String,Object> userSessionParam;//用户自定义session值
@JsonIgnore private Map<String, Set<String>> orgInfo;//上下级组织信息
private JSONObject orgInfo;//上下级组织信息
@JsonIgnore @JsonIgnore
......
...@@ -11,6 +11,7 @@ import org.springframework.security.core.userdetails.UserDetailsService; ...@@ -11,6 +11,7 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.beans.factory.annotation.Qualifier;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -26,7 +27,7 @@ public class AuthorizationTokenFilter extends OncePerRequestFilter { ...@@ -26,7 +27,7 @@ public class AuthorizationTokenFilter extends OncePerRequestFilter {
private final AuthTokenUtil authTokenUtil; private final AuthTokenUtil authTokenUtil;
private final String tokenHeader; private final String tokenHeader;
public AuthorizationTokenFilter(AuthenticationUserService userDetailsService, AuthTokenUtil authTokenUtil, @Value("${ibiz.jwt.header:Authorization}") String tokenHeader) { public AuthorizationTokenFilter(@Qualifier("IBZUAAUserService") AuthenticationUserService userDetailsService, AuthTokenUtil authTokenUtil, @Value("${ibiz.jwt.header:Authorization}") String tokenHeader) {
this.userDetailsService = userDetailsService; this.userDetailsService = userDetailsService;
this.authTokenUtil = authTokenUtil; this.authTokenUtil = authTokenUtil;
this.tokenHeader = tokenHeader; this.tokenHeader = tokenHeader;
......
...@@ -13,16 +13,14 @@ import org.springframework.stereotype.Service; ...@@ -13,16 +13,14 @@ import org.springframework.stereotype.Service;
public interface AuthenticationUserService extends UserDetailsService { public interface AuthenticationUserService extends UserDetailsService {
@Override @Override
@Cacheable( value="ibzdict_users",key = "'getByUsername:'+#p0") @Cacheable( value="ibzuaa_users",key = "'getByUsername:'+#p0")
AuthenticationUser loadUserByUsername(String username); AuthenticationUser loadUserByUsername(String username);
@Cacheable( value="ibzdict_users",key = "'getByUsername:'+#p0") @Cacheable( value="ibzuaa_users",key = "'getByUsername:'+#p0")
AuthenticationUser loadUserByLogin(String username,String password); AuthenticationUser loadUserByLogin(String username,String password);
@Cacheable( value="ibzdict_users",key = "'getByUsername:'+#p1") @CacheEvict( value="ibzuaa_users",key = "'getByUsername:'+#p0")
AuthenticationUser loadUserByLogin(String domain,String username,String password);
@CacheEvict( value="ibzdict_users",key = "'getByUsername:'+#p0")
void resetByUsername(String username); void resetByUsername(String username);
} }
package cn.ibizlab.util.service;
import com.alibaba.fastjson.JSONObject;
import cn.ibizlab.util.client.IBZOUFeignClient;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.client.IBZUAAFeignClient;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.security.AuthorizationLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
/**
* 实体[IBZUSER] 服务对象接口实现
*/
@Service("IBZUAAUserService")
public class IBZUAAUserService implements AuthenticationUserService{
@Autowired
private IBZUAAFeignClient uaaFeignClient;
@Override
public AuthenticationUser loadUserByUsername(String username) {
AuthenticationUser user=uaaFeignClient.loginByUsername(username);
if(user==null)
throw new BadRequestAlertException("登录失败","IBZUAAUser",username);
return user;
}
@Override
public AuthenticationUser loadUserByLogin(String username, String password) {
String[] data=username.split("[|]");
String loginname=username;
String domains="";
if(data.length==2) {
loginname=data[0].trim();
domains=data[1].trim();
}
AuthorizationLogin logininfo = new AuthorizationLogin();
logininfo.setDomain(domains);
logininfo.setLoginname(loginname);
logininfo.setPassword(password);
AuthenticationUser user=uaaFeignClient.login(logininfo);
if(user==null)
throw new BadRequestAlertException("登录失败","IBZUAAUser",username);
return user;
}
@Override
public void resetByUsername(String username) {
}
}
...@@ -62,12 +62,6 @@ public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> impl ...@@ -62,12 +62,6 @@ public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> impl
return authuserdetail; return authuserdetail;
} }
@Override
public AuthenticationUser loadUserByLogin(String domain, String username, String password) {
if(!StringUtils.isEmpty(domain))
username = username+"|"+domain;
return loadUserByLogin(username,password);
}
public void resetByUsername(String username) { public void resetByUsername(String username) {
......
...@@ -19,18 +19,6 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -19,18 +19,6 @@ import org.springframework.beans.factory.annotation.Value;
@Service("SimpleUserService") @Service("SimpleUserService")
public class SimpleUserService implements AuthenticationUserService{ public class SimpleUserService implements AuthenticationUserService{
@Value("${ibiz.enablePermissionValid:false}")
boolean enablePermissionValid; //是否开启权限校验
@Value("${ibiz.systemid:2C40DFCD-0DF5-47BF-91A5-C45F810B0001}")
private String systemid;
@Autowired
private IBZUAAFeignClient uaaFeignClient;
@Autowired
private IBZOUFeignClient ouFeignClient;
@Override @Override
public AuthenticationUser loadUserByUsername(String username) { public AuthenticationUser loadUserByUsername(String username) {
AuthenticationUser user = new AuthenticationUser(); AuthenticationUser user = new AuthenticationUser();
...@@ -39,17 +27,12 @@ public class SimpleUserService implements AuthenticationUserService{ ...@@ -39,17 +27,12 @@ public class SimpleUserService implements AuthenticationUserService{
String domains=""; String domains="";
String password=""; String password="";
if(data.length==3) { if(data.length==2) {
loginname=data[0].trim(); loginname=data[0].trim();
domains=data[1].trim(); domains=data[1].trim();
password=data[2].trim();
}
else if(data.length==2) {
loginname=data[0].trim();
password=data[1].trim();
} }
user.setUserid(DigestUtils.md5DigestAsHex(username.getBytes())); user.setUserid(username);
user.setUsercode(loginname); user.setUsercode(loginname);
user.setUsername(username); user.setUsername(username);
user.setLoginname(loginname); user.setLoginname(loginname);
...@@ -60,55 +43,20 @@ public class SimpleUserService implements AuthenticationUserService{ ...@@ -60,55 +43,20 @@ public class SimpleUserService implements AuthenticationUserService{
user.setOrgcode(domains); user.setOrgcode(domains);
user.setOrgname(domains); user.setOrgname(domains);
setUserPermission(user);
setUserOrgInfo(user);
return user; return user;
} }
@Override @Override
public AuthenticationUser loadUserByLogin(String username, String password) { public AuthenticationUser loadUserByLogin(String username, String password) {
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", username, password).getBytes()); AuthenticationUser authuserdetail = loadUserByUsername(username);
AuthenticationUser authuserdetail = loadUserByUsername(username+"|"+password);
return authuserdetail; return authuserdetail;
} }
@Override
public AuthenticationUser loadUserByLogin(String domain, String username, String password) {
if(!StringUtils.isEmpty(domain))
username = username+"|"+domain;
return loadUserByLogin(username,password);
}
@Override @Override
public void resetByUsername(String username) { public void resetByUsername(String username) {
} }
/**
* 设置用户权限
*/
private void setUserPermission(AuthenticationUser user) {
if(enablePermissionValid){
JSONObject permission= uaaFeignClient.getUserPermissionData(user.getLoginname(),systemid);
user.setPermisionList(permission);
}
}
/**
* 设置用户组织相关信息
* @param user
*/
private void setUserOrgInfo(AuthenticationUser user) {
if(enablePermissionValid) {
JSONObject orgInfo=ouFeignClient.getOrgInfo(user.getLoginname());
if(orgInfo==null)
throw new RuntimeException("获取用户信息失败,请检查用户中心[IBZOU]中是否存在当前用户!");
JSONObject curUser=orgInfo.getJSONObject("curuser");
user.setOrgInfo(orgInfo);
user.setMdeptid(curUser.getString("orgdept"));
user.setOrgid(curUser.getString("org"));
}
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册