Слияние кода завершено, страница обновится автоматически
<dependencies>
<!-- OAuth 2.1 зависимость -->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-oauth2-authorization-server -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId>
<version>0.4.0-M1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.com.xuxiaowei.boot/spring-boot-starter-wechat-miniprogram -->
<dependency>
<groupId>cn.com.xuxiaowei.boot</groupId>
<artifactId>spring-boot-starter-wechat-miniprogram</artifactId>
<version>0.0.2-alpha.1</version>
</dependency>
</dependencies>
package cloud.xuxiaowei.passport.configuration;
// import cloud.xuxiaowei.passport.handler.AccessTokenAuthenticationFailureHandlerImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2WeChatMiniProgramAuthenticationProvider;
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
import org.springframework.security.oauth2.server.authorization.web.authentication.*;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.RequestMatcher;
import java.util.Arrays;
/**
* Spring Security конфигурация
* <p>
* Подробное использование см.:
* <p>
* <a href=
* "https://gitee.com/xuxiaowei-cloud/xuxiaowei-cloud/blob/main/passport/src/main/java/cloud/xuxiaowei/passport/configuration/AuthorizationServerConfiguration.java">Gitee</a>
* <p>
* <a href=
* "https://github.com/xuxiaowei-cloud/xuxiaowei-cloud/blob/main/passport/src/main/java/cloud/xuxiaowei/passport/configuration/AuthorizationServerConfiguration.java">Github</a>
*
* @author xuxiaowei
* @since 0.0.1
*/
@Configuration
public class WebSecurityConfigurerAdapterConfiguration {
@Bean
@Order(-1)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
// Этот фрагмент кода взят из: OAuth2AuthorizationServerConfiguration#applyDefaultSecurity(HttpSecurity)
// @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
new OAuth2AuthorizationServerConfigurer();
RequestMatcher endpointsMatcher = authorizationServerConfigurer
.getEndpointsMatcher();
http
.requestMatcher(endpointsMatcher)
.authorizeRequests(authorizeRequests ->
authorizeRequests.anyRequest().authenticated()
)
.csrf(csrf -> csrf.ignoringRequestMatchers(endpointsMatcher))
.apply(authorizationServerConfigurer);
// @formatter:on
// Пользовательское клиентское разрешение
authorizationServerConfigurer.tokenEndpoint(tokenEndpointCustomizer -> tokenEndpointCustomizer
.accessTokenRequestConverter(new DelegatingAuthenticationConverter(Arrays.asList(
// Новое: WeChat OAuth2 для проверки авторизации, предоставленной {@link
// OAuth2WeChatMiniProgramAuthenticationToken}
new OAuth2WeChatMiniProgramAuthenticationConverter(),
// Значение по умолчанию: преобразователь аутентификации кода авторизации OAuth2
new OAuth2AuthorizationCodeAuthenticationConverter(),
// Значение по умолчанию: преобразователь аутентификации токена обновления OAuth2
new OAuth2RefreshTokenAuthenticationConverter())))
);
}
}
``` **Текст запроса:**
// 默认值:OAuth2 客户端凭据身份验证转换器
new OAuth2ClientCredentialsAuthenticationConverter())))
// 用于处理失败的身份验证尝试的策略。
// .errorResponseHandler(new AccessTokenAuthenticationFailureHandlerImpl())
);
// 微信小程序 OAuth2 身份验证提供程序
new OAuth2WeChatMiniProgramAuthenticationProvider(http);
return http.build();
}
**Перевод текста на русский язык:**
// Значение по умолчанию: преобразователь аутентификации клиента OAuth2
new OAuth2ClientCredentialsAuthenticationConverter());
// Стратегия для обработки неудачных попыток аутентификации.
// errorResponseHandler (новый AccessTokenAuthenticationFailureHandlerImpl ())
);
// Поставщик аутентификации OAuth2 для небольших программ WeChat
new OAuth2WeChatMiniProgramAuthenticationProvider (http);
вернуть http.build ();
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )