Merge branch 'dev' of https://gitee.ltd/pig/pigx into dev
# Conflicts: # pigx-config/src/main/resources/config/pigx-codegen-dev.yml
This commit is contained in:
commit
58d8f245e5
25 files changed
+178
-83
No files matched your search
+1
@@ -99,6 +99,7 @@ public class MobileLoginSuccessHandler implements AuthenticationSuccessHandler {
|
||||
throw new BadCredentialsException(
|
||||
"Failed to decode basic authentication token");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-13
@@ -24,6 +24,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationEventPublisher;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -43,7 +44,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
*/
|
||||
public class MobileAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
||||
private static final String SPRING_SECURITY_FORM_MOBILE_KEY = "mobile";
|
||||
private AuthenticationEventPublisher eventPublisher = new MobileAuthenticationFilter.NullEventPublisher();
|
||||
private AuthenticationEntryPoint authenticationEntryPoint = new MobileAuthenticationEntryPoint();
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -51,6 +51,9 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean postOnly = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private AuthenticationEventPublisher eventPublisher;
|
||||
|
||||
public MobileAuthenticationFilter() {
|
||||
super(new AntPathRequestMatcher(SecurityConstants.MOBILE_TOKEN_URL, "POST"));
|
||||
@@ -76,8 +79,13 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||
|
||||
setDetails(request, mobileAuthenticationToken);
|
||||
|
||||
Authentication authResult = null;
|
||||
try {
|
||||
return this.getAuthenticationManager().authenticate(mobileAuthenticationToken);
|
||||
authResult = this.getAuthenticationManager().authenticate(mobileAuthenticationToken);
|
||||
|
||||
logger.debug("Authentication success: " + authResult);
|
||||
eventPublisher.publishAuthenticationSuccess(authResult);
|
||||
SecurityContextHolder.getContext().setAuthentication(authResult);
|
||||
|
||||
} catch (Exception failed) {
|
||||
SecurityContextHolder.clearContext();
|
||||
@@ -93,7 +101,8 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||
logger.error("authenticationEntryPoint handle error:{}", failed);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return authResult;
|
||||
}
|
||||
|
||||
private String obtainMobile(HttpServletRequest request) {
|
||||
@@ -104,15 +113,5 @@ public class MobileAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||
MobileAuthenticationToken authRequest) {
|
||||
authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
|
||||
}
|
||||
|
||||
private static final class NullEventPublisher implements AuthenticationEventPublisher {
|
||||
@Override
|
||||
public void publishAuthenticationFailure(AuthenticationException exception, Authentication authentication) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishAuthenticationSuccess(Authentication authentication) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -18,7 +18,10 @@
|
||||
package com.pig4cloud.pigx.common.security.mobile;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationEventPublisher;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -32,9 +35,12 @@ import org.springframework.stereotype.Component;
|
||||
* @date 2018/8/5
|
||||
* 手机号登录配置入口
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class MobileSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
@Autowired
|
||||
private AuthenticationEventPublisher defaultAuthenticationEventPublisher;
|
||||
private AuthenticationSuccessHandler mobileLoginSuccessHandler;
|
||||
private PigxUserDetailsService userDetailsService;
|
||||
|
||||
@@ -43,6 +49,7 @@ public class MobileSecurityConfigurer extends SecurityConfigurerAdapter<DefaultS
|
||||
MobileAuthenticationFilter mobileAuthenticationFilter = new MobileAuthenticationFilter();
|
||||
mobileAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
|
||||
mobileAuthenticationFilter.setAuthenticationSuccessHandler(mobileLoginSuccessHandler);
|
||||
mobileAuthenticationFilter.setEventPublisher(defaultAuthenticationEventPublisher);
|
||||
|
||||
MobileAuthenticationProvider mobileAuthenticationProvider = new MobileAuthenticationProvider();
|
||||
mobileAuthenticationProvider.setUserDetailsService(userDetailsService);
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/10/22
|
||||
* <p>
|
||||
* see JdbcClientDetailsService
|
||||
*/
|
||||
public class PigxClientDetailsService extends JdbcClientDetailsService {
|
||||
|
||||
public PigxClientDetailsService(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写原生方法支持redis缓存
|
||||
*
|
||||
* @param clientId
|
||||
* @return
|
||||
* @throws InvalidClientException
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = SecurityConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
|
||||
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
|
||||
return super.loadClientByClientId(clientId);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user