fix ld
This commit is contained in:
@@ -13,7 +13,6 @@ import com.senmesh.security.handle.MyAuthenctiationFailureHandler;
|
||||
import com.senmesh.security.mobile.MobileAuthenticationProvider;
|
||||
import com.senmesh.security.social.service.StandardClientRegistrationRepository;
|
||||
import com.senmesh.security.social.wechat.service.WechatOauthLoginProvider;
|
||||
import com.senmesh.security.ssb.SsbAuthenticationProvider;
|
||||
import com.senmesh.security.temptoken.TokenAuthenticationProvider;
|
||||
import com.senmesh.security.upassword.UpasswordAuthenticationProvider;
|
||||
import com.senmesh.security.util.SecurityPropertyUtils;
|
||||
@@ -79,12 +78,6 @@ public class SecurityConfiguration {
|
||||
UpasswordAuthenticationProvider upasswordAuthenticationProvider(UserLoginService userLoginService) {
|
||||
return new UpasswordAuthenticationProvider(userLoginService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(UserLoginService.class)
|
||||
SsbAuthenticationProvider ssbAuthenticationProvider(UserLoginService userLoginService) {
|
||||
return new SsbAuthenticationProvider(userLoginService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(UserLoginService.class)
|
||||
|
||||
@@ -31,8 +31,6 @@ import com.senmesh.security.mobile.MobileAuthenticationProvider;
|
||||
import com.senmesh.security.social.service.StandardAuthorizationCodeTokenResponseClient;
|
||||
import com.senmesh.security.social.service.StandardOAuth2UserService;
|
||||
import com.senmesh.security.social.service.StandardOauth2AuthorizationRequestResolver;
|
||||
import com.senmesh.security.ssb.SsbAuthenticationFilter;
|
||||
import com.senmesh.security.ssb.SsbAuthenticationProvider;
|
||||
import com.senmesh.security.temptoken.TokenAuthenticationFilter;
|
||||
import com.senmesh.security.temptoken.TokenAuthenticationProvider;
|
||||
import com.senmesh.security.upassword.UpasswordAuthenticationFilter;
|
||||
@@ -78,8 +76,6 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired(required = false)
|
||||
private TokenAuthenticationProvider tokenAuthenticationProvider;
|
||||
@Autowired
|
||||
private SsbAuthenticationProvider ssbAuthenticationProvider;
|
||||
|
||||
@Autowired(required = false)
|
||||
private UcardAuthenticationProvider ucardAuthenticationProvider;
|
||||
@@ -99,7 +95,6 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
auth.authenticationProvider(upasswordAuthenticationProvider)
|
||||
.authenticationProvider(mobileAuthenticationProvider)
|
||||
.authenticationProvider(tokenAuthenticationProvider)
|
||||
.authenticationProvider(ssbAuthenticationProvider)
|
||||
.authenticationProvider(ucardAuthenticationProvider);
|
||||
;
|
||||
}
|
||||
@@ -151,12 +146,11 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
UsernamePasswordAuthenticationFilter.class);
|
||||
http.addFilterAfter(mobileAuthenticationFilter(), UpasswordAuthenticationFilter.class);
|
||||
http.addFilterAfter(tokenAuthenticationFilter(), UpasswordAuthenticationFilter.class);
|
||||
http.addFilterAfter(ssbAuthenticationFilter(), UpasswordAuthenticationFilter.class);
|
||||
http.addFilterAfter(ucardAuthenticationFilter(), UpasswordAuthenticationFilter.class);
|
||||
|
||||
|
||||
// 禁用CSRF
|
||||
http.csrf().disable();
|
||||
// http.csrf().disable();
|
||||
http.headers().frameOptions().deny();
|
||||
http.headers().xssProtection().block(true);
|
||||
http.headers().contentTypeOptions();
|
||||
@@ -205,7 +199,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
/**
|
||||
* 手机号登录请求过滤器
|
||||
*
|
||||
* @param authenticationManager
|
||||
* @param
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @author sr on 2020-06-04
|
||||
@@ -248,11 +242,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
return filter;
|
||||
}
|
||||
|
||||
private SsbAuthenticationFilter ssbAuthenticationFilter() throws Exception {
|
||||
SsbAuthenticationFilter filter = new SsbAuthenticationFilter();
|
||||
addHandler(filter);
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 身份证登录
|
||||
|
||||
@@ -75,7 +75,7 @@ public class UserInfoDTO implements Serializable{
|
||||
|
||||
public void setPassword(String password){
|
||||
this.password = password;
|
||||
if (!PasswordUtils.match(UserUtils.DEFAULT_ORG_USER_PASSWORD, password)) {
|
||||
if (!PasswordUtils.match(UserUtils.getDefaultOrgUserPassword(), password)) {
|
||||
this.originPassword = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.senmesh.common.util.ResponseUtils;
|
||||
import com.senmesh.security.config.SecurityProperties;
|
||||
import com.senmesh.security.dto.SecurityUserDTO;
|
||||
import com.senmesh.security.jwt.JwtTokenUtils;
|
||||
import com.senmesh.security.ssb.SsbAuthenticationFilter;
|
||||
import com.senmesh.security.util.SecurityUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -67,12 +66,7 @@ public class MyLoginSuccessHandler extends SavedRequestAwareAuthenticationSucces
|
||||
AlitaResult.success(CasTokenDTO.builder().token(token).build()));
|
||||
} else {
|
||||
String successPage = securityProperties.getLoginSuccessPage();
|
||||
if (request.getRequestURI().contains(SsbAuthenticationFilter.LOGIN_URI)) {
|
||||
successPage = securityProperties.getLoginH5SuccessPage();
|
||||
}
|
||||
String successToUrl =
|
||||
SecurityUtils.dealSuccessUrl(request, successPage, token);
|
||||
response.sendRedirect(successToUrl);
|
||||
response.sendRedirect(successPage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||
|
||||
import com.senmesh.security.ssb.SsbAuthenticationFilter;
|
||||
import com.senmesh.usercenter.auth.constant.AuthTypeEnum;
|
||||
|
||||
public enum CommonOAuth2Provider {
|
||||
@@ -26,23 +25,7 @@ public enum CommonOAuth2Provider {
|
||||
return builder;
|
||||
}
|
||||
},
|
||||
|
||||
SSBAPP {
|
||||
|
||||
@Override
|
||||
public Builder getBuilder(String registrationId) {
|
||||
ClientRegistration.Builder builder = getBuilder(registrationId,
|
||||
ClientAuthenticationMethod.BASIC, DEFAULT_REDIRECT_URL);
|
||||
builder.authorizationUri("https://api.eshimin.com/newOauth/authorize");
|
||||
builder.tokenUri("https://api.eshimin.com/newOauth/accessToken");
|
||||
builder.userInfoUri("https://api.eshimin.com/newOauth/userInfo");
|
||||
builder.clientName(AuthTypeEnum.SSB_APP.name());
|
||||
builder.scope("read");
|
||||
builder.redirectUriTemplate("{baseUrl}/" + SsbAuthenticationFilter.LOGIN_URI);
|
||||
builder.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE);
|
||||
return builder;
|
||||
}
|
||||
},
|
||||
|
||||
WECHAT_LITE {
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.senmesh.security.social.ssb.service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.senmesh.sdk.ssb.SsbProperties;
|
||||
import com.senmesh.sdk.ssb.util.SM2Utils;
|
||||
import com.senmesh.security.social.service.IOauthProvider;
|
||||
import com.senmesh.security.util.SecurityUtils;
|
||||
import com.senmesh.usercenter.auth.constant.AuthTypeEnum;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SsbOauthLoginProvider implements IOauthProvider {
|
||||
|
||||
private static final String AUTH_URL =
|
||||
"https://api.eshimin.com/newOauth/authorize?client_id=%s&response_type=authorization_code&scope=read&redirect_uri=%s×tamp=%s&sign=%s&state=%s";
|
||||
|
||||
@Autowired
|
||||
private SsbProperties ssbProperties;
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return AuthTypeEnum.SSB_APP.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2AuthorizationRequest decorateRequest(HttpServletRequest request,
|
||||
OAuth2AuthorizationRequest authorizationRequest) {
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String sign = SM2Utils.sign(ssbProperties.getSm2PrivateKey(),
|
||||
ssbProperties.getAppKey() + ssbProperties.getAppSecret() + timestamp,
|
||||
ssbProperties.getAppKey());
|
||||
|
||||
// 指定成功跳转地址
|
||||
String redirectUrl =
|
||||
SecurityUtils.dealRedirectUrl(request, authorizationRequest.getRedirectUri());
|
||||
|
||||
String state = "123";
|
||||
|
||||
// 微信Authorization Request URL
|
||||
String authorizationRequestUri =
|
||||
String.format(AUTH_URL,
|
||||
authorizationRequest.getClientId(),
|
||||
SecurityUtils.encodeURL(redirectUrl),
|
||||
timestamp,
|
||||
sign,
|
||||
state);
|
||||
|
||||
return OAuth2AuthorizationRequest.from(authorizationRequest)
|
||||
.authorizationRequestUri(authorizationRequestUri)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.senmesh.security.ssb;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
import com.senmesh.common.util.JsonUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 账号密码认证过滤器,指定请求组装token,调起认证
|
||||
*
|
||||
* @author sr on 2021-06-21
|
||||
*/
|
||||
@Slf4j
|
||||
public class SsbAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
||||
|
||||
private boolean postOnly = true;
|
||||
|
||||
public static final String REQUEST_METHOD = "GET";
|
||||
public static final String LOGIN_URI = "/h5/ssb_login_notify";
|
||||
public static final AntPathRequestMatcher requiresAuthenticationRequestMatcher =
|
||||
new AntPathRequestMatcher(LOGIN_URI, REQUEST_METHOD);
|
||||
|
||||
public static final String PARAM_PLATFORM = "platform";
|
||||
public static final String PARAM_ACCESS_TOKEN = "access_token";
|
||||
public static final String PARAM_CODE = "code";
|
||||
public static final String PARAM_STATE = "state";
|
||||
|
||||
public SsbAuthenticationFilter() {
|
||||
super(requiresAuthenticationRequestMatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication attemptAuthentication(HttpServletRequest request,
|
||||
HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
||||
|
||||
if (postOnly && !REQUEST_METHOD.equals(request.getMethod())) {
|
||||
throw new AuthenticationServiceException(
|
||||
"Authentication method not supported: " + request.getMethod());
|
||||
}
|
||||
|
||||
String platform = request.getParameter(PARAM_PLATFORM);
|
||||
String accessToken = request.getParameter(PARAM_ACCESS_TOKEN);
|
||||
String code = request.getParameter(PARAM_CODE);
|
||||
String state = request.getParameter(PARAM_STATE);
|
||||
log.info("ssb login req params:{}", JsonUtils.toJsonString(request.getParameterMap()));
|
||||
AbstractAuthenticationToken authRequest = new SsbAuthenticationToken(
|
||||
SsbLoginDTO.builder().accessToken(accessToken).platform(platform).code(code).state(state).build(), accessToken);
|
||||
|
||||
// Allow subclasses to set the "details" property
|
||||
setDetails(request, authRequest);
|
||||
|
||||
return this.getAuthenticationManager().authenticate(authRequest);
|
||||
}
|
||||
|
||||
protected void setDetails(HttpServletRequest request, AbstractAuthenticationToken authRequest) {
|
||||
authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.senmesh.security.ssb;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import com.senmesh.common.exception.util.Assert;
|
||||
import com.senmesh.common.util.JsonUtils;
|
||||
import com.senmesh.common.validation.util.ValidateUtils;
|
||||
import com.senmesh.security.dto.SecurityUserDTO;
|
||||
import com.senmesh.security.expection.BadLoginException;
|
||||
import com.senmesh.security.mapstruct.UserMapMapper;
|
||||
import com.senmesh.usercenter.user.login.dto.UserDetailDTO;
|
||||
import com.senmesh.usercenter.user.login.service.UserLoginService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 账号密码认证provider,比对信息是否匹配
|
||||
*
|
||||
* @author sr on 2021-06-21
|
||||
*/
|
||||
@Slf4j
|
||||
public class SsbAuthenticationProvider implements AuthenticationProvider {
|
||||
|
||||
private UserLoginService userLoginService;
|
||||
|
||||
public SsbAuthenticationProvider(UserLoginService userLoginService) {
|
||||
this.userLoginService = userLoginService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
SsbLoginDTO ssbLoginDTO =
|
||||
(SsbLoginDTO) authentication.getPrincipal();
|
||||
log.info("ssb login req:{}", JsonUtils.toJsonString(ssbLoginDTO));
|
||||
String errMsg = ValidateUtils.validate(ssbLoginDTO);
|
||||
Assert.isTrue(errMsg == null, new BadLoginException(errMsg));
|
||||
SecurityUserDTO loadedUser = null;
|
||||
try {
|
||||
UserDetailDTO userDetailDTO = this.userLoginService.loadUser(ssbLoginDTO);
|
||||
loadedUser = UserMapMapper.INSTANCE.dtoToDto(userDetailDTO);
|
||||
} catch (BadLoginException be) {
|
||||
throw be;
|
||||
} catch (Exception e) {
|
||||
throw new BadLoginException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
SsbAuthenticationToken result =
|
||||
new SsbAuthenticationToken(loadedUser, listUserGrantedAuthorities(loadedUser));
|
||||
result.setDetails(authentication.getDetails());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> authentication) {
|
||||
return (SsbAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
}
|
||||
|
||||
private Set<GrantedAuthority> listUserGrantedAuthorities(UserDetails userDetails) {
|
||||
// 什么都不用做,访问资源鉴权的时会拿userDetail去缓存获取对应权限
|
||||
return new HashSet<GrantedAuthority>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.senmesh.security.ssb;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
|
||||
/**
|
||||
* 账号密码认证信息
|
||||
* @author sr on 2021-06-21
|
||||
*/
|
||||
public class SsbAuthenticationToken extends UsernamePasswordAuthenticationToken {
|
||||
|
||||
public SsbAuthenticationToken(Object principal, Object credentials) {
|
||||
super(principal, credentials);
|
||||
}
|
||||
|
||||
public SsbAuthenticationToken(Object principal, Object credentials,
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
super(principal, credentials, authorities);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.senmesh.security.ssb;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SsbLoginDTO implements Serializable {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 6780283569028235063L;
|
||||
/** 平台标识
|
||||
eshimin: 随申办 APP
|
||||
weixinmini:微信小程序
|
||||
weixinmp:微信公众号
|
||||
alipaymini:支付宝小程序
|
||||
alipayfuwu:支付宝生活号 **/
|
||||
// @NotBlank(message = "平台标识不能为空")
|
||||
private String platform;
|
||||
/** 用户令牌,作为获取用户信息的入参 **/
|
||||
private String accessToken;
|
||||
/** oauth code **/
|
||||
private String code;
|
||||
private String state;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user