diff --git a/pigx-auth/pom.xml b/pigx-auth/pom.xml index 38ccae031..3d2a1eda1 100644 --- a/pigx-auth/pom.xml +++ b/pigx-auth/pom.xml @@ -46,6 +46,12 @@ pigx-upms-api ${pigx.version} + + + com.pig4cloud + pigx-common-security + ${pigx.version} + org.springframework.cloud diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java index 8e87f770a..ac2b43d01 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java @@ -22,7 +22,7 @@ package com.pig4cloud.pigx.auth.config; import com.fasterxml.jackson.databind.ObjectMapper; import com.pig4cloud.pigx.common.security.mobile.MobileLoginSuccessHandler; import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer; -import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService; +import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/pigx-common/pigx-common-core/pom.xml b/pigx-common/pigx-common-core/pom.xml index 81c112062..7c65e512e 100644 --- a/pigx-common/pigx-common-core/pom.xml +++ b/pigx-common/pigx-common-core/pom.xml @@ -50,7 +50,6 @@ javax.servlet javax.servlet-api - provided @@ -64,5 +63,14 @@ ${mbp.boot.version} compile + + + io.github.openfeign + feign-okhttp + + + org.springframework.cloud + spring-cloud-starter-openfeign + diff --git a/pigx-common/pigx-common-log/pom.xml b/pigx-common/pigx-common-log/pom.xml index eb8310a0f..7ddfd012b 100644 --- a/pigx-common/pigx-common-log/pom.xml +++ b/pigx-common/pigx-common-log/pom.xml @@ -47,5 +47,10 @@ pigx-upms-api ${pigx.version} + + com.pig4cloud + pigx-common-security + ${pigx.version} + diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java index 21cd3d7fb..196576f58 100644 --- a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java @@ -53,7 +53,7 @@ public class SysLogUtils { }); SysLog sysLog = new SysLog(); - sysLog.setCreateBy(SecurityUtils.getUser()); + sysLog.setCreateBy(SecurityUtils.getUser().getUsername()); sysLog.setType(CommonConstant.STATUS_NORMAL); sysLog.setRemoteAddr(HttpUtil.getClientIP(request)); sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI())); diff --git a/pigx-common/pigx-common-security/pom.xml b/pigx-common/pigx-common-security/pom.xml index 93b02bbd6..886042ebc 100644 --- a/pigx-common/pigx-common-security/pom.xml +++ b/pigx-common/pigx-common-security/pom.xml @@ -46,14 +46,11 @@ org.springframework.cloud spring-cloud-starter-security - + - io.github.openfeign - feign-okhttp - - - org.springframework.cloud - spring-cloud-starter-openfeign + com.pig4cloud + pigx-upms-api + ${pigx.version} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java new file mode 100644 index 000000000..4242db953 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.component; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; +import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; +import org.springframework.security.oauth2.provider.token.RemoteTokenServices; + +/** + * @author lengleng + * @date 2018/6/22 + */ +public abstract class PigxResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter { + @Autowired + protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; + @Autowired + protected PigAccessDeniedHandler pigAccessDeniedHandler; + @Autowired + protected RemoteTokenServices remoteTokenServices; + @Autowired + protected UserDetailsService userDetailsService; + + @Override + public abstract void configure(HttpSecurity http) throws Exception; + + /** + * why add resourceId + * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token + * + * @param resources + */ + @Override + public void configure(ResourceServerSecurityConfigurer resources) { + DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); + DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); + userTokenConverter.setUserDetailsService(userDetailsService); + accessTokenConverter.setUserTokenConverter(userTokenConverter); + remoteTokenServices.setAccessTokenConverter(accessTokenConverter); + resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) + .accessDeniedHandler(pigAccessDeniedHandler) + .tokenServices(remoteTokenServices); + } + + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java index 2eb72390b..4a855deca 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java @@ -17,7 +17,7 @@ package com.pig4cloud.pigx.common.security.mobile; -import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService; +import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java index 8140b4893..f71672931 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java @@ -17,7 +17,7 @@ package com.pig4cloud.pigx.common.security.mobile; -import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService; +import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import lombok.AllArgsConstructor; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.SecurityConfigurerAdapter; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java new file mode 100644 index 000000000..e69b617fc --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.service; + +import lombok.Getter; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; + +import java.util.Collection; + +/** + * @author lengleng + * @date 2018/8/20 + * 扩展用户信息 + */ +public class PigxUser extends User { + /** + * 用户ID + */ + @Getter + private Integer id; + /** + * 部门ID + */ + @Getter + private Integer deptId; + + /** + * Construct the User with the details required by + * {@link DaoAuthenticationProvider}. + * + * @param id 用户ID + * @param deptId 部门ID + * @param username the username presented to the + * DaoAuthenticationProvider + * @param password the password that should be presented to the + * DaoAuthenticationProvider + * @param enabled set to true if the user is enabled + * @param accountNonExpired set to true if the account has not expired + * @param credentialsNonExpired set to true if the credentials have not + * expired + * @param accountNonLocked set to true if the account is not locked + * @param authorities the authorities that should be granted to the caller if they + * presented the correct username and password and the user is enabled. Not null. + * @throws IllegalArgumentException if a null value was passed either as + * a parameter or as an element in the GrantedAuthority collection + */ + public PigxUser(Integer id, Integer deptId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + this.id = id; + this.deptId = id; + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/PigxUserDetailsService.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsService.java similarity index 96% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/PigxUserDetailsService.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsService.java index 7e94476b3..58778add3 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/PigxUserDetailsService.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsService.java @@ -13,7 +13,8 @@ * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: lengleng (wangiegie@gmail.com) - */package com.pig4cloud.pigx.common.security.util; + */ +package com.pig4cloud.pigx.common.security.service; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java similarity index 72% rename from pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java index e3b41b968..db6f18550 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java @@ -1,23 +1,21 @@ /* + * Copyright (c) 2018-2025, lengleng All rights reserved. * - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - * + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.auth.service; +package com.pig4cloud.pigx.common.security.service; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; @@ -27,12 +25,10 @@ import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; -import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @@ -104,7 +100,8 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService { SysUser user = info.getSysUser(); boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL); // 构造security用户 - return new User(info.getSysUser().getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled, + + return new PigxUser(user.getUserId(), user.getDeptId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled, true, true, true, authorities); } } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java index ae1c8190e..8e93f4297 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java @@ -22,6 +22,7 @@ package com.pig4cloud.pigx.common.security.util; import cn.hutool.core.util.StrUtil; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.security.service.PigxUser; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; @@ -48,12 +49,12 @@ public class SecurityUtils { /** * 获取用户 */ - public static String getUser(Authentication authentication) { + public static PigxUser getUser(Authentication authentication) { Object principal = authentication.getPrincipal(); - if (principal == null) { - return null; + if (principal instanceof PigxUser) { + return (PigxUser) principal; } - return (String) principal; + return null; } public static String getClientId() { @@ -68,7 +69,7 @@ public class SecurityUtils { /** * 获取用户 */ - public static String getUser() { + public static PigxUser getUser() { Authentication authentication = getAuthentication(); if (authentication == null) { return null; diff --git a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories index 4e205b712..016400a67 100644 --- a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories +++ b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories @@ -3,5 +3,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler,\ com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint,\ com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration,\ + com.pig4cloud.pigx.common.security.service.PigxUserDetailsServiceImpl,\ com.pig4cloud.pigx.common.security.social.QqSocialConfig,\ com.pig4cloud.pigx.common.security.social.WxSocialConfig diff --git a/pigx-common/pigx-common-swagger/pom.xml b/pigx-common/pigx-common-swagger/pom.xml index 89fdff780..89c80b536 100644 --- a/pigx-common/pigx-common-swagger/pom.xml +++ b/pigx-common/pigx-common-swagger/pom.xml @@ -41,12 +41,6 @@ pigx-common-security ${pigx.version} - - - javax.servlet - javax.servlet-api - provided - io.springfox diff --git a/pigx-upms/pigx-upms-api/pom.xml b/pigx-upms/pigx-upms-api/pom.xml index 419f7c35a..94596fa78 100644 --- a/pigx-upms/pigx-upms-api/pom.xml +++ b/pigx-upms/pigx-upms-api/pom.xml @@ -38,7 +38,7 @@ com.pig4cloud - pigx-common-security + pigx-common-core ${pigx.version} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java index 6fe57204f..2371f6a99 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java @@ -31,8 +31,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients; * 用户统一管理系统 */ @EnablePigxSwagger2 -@EnableFeignClients @SpringCloudApplication +@EnableFeignClients({"com.pig4cloud.pigx.admin.api.feign"}) public class PigxAdminApplication { public static void main(String[] args) { SpringApplication.run(PigxAdminApplication.class, args); diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java index 20925f5c3..d0b16265c 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java @@ -19,15 +19,11 @@ package com.pig4cloud.pigx.admin.config; -import com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler; -import com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint; -import lombok.AllArgsConstructor; +import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; /** * @author lengleng @@ -35,12 +31,8 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Res */ @Configuration @EnableResourceServer -@AllArgsConstructor @EnableGlobalMethodSecurity(prePostEnabled = true) -public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { - private final PigAccessDeniedHandler pigAccessDeniedHandler; - private final ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; - +public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { http.authorizeRequests() @@ -53,16 +45,5 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { .and().csrf().disable(); } - /** - * why add resourceId - * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token - * - * @param resources - * @throws Exception - */ - @Override - public void configure(ResourceServerSecurityConfigurer resources) throws Exception { - resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .accessDeniedHandler(pigAccessDeniedHandler); - } + } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java index f445ecb47..246e9eb89 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java @@ -25,7 +25,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysDept; import com.pig4cloud.pigx.admin.service.SysDeptService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.util.R; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -42,9 +42,9 @@ import java.util.List; */ @RestController @RequestMapping("/dept") +@AllArgsConstructor public class DeptController { - @Autowired - private SysDeptService sysDeptService; + private final SysDeptService sysDeptService; /** * 通过ID查询 diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java index ed3e42509..a4dfe5442 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java @@ -73,7 +73,7 @@ public class UserController { } //为空时查询当前用户 if (StrUtil.isBlank(username)) { - username = SecurityUtils.getUser(); + username = SecurityUtils.getUser().getUsername(); } return new R<>(userService.findUserInfo(EnumLoginType.PWD.getType(), username)); @@ -163,6 +163,6 @@ public class UserController { */ @PutMapping("/editInfo") public R editInfo(@RequestBody UserDTO userDto) { - return userService.updateUserInfo(userDto, SecurityUtils.getUser()); + return userService.updateUserInfo(userDto, SecurityUtils.getUser().getUsername()); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java index 14e58c617..62159c7a1 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java @@ -29,8 +29,8 @@ import com.pig4cloud.pigx.admin.mapper.SysDeptMapper; import com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper; import com.pig4cloud.pigx.admin.service.SysDeptService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import lombok.AllArgsConstructor; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -46,11 +46,10 @@ import java.util.List; * @since 2018-01-20 */ @Service +@AllArgsConstructor public class SysDeptServiceImpl extends ServiceImpl implements SysDeptService { - @Autowired - private SysDeptMapper sysDeptMapper; - @Autowired - private SysDeptRelationMapper sysDeptRelationMapper; + private final SysDeptMapper sysDeptMapper; + private final SysDeptRelationMapper sysDeptRelationMapper; /** * 添加信息部门 diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java index 80f09ecd2..da6309221 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java @@ -71,9 +71,7 @@ public class SysSocialDetailsServiceImpl extends ServiceImpl result = getOpenId(appId, code); - SysUser condition = new SysUser(); - condition.setUsername(SecurityUtils.getUser()); - SysUser sysUser = sysUserMapper.selectOne(condition); + SysUser sysUser = sysUserMapper.selectById(SecurityUtils.getUser().getId()); sysUser.setWxOpenid(result.get("openId")); sysUserMapper.updateAllColumnById(sysUser); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java index e1c6cab7d..947c92642 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java @@ -17,14 +17,12 @@ package com.pig4cloud.pigx.codegen.config; -import com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler; -import com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint; +import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; /** @@ -35,9 +33,7 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Res @EnableResourceServer @AllArgsConstructor @EnableGlobalMethodSecurity(prePostEnabled = true) -public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { - private final PigAccessDeniedHandler pigAccessDeniedHandler; - private final ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; +public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { @@ -48,14 +44,12 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { } /** - * why add resourceId - * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token + * 重写抽象类实现,不需要调用feign 获取 userdetils * * @param resources - * @throws Exception */ @Override - public void configure(ResourceServerSecurityConfigurer resources) throws Exception { + public void configure(ResourceServerSecurityConfigurer resources) { resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) .accessDeniedHandler(pigAccessDeniedHandler); } diff --git a/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/config/ResourceServerConfigurer.java b/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/config/ResourceServerConfigurer.java index fee0c9430..4a17dc4a5 100644 --- a/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/config/ResourceServerConfigurer.java +++ b/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/config/ResourceServerConfigurer.java @@ -18,6 +18,7 @@ package com.pig4cloud.pigx.daemon.config; import com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler; +import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter; import com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Configuration; @@ -35,9 +36,7 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Res @EnableResourceServer @AllArgsConstructor @EnableGlobalMethodSecurity(prePostEnabled = true) -public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { - private final PigAccessDeniedHandler pigAccessDeniedHandler; - private final ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; +public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { @@ -48,14 +47,12 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { } /** - * why add resourceId - * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token + * 重写抽象类实现,不需要调用feign 获取 userdetils * * @param resources - * @throws Exception */ @Override - public void configure(ResourceServerSecurityConfigurer resources) throws Exception { + public void configure(ResourceServerSecurityConfigurer resources) { resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) .accessDeniedHandler(pigAccessDeniedHandler); } diff --git a/pigx-visual/pigx-tx-manager/pom.xml b/pigx-visual/pigx-tx-manager/pom.xml index 3217c9afd..8c96f4009 100644 --- a/pigx-visual/pigx-tx-manager/pom.xml +++ b/pigx-visual/pigx-tx-manager/pom.xml @@ -67,10 +67,6 @@ pigx-common-core ${pigx.version} - - javax.servlet - javax.servlet-api -