♻️ Refactoring code. 事件通知重构

This commit is contained in:
lbw 2022-06-02 17:31:34 +08:00
parent bb0864294d
commit cb91df9a33
26 changed files with 585 additions and 548 deletions

View File

@ -58,8 +58,7 @@ pig
├── pig-common-seata -- 分布式事务 ├── pig-common-seata -- 分布式事务
├── pig-common-security -- 安全工具类 ├── pig-common-security -- 安全工具类
├── pig-common-swagger -- 接口文档 ├── pig-common-swagger -- 接口文档
├── pig-common-feign -- feign 扩展封装 └── pig-common-feign -- feign 扩展封装
└── pig-common-test -- oauth2.0 单元测试扩展封装
├── pig-register -- Nacos Server[8848] ├── pig-register -- Nacos Server[8848]
├── pig-gateway -- Spring Cloud Gateway网关[9999] ├── pig-gateway -- Spring Cloud Gateway网关[9999]
└── pig-upms -- 通用用户权限管理模块 └── pig-upms -- 通用用户权限管理模块

View File

@ -16,7 +16,9 @@
package com.pig4cloud.pig.auth.config; package com.pig4cloud.pig.auth.config;
import com.pig4cloud.pig.auth.support.*; import com.pig4cloud.pig.auth.support.CustomeOAuth2AccessTokenGenerator;
import com.pig4cloud.pig.auth.support.handler.PigAuthenticationFailureEventHandler;
import com.pig4cloud.pig.auth.support.handler.PigAuthenticationSuccessEventHandler;
import com.pig4cloud.pig.auth.support.password.OAuth2ResourceOwnerPasswordAuthenticationConverter; import com.pig4cloud.pig.auth.support.password.OAuth2ResourceOwnerPasswordAuthenticationConverter;
import com.pig4cloud.pig.auth.support.password.OAuth2ResourceOwnerPasswordAuthenticationProvider; import com.pig4cloud.pig.auth.support.password.OAuth2ResourceOwnerPasswordAuthenticationProvider;
import com.pig4cloud.pig.auth.support.sms.OAuth2ResourceOwnerSmsAuthenticationConverter; import com.pig4cloud.pig.auth.support.sms.OAuth2ResourceOwnerSmsAuthenticationConverter;
@ -63,16 +65,23 @@ public class AuthorizationServerConfiguration {
OAuth2AuthorizationService authorizationService) throws Exception { OAuth2AuthorizationService authorizationService) throws Exception {
OAuth2AuthorizationServerConfigurer<HttpSecurity> authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer<>(); OAuth2AuthorizationServerConfigurer<HttpSecurity> authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer<>();
http.apply(authorizationServerConfigurer.tokenEndpoint( http.apply(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {
(tokenEndpoint) -> tokenEndpoint.accessTokenRequestConverter(new DelegatingAuthenticationConverter( // sas 支持的 Converter
Arrays.asList(new OAuth2ResourceOwnerPasswordAuthenticationConverter(), tokenEndpoint.accessTokenRequestConverter(new DelegatingAuthenticationConverter(
new OAuth2ResourceOwnerSmsAuthenticationConverter(), Arrays.asList(new OAuth2ResourceOwnerPasswordAuthenticationConverter(),
new OAuth2RefreshTokenAuthenticationConverter(), new OAuth2ResourceOwnerSmsAuthenticationConverter(),
new OAuth2ClientCredentialsAuthenticationConverter(), new OAuth2RefreshTokenAuthenticationConverter(),
new OAuth2AuthorizationCodeAuthenticationConverter(), new OAuth2ClientCredentialsAuthenticationConverter(),
new OAuth2AuthorizationCodeRequestAuthenticationConverter()))))); new OAuth2AuthorizationCodeAuthenticationConverter(),
authorizationServerConfigurer.authorizationEndpoint( new OAuth2AuthorizationCodeRequestAuthenticationConverter())));
authorizationEndpoint -> authorizationEndpoint.consentPage(CUSTOM_CONSENT_PAGE_URI)); // 登录成功处理器
tokenEndpoint.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler());
// 登录失败处理器
tokenEndpoint.errorResponseHandler(new PigAuthenticationFailureEventHandler());
}));
authorizationServerConfigurer.authorizationEndpoint(authorizationEndpoint -> {
authorizationEndpoint.consentPage(CUSTOM_CONSENT_PAGE_URI);
});
authorizationServerConfigurer.authorizationService(authorizationService); authorizationServerConfigurer.authorizationService(authorizationService);

View File

@ -16,16 +16,14 @@
package com.pig4cloud.pig.auth.config; package com.pig4cloud.pig.auth.config;
import com.pig4cloud.pig.auth.support.handler.FormAuthenticationFailureHandler;
import com.pig4cloud.pig.auth.support.handler.SsoLogoutSuccessHandler;
import com.pig4cloud.pig.common.security.component.PigDaoAuthenticationProvider; import com.pig4cloud.pig.common.security.component.PigDaoAuthenticationProvider;
import com.pig4cloud.pig.common.security.handler.FormAuthenticationFailureHandler;
import com.pig4cloud.pig.common.security.handler.SsoLogoutSuccessHandler;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
/** /**
* 服务安全相关配置 * 服务安全相关配置
@ -51,8 +49,11 @@ public class WebSecurityConfiguration {
.csrf().disable() .csrf().disable()
// 个性化 formLogin // 个性化 formLogin
.formLogin().loginPage("/token/login").loginProcessingUrl("/token/form") .formLogin().loginPage("/token/login").loginProcessingUrl("/token/form")
.failureHandler(authenticationFailureHandler()).and().logout() // SSO登录失败处理
.logoutSuccessHandler(logoutSuccessHandler()).deleteCookies("JSESSIONID").invalidateHttpSession(true); .failureHandler(new FormAuthenticationFailureHandler()).and().logout()
// SSO登出成功处理
.logoutSuccessHandler(new SsoLogoutSuccessHandler()).deleteCookies("JSESSIONID")
.invalidateHttpSession(true);
// 处理 UsernamePasswordAuthenticationToken // 处理 UsernamePasswordAuthenticationToken
http.authenticationProvider(new PigDaoAuthenticationProvider()); http.authenticationProvider(new PigDaoAuthenticationProvider());
@ -65,22 +66,4 @@ public class WebSecurityConfiguration {
return (web) -> web.ignoring().antMatchers("/css/**", "/error"); return (web) -> web.ignoring().antMatchers("/css/**", "/error");
} }
/**
* sso 表单登录失败处理
* @return FormAuthenticationFailureHandler
*/
@Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
return new FormAuthenticationFailureHandler();
}
/**
* SSO 退出逻辑处理
* @return LogoutSuccessHandler
*/
@Bean
public LogoutSuccessHandler logoutSuccessHandler() {
return new SsoLogoutSuccessHandler();
}
} }

View File

@ -21,6 +21,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.admin.api.entity.SysOauthClientDetails; import com.pig4cloud.pig.admin.api.entity.SysOauthClientDetails;
import com.pig4cloud.pig.admin.api.feign.RemoteClientDetailsService; import com.pig4cloud.pig.admin.api.feign.RemoteClientDetailsService;
import com.pig4cloud.pig.admin.api.vo.TokenVo;
import com.pig4cloud.pig.common.security.util.OAuth2EndpointUtils; import com.pig4cloud.pig.common.security.util.OAuth2EndpointUtils;
import com.pig4cloud.pig.common.security.util.OAuth2ErrorCodesExpand; import com.pig4cloud.pig.common.security.util.OAuth2ErrorCodesExpand;
import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.CacheConstants;
@ -80,7 +81,7 @@ public class PigTokenEndpoint {
private final RemoteClientDetailsService clientDetailsService; private final RemoteClientDetailsService clientDetailsService;
private final RedisTemplate redisTemplate; private final RedisTemplate<String, Object> redisTemplate;
private final CacheManager cacheManager; private final CacheManager cacheManager;
@ -192,7 +193,20 @@ public class PigTokenEndpoint {
Set<String> keys = redisTemplate.keys(key); Set<String> keys = redisTemplate.keys(key);
List<String> pages = keys.stream().skip((current - 1) * size).limit(size).collect(Collectors.toList()); List<String> pages = keys.stream().skip((current - 1) * size).limit(size).collect(Collectors.toList());
Page result = new Page(current, size); Page result = new Page(current, size);
result.setRecords(redisTemplate.opsForValue().multiGet(pages));
List<TokenVo> tokenVoList = redisTemplate.opsForValue().multiGet(pages).stream().map(obj -> {
OAuth2Authorization authorization = (OAuth2Authorization) obj;
TokenVo tokenVo = new TokenVo();
tokenVo.setClientId(authorization.getRegisteredClientId());
tokenVo.setId(authorization.getId());
tokenVo.setUsername(authorization.getPrincipalName());
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
tokenVo.setAccessToken(accessToken.getToken().getTokenValue());
tokenVo.setExpiresAt(accessToken.getToken().getExpiresAt());
tokenVo.setIssuedAt(accessToken.getToken().getIssuedAt());
return tokenVo;
}).collect(Collectors.toList());
result.setRecords(tokenVoList);
result.setTotal(keys.size()); result.setTotal(keys.size());
return R.ok(result); return R.ok(result);
} }

View File

@ -88,10 +88,9 @@ public class CustomeOAuth2AccessTokenGenerator implements OAuth2TokenGenerator<O
String key = String.format("%s::%s::%s", SecurityContextHolder.getContext().getAuthentication().getPrincipal(), String key = String.format("%s::%s::%s", SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
context.getPrincipal().getName(), UUID.randomUUID()); context.getPrincipal().getName(), UUID.randomUUID());
return new CustomeOAuth2AccessTokenGenerator.OAuth2AccessTokenClaims(OAuth2AccessToken.TokenType.BEARER, key,
return new CustomeOAuth2AccessTokenGenerator.OAuth2AccessTokenClaims( accessTokenClaimsSet.getIssuedAt(), accessTokenClaimsSet.getExpiresAt(), context.getAuthorizedScopes(),
OAuth2AccessToken.TokenType.BEARER, key, accessTokenClaimsSet.getIssuedAt(), accessTokenClaimsSet.getClaims());
accessTokenClaimsSet.getExpiresAt(), context.getAuthorizedScopes(), accessTokenClaimsSet.getClaims());
} }
/** /**

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.pig4cloud.pig.common.security.handler; package com.pig4cloud.pig.auth.support.handler;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
/** /**
* @author lengleng * @author lengleng
* @date 2019-08-20 * @date 2022-06-02
* <p> * <p>
* 表单登录失败处理逻辑 * 表单登录失败处理逻辑
*/ */

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.auth.support.handler;
import com.pig4cloud.pig.admin.api.entity.SysLog;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
import com.pig4cloud.pig.common.log.event.SysLogEvent;
import com.pig4cloud.pig.common.log.util.LogTypeEnum;
import com.pig4cloud.pig.common.log.util.SysLogUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author lengleng
* @date 2022-06-02
*/
@Slf4j
public class PigAuthenticationFailureEventHandler implements AuthenticationFailureHandler {
private final MappingJackson2HttpMessageConverter errorHttpResponseConverter = new MappingJackson2HttpMessageConverter();
/**
* Called when an authentication attempt fails.
* @param request the request during which the authentication attempt occurred.
* @param response the response.
* @param exception the exception which was thrown to reject the authentication
* request.
*/
@Override
@SneakyThrows
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) {
String username = request.getParameter("username");
log.info("用户:{} 登录失败,异常:{}", username, exception.getLocalizedMessage());
SysLog logVo = SysLogUtils.getSysLog();
logVo.setTitle("登录失败");
logVo.setType(LogTypeEnum.ERROR.getType());
logVo.setException(exception.getLocalizedMessage());
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);
logVo.setCreateBy(username);
logVo.setUpdateBy(username);
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
// 写出错误信息
sendErrorResponse(request, response, exception);
}
private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException {
OAuth2Error error = ((OAuth2AuthenticationException) exception).getError();
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
httpResponse.setStatusCode(HttpStatus.BAD_REQUEST);
this.errorHttpResponseConverter.write(R.failed(error.getDescription()), MediaType.APPLICATION_JSON,
httpResponse);
}
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.auth.support.handler;
import com.pig4cloud.pig.admin.api.entity.SysLog;
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
import com.pig4cloud.pig.common.log.event.SysLogEvent;
import com.pig4cloud.pig.common.log.util.SysLogUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AccessTokenAuthenticationToken;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.temporal.ChronoUnit;
import java.util.Map;
/**
* @author lengleng
* @date 2022-06-02
*/
@Slf4j
public class PigAuthenticationSuccessEventHandler implements AuthenticationSuccessHandler {
private final HttpMessageConverter<OAuth2AccessTokenResponse> accessTokenHttpResponseConverter = new OAuth2AccessTokenResponseHttpMessageConverter();
/**
* Called when a user has been successfully authenticated.
* @param request the request which caused the successful authentication
* @param response the response
* @param authentication the <tt>Authentication</tt> object which was created during
* the authentication process.
*/
@SneakyThrows
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) {
log.info("用户:{} 登录成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
SysLog logVo = SysLogUtils.getSysLog();
logVo.setTitle("登录成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);
logVo.setCreateBy(authentication.getName());
logVo.setUpdateBy(authentication.getName());
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
// 输出token
sendAccessTokenResponse(request, response, authentication);
}
private void sendAccessTokenResponse(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException {
OAuth2AccessTokenAuthenticationToken accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) authentication;
OAuth2AccessToken accessToken = accessTokenAuthentication.getAccessToken();
OAuth2RefreshToken refreshToken = accessTokenAuthentication.getRefreshToken();
Map<String, Object> additionalParameters = accessTokenAuthentication.getAdditionalParameters();
OAuth2AccessTokenResponse.Builder builder = OAuth2AccessTokenResponse.withToken(accessToken.getTokenValue())
.tokenType(accessToken.getTokenType()).scopes(accessToken.getScopes());
if (accessToken.getIssuedAt() != null && accessToken.getExpiresAt() != null) {
builder.expiresIn(ChronoUnit.SECONDS.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()));
}
if (refreshToken != null) {
builder.refreshToken(refreshToken.getTokenValue());
}
if (!CollectionUtils.isEmpty(additionalParameters)) {
builder.additionalParameters(additionalParameters);
}
OAuth2AccessTokenResponse accessTokenResponse = builder.build();
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
this.accessTokenHttpResponseConverter.write(accessTokenResponse, null, httpResponse);
}
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.auth.support.handler;
import cn.hutool.core.collection.CollUtil;
import com.pig4cloud.pig.admin.api.entity.SysLog;
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
import com.pig4cloud.pig.common.core.util.WebUtils;
import com.pig4cloud.pig.common.log.event.SysLogEvent;
import com.pig4cloud.pig.common.log.util.SysLogUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.event.LogoutSuccessEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
import org.springframework.stereotype.Component;
/**
* @author zhangran
* @date 2022-06-02
*
* 事件机制处理退出相关
*/
@Slf4j
@Component
public class PigLogoutSuccessEventHandler implements ApplicationListener<LogoutSuccessEvent> {
@Override
public void onApplicationEvent(LogoutSuccessEvent event) {
Authentication authentication = (Authentication) event.getSource();
if (CollUtil.isNotEmpty(authentication.getAuthorities())) {
handle(authentication);
}
}
/**
* 处理退出成功方法
* <p>
* 获取到登录的authentication 对象
* @param authentication 登录对象
*/
public void handle(Authentication authentication) {
log.info("用户:{} 退出成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
SysLog logVo = SysLogUtils.getSysLog();
logVo.setTitle("退出成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);
// 设置对应的token
WebUtils.getRequest().ifPresent(request -> logVo.setParams(request.getHeader(HttpHeaders.AUTHORIZATION)));
// 这边设置ServiceId
if (authentication instanceof OAuth2Authorization) {
OAuth2Authorization auth2Authentication = (OAuth2Authorization) authentication;
logVo.setServiceId(auth2Authentication.getRegisteredClientId());
}
logVo.setCreateBy(authentication.getName());
logVo.setUpdateBy(authentication.getName());
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
}
}

View File

@ -1,4 +1,4 @@
package com.pig4cloud.pig.common.security.handler; package com.pig4cloud.pig.auth.support.handler;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -11,7 +11,7 @@ import java.io.IOException;
/** /**
* @author lengleng * @author lengleng
* @date 2020/10/6 * @date 2022-06-02
* <p> * <p>
* sso 退出功能 根据客户端传入跳转 * sso 退出功能 根据客户端传入跳转
*/ */

View File

@ -48,8 +48,6 @@ public class SysLogUtils {
HttpServletRequest request = ((ServletRequestAttributes) Objects HttpServletRequest request = ((ServletRequestAttributes) Objects
.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); .requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
SysLog sysLog = new SysLog(); SysLog sysLog = new SysLog();
sysLog.setCreateBy(Objects.requireNonNull(getUsername()));
sysLog.setUpdateBy(Objects.requireNonNull(getUsername()));
sysLog.setType(LogTypeEnum.NORMAL.getType()); sysLog.setType(LogTypeEnum.NORMAL.getType());
sysLog.setRemoteAddr(ServletUtil.getClientIP(request)); sysLog.setRemoteAddr(ServletUtil.getClientIP(request));
sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI())); sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI()));

View File

@ -56,17 +56,17 @@
<artifactId>spring-security-oauth2-jose</artifactId> <artifactId>spring-security-oauth2-jose</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>io.springboot.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId> <artifactId>spring-security-oauth2-authorization-server</artifactId>
<version>0.3.0</version> <version>${spring.authorization.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId> <artifactId>spring-webmvc</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId> <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,24 +1,12 @@
package com.pig4cloud.pig.common.security.component; package com.pig4cloud.pig.common.security.component;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import com.nimbusds.jose.jwk.source.JWKSource;
import com.nimbusds.jose.proc.SecurityContext;
import com.pig4cloud.pig.common.security.service.PigRedisOAuth2AuthorizationConsentService; import com.pig4cloud.pig.common.security.service.PigRedisOAuth2AuthorizationConsentService;
import com.pig4cloud.pig.common.security.service.PigRedisOAuth2AuthorizationService; import com.pig4cloud.pig.common.security.service.PigRedisOAuth2AuthorizationService;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsent;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService; import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.UUID;
/** /**
* @author lengleng * @author lengleng
* @date 2021/10/16 * @date 2021/10/16
@ -35,22 +23,4 @@ public class PigTokenStoreAutoConfiguration {
return new PigRedisOAuth2AuthorizationConsentService(redisTemplate); return new PigRedisOAuth2AuthorizationConsentService(redisTemplate);
} }
@Bean
@SneakyThrows
public JWKSource<SecurityContext> jwkSource() {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
// @formatter:off
RSAKey rsaKey= new RSAKey.Builder(publicKey)
.privateKey(privateKey)
.keyID(UUID.randomUUID().toString())
.build();
JWKSet jwkSet = new JWKSet(rsaKey);
return (jwkSelector, securityContext) -> jwkSelector.select(jwkSet);
}
} }

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.common.security.handler;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
/**
* @author lengleng
* @date 2019/2/1 认证失败事件处理器
*/
public abstract class AbstractAuthenticationFailureEventHandler
implements ApplicationListener<AbstractAuthenticationFailureEvent> {
/**
* Handle an application event.
* @param event the event to respond to
*/
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
AuthenticationException authenticationException = event.getException();
Authentication authentication = (Authentication) event.getSource();
handle(authenticationException, authentication);
}
/**
* 处理登录成功方法
* <p>
* @param authenticationException 登录的authentication 对象
* @param authentication 登录的authenticationException 对象
*/
public abstract void handle(AuthenticationException authenticationException, Authentication authentication);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.common.security.handler;
import cn.hutool.core.collection.CollUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;
/**
* @author lengleng
* @date 2019/2/1 认证成功事件处理器
*/
public abstract class AbstractAuthenticationSuccessEventHandler
implements ApplicationListener<AuthenticationSuccessEvent> {
/**
* Handle an application event.
* @param event the event to respond to
*/
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
Authentication authentication = (Authentication) event.getSource();
if (CollUtil.isNotEmpty(authentication.getAuthorities())) {
handle(authentication);
}
}
/**
* 处理登录成功方法
* <p>
* 获取到登录的authentication 对象
* @param authentication 登录对象
*/
public abstract void handle(Authentication authentication);
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.common.security.handler;
import cn.hutool.core.collection.CollUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.LogoutSuccessEvent;
import org.springframework.security.core.Authentication;
/**
* @author zhangran
* @date 2021/6/23 退出成功事件处理器
*/
public abstract class AbstractLogoutSuccessEventHandler implements ApplicationListener<LogoutSuccessEvent> {
/**
* Handle an application event.
* @param event the event to respond to
*/
@Override
public void onApplicationEvent(LogoutSuccessEvent event) {
Authentication authentication = (Authentication) event.getSource();
if (CollUtil.isNotEmpty(authentication.getAuthorities())) {
handle(authentication);
}
}
/**
* 处理退出成功方法
* <p>
* 获取到登录的authentication 对象
* @param authentication 登录对象
*/
public abstract void handle(Authentication authentication);
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common</artifactId>
<version>3.4.10</version>
</parent>
<artifactId>pig-common-test</artifactId>
<packaging>jar</packaging>
<description>pig oauth 2.0 单元测试工具类</description>
<dependencies>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,29 +0,0 @@
package com.pig4cloud.pig.test.annotation;
import com.pig4cloud.pig.test.WithMockSecurityContextFactory;
import org.springframework.security.test.context.support.WithSecurityContext;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @author lengleng
* @date 2020/9/22
* <p>
* WithMockOAuth2User 注解
*/
@Retention(RetentionPolicy.RUNTIME)
@WithSecurityContext(factory = WithMockSecurityContextFactory.class)
public @interface WithMockOAuth2User {
/**
* 用户名
*/
String username() default "admin";
/**
* 密码
*/
String password() default "123456";
}

View File

@ -1,29 +0,0 @@
package com.pig4cloud.pig.test.kit;
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
import org.springframework.http.HttpHeaders;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
/**
* @author lengleng
* @date 2020/9/22
* <p>
* Mock 工具类
*/
public class OAuthMockKit {
/**
* mock 请求增加统一请求头
* @return RequestPostProcessor 类似于拦截器
*/
public static RequestPostProcessor token() {
return mockRequest -> {
OAuth2ClientContext clientContext = SpringContextHolder.getBean(OAuth2ClientContext.class);
String token = clientContext.getAccessToken().getValue();
mockRequest.addHeader(HttpHeaders.AUTHORIZATION, String.format("Bearer: %s", token));
return mockRequest;
};
}
}

View File

@ -40,6 +40,5 @@
<module>pig-common-security</module> <module>pig-common-security</module>
<module>pig-common-feign</module> <module>pig-common-feign</module>
<module>pig-common-swagger</module> <module>pig-common-swagger</module>
<!-- <module>pig-common-test</module>-->
</modules> </modules>
</project> </project>

View File

@ -0,0 +1,30 @@
package com.pig4cloud.pig.admin.api.vo;
import lombok.Data;
import java.time.Instant;
/**
* 前端展示令牌管理
*
* @author lengleng
* @date 2022/6/2
*/
@Data
public class TokenVo {
private String id;
private Long userId;
private String clientId;
private String username;
private String accessToken;
private Instant issuedAt;
private Instant expiresAt;
}

View File

@ -170,7 +170,7 @@ public class UserController {
* @return 用户集合 * @return 用户集合
*/ */
@GetMapping("/page") @GetMapping("/page")
public R<IPage<List<UserVO>>> getUserPage(Page page, UserDTO userDTO) { public R<IPage<UserVO>> getUserPage(Page page, UserDTO userDTO) {
return R.ok(userService.getUserWithRolePage(page, userDTO)); return R.ok(userService.getUserWithRolePage(page, userDTO));
} }

View File

@ -51,7 +51,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @param userDTO 查询参数 * @param userDTO 查询参数
* @return list * @return list
*/ */
IPage<List<UserVO>> getUserVosPage(Page page, @Param("query") UserDTO userDTO); IPage<UserVO> getUserVosPage(Page page, @Param("query") UserDTO userDTO);
/** /**
* 通过ID查询用户信息 * 通过ID查询用户信息

View File

@ -49,7 +49,7 @@ public interface SysUserService extends IService<SysUser> {
* @param userDTO 参数列表 * @param userDTO 参数列表
* @return * @return
*/ */
IPage<List<UserVO>> getUserWithRolePage(Page page, UserDTO userDTO); IPage<UserVO> getUserWithRolePage(Page page, UserDTO userDTO);
/** /**
* 删除用户 * 删除用户

View File

@ -142,7 +142,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return * @return
*/ */
@Override @Override
public IPage<List<UserVO>> getUserWithRolePage(Page page, UserDTO userDTO) { public IPage<UserVO> getUserWithRolePage(Page page, UserDTO userDTO) {
return baseMapper.getUserVosPage(page, userDTO); return baseMapper.getUserVosPage(page, userDTO);
} }

441
pom.xml
View File

@ -16,231 +16,232 @@
~ limitations under the License. ~ limitations under the License.
--> -->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.pig4cloud</groupId> <groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId> <artifactId>pig</artifactId>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<version>3.5.0-SNAPSHOT</version> <version>3.5.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<url>https://www.pig4cloud.com</url> <url>https://www.pig4cloud.com</url>
<properties> <properties>
<spring-boot.version>2.7.0</spring-boot.version> <spring-boot.version>2.7.0</spring-boot.version>
<spring-cloud.version>2021.0.3</spring-cloud.version> <spring-cloud.version>2021.0.3</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version> <spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<spring-boot-admin.version>2.6.7</spring-boot-admin.version> <spring-boot-admin.version>2.6.7</spring-boot-admin.version>
<hutool.version>5.8.2</hutool.version> <spring.authorization.version>0.3.0</spring.authorization.version>
<dynamic-ds.version>3.5.1</dynamic-ds.version> <hutool.version>5.8.2</hutool.version>
<captcha.version>2.2.2</captcha.version> <dynamic-ds.version>3.5.1</dynamic-ds.version>
<velocity.version>2.3</velocity.version> <captcha.version>2.2.2</captcha.version>
<velocity.tool.version>3.1</velocity.tool.version> <velocity.version>2.3</velocity.version>
<configuration.version>1.10</configuration.version> <velocity.tool.version>3.1</velocity.tool.version>
<jasypt.version>2.1.0</jasypt.version> <configuration.version>1.10</configuration.version>
<swagger.fox.version>3.0.0</swagger.fox.version> <jasypt.version>2.1.0</jasypt.version>
<xxl-job.version>2.3.1</xxl-job.version> <swagger.fox.version>3.0.0</swagger.fox.version>
<docker.plugin.version>0.32.0</docker.plugin.version> <xxl-job.version>2.3.1</xxl-job.version>
<docker.host>http://192.168.0.100:2375</docker.host> <docker.plugin.version>0.32.0</docker.plugin.version>
<docker.registry>192.168.0.100</docker.registry> <docker.host>http://192.168.0.100:2375</docker.host>
<docker.namespace>pig4cloud</docker.namespace> <docker.registry>192.168.0.100</docker.registry>
<docker.username>username</docker.username> <docker.namespace>pig4cloud</docker.namespace>
<docker.password>password</docker.password> <docker.username>username</docker.username>
<git.commit.plugin>4.9.9</git.commit.plugin> <docker.password>password</docker.password>
<spring.checkstyle.plugin>0.0.32</spring.checkstyle.plugin> <git.commit.plugin>4.9.9</git.commit.plugin>
</properties> <spring.checkstyle.plugin>0.0.32</spring.checkstyle.plugin>
</properties>
<!-- 以下依赖 全局所有的模块都会引入 --> <!-- 以下依赖 全局所有的模块都会引入 -->
<dependencies> <dependencies>
<!--配置文件处理器--> <!--配置文件处理器-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!--配置文件加解密--> <!--配置文件加解密-->
<dependency> <dependency>
<groupId>com.github.ulisesbocchio</groupId> <groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId> <artifactId>jasypt-spring-boot-starter</artifactId>
<version>${jasypt.version}</version> <version>${jasypt.version}</version>
</dependency> </dependency>
<!--监控--> <!--监控-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<!--监控客户端--> <!--监控客户端-->
<dependency> <dependency>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId> <artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin.version}</version> <version>${spring-boot-admin.version}</version>
</dependency> </dependency>
<!--Lombok--> <!--Lombok-->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--测试依赖--> <!--测试依赖-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<modules> <modules>
<module>pig-register</module> <module>pig-register</module>
<module>pig-gateway</module> <module>pig-gateway</module>
<module>pig-auth</module> <module>pig-auth</module>
<module>pig-upms</module> <module>pig-upms</module>
<module>pig-common</module> <module>pig-common</module>
<module>pig-visual</module> <module>pig-visual</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<!--pig 公共版本定义--> <!--pig 公共版本定义-->
<dependency> <dependency>
<groupId>com.pig4cloud</groupId> <groupId>com.pig4cloud</groupId>
<artifactId>pig-common-bom</artifactId> <artifactId>pig-common-bom</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<!-- spring boot 依赖 --> <!-- spring boot 依赖 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId> <artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<!-- spring cloud 依赖 --> <!-- spring cloud 依赖 -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId> <artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version> <version>${spring-cloud.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<!-- spring cloud alibaba 依赖 --> <!-- spring cloud alibaba 依赖 -->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId> <artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version> <version>${spring-cloud-alibaba.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
<resources> <resources>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
</resources> </resources>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
<configuration> <configuration>
<finalName>${project.build.finalName}</finalName> <finalName>${project.build.finalName}</finalName>
<layers> <layers>
<enabled>true</enabled> <enabled>true</enabled>
</layers> </layers>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<goals> <goals>
<goal>repackage</goal> <goal>repackage</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>io.fabric8</groupId> <groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId> <artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version> <version>${docker.plugin.version}</version>
<configuration> <configuration>
<!-- Docker Remote Api--> <!-- Docker Remote Api-->
<dockerHost>${docker.host}</dockerHost> <dockerHost>${docker.host}</dockerHost>
<!-- Docker 镜像私服--> <!-- Docker 镜像私服-->
<registry>${docker.registry}</registry> <registry>${docker.registry}</registry>
<!-- 认证信息--> <!-- 认证信息-->
<authConfig> <authConfig>
<push> <push>
<username>${docker.username}</username> <username>${docker.username}</username>
<password>${docker.password}</password> <password>${docker.password}</password>
</push> </push>
</authConfig> </authConfig>
<images> <images>
<image> <image>
<!-- 镜像名称: 172.17.0.111/library/pig-gateway:2.6.3--> <!-- 镜像名称: 172.17.0.111/library/pig-gateway:2.6.3-->
<name>${docker.registry}/${docker.namespace}/${project.name}:${project.version}</name> <name>${docker.registry}/${docker.namespace}/${project.name}:${project.version}</name>
<build> <build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile> <dockerFile>${project.basedir}/Dockerfile</dockerFile>
</build> </build>
</image> </image>
</images> </images>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
<plugins> <plugins>
<!--打包jar 与git commit 关联插件--> <!--打包jar 与git commit 关联插件-->
<plugin> <plugin>
<groupId>io.github.git-commit-id</groupId> <groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId> <artifactId>git-commit-id-maven-plugin</artifactId>
<version>${git.commit.plugin}</version> <version>${git.commit.plugin}</version>
<executions> <executions>
<execution> <execution>
<id>get-the-git-infos</id> <id>get-the-git-infos</id>
<goals> <goals>
<goal>revision</goal> <goal>revision</goal>
</goals> </goals>
<phase>initialize</phase> <phase>initialize</phase>
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory> <failOnNoGitDirectory>false</failOnNoGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile> <generateGitPropertiesFile>true</generateGitPropertiesFile>
<!--因为项目定制了jackson的日期时间序列化/反序列化格式,因此这里要进行配置,不然通过management.info.git.mode=full进行完整git信息监控时会存在问题--> <!--因为项目定制了jackson的日期时间序列化/反序列化格式,因此这里要进行配置,不然通过management.info.git.mode=full进行完整git信息监控时会存在问题-->
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat> <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
<includeOnlyProperties> <includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty> <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.(id|message|time).*$</includeOnlyProperty> <includeOnlyProperty>^git.commit.(id|message|time).*$</includeOnlyProperty>
</includeOnlyProperties> </includeOnlyProperties>
</configuration> </configuration>
</plugin> </plugin>
<!--代码格式插件默认使用spring 规则--> <!--代码格式插件默认使用spring 规则-->
<plugin> <plugin>
<groupId>io.spring.javaformat</groupId> <groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId> <artifactId>spring-javaformat-maven-plugin</artifactId>
<version>${spring.checkstyle.plugin}</version> <version>${spring.checkstyle.plugin}</version>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles> <profiles>
<profile> <profile>
<id>dev</id> <id>dev</id>
<properties> <properties>
<!-- 环境标识,需要与配置文件的名称相对应 --> <!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>dev</profiles.active> <profiles.active>dev</profiles.active>
</properties> </properties>
<activation> <activation>
<!-- 默认环境 --> <!-- 默认环境 -->
<activeByDefault>true</activeByDefault> <activeByDefault>true</activeByDefault>
</activation> </activation>
</profile> </profile>
</profiles> </profiles>
</project> </project>