Spring Boot — поддержка нескольких эмитентов-uriJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Spring Boot — поддержка нескольких эмитентов-uri

Сообщение Anonymous »

Привет, я безуспешно искал в Интернете и надеюсь, что кто-нибудь из SO сможет помочь.
В настоящее время у меня есть API Spring Boot ( Версия 2.5.4), принимающая JWT, предоставленный Auth0. Теперь я создал там второго клиента и пытаюсь понять, как я могу поддерживать два или более Issuer-uri.
Вот как я сейчас это делаю:
Вот как я сейчас это делаю:
@Configuration
@EnableWebSecurity(debug = false)
@EnableGlobalMethodSecurity(
securedEnabled = true,
jsr250Enabled = true,
prePostEnabled = true
)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Value("${auth0.audience}")
private String audience;

@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
private String issuer;

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3010"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
configuration.setAllowCredentials(true);
configuration.addAllowedHeader("Authorization");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Override
protected void configure(HttpSecurity http) throws Exception {

http
.cors()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.headers().referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.SAME_ORIGIN)
.and()
.xssProtection()
.and()
.contentSecurityPolicy("script-src 'self'").and()
.and()
.csrf()
.disable()
.formLogin()
.disable()
.httpBasic()
.disable()
.exceptionHandling()
.authenticationEntryPoint(new RestAuthenticationEntryPoint())
.and()
.authorizeRequests()
.antMatchers("/api/v1/user/profile/**").permitAll()
.antMatchers("/user/profile/**").permitAll()
.antMatchers("/swagger-resources/**").permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2ResourceServer().jwt();
}

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/health", "/health/**");
}

@Bean
JwtDecoder jwtDecoder() {
/*
By default, Spring Security does not validate the "aud" claim of the token, to ensure that this token is
indeed intended for our app. Adding our own validator is easy to do:
*/

NimbusJwtDecoder jwtDecoder = (NimbusJwtDecoder)
JwtDecoders.fromOidcIssuerLocation(issuer);

OAuth2TokenValidator audienceValidator = new AudienceValidator(audience);
OAuth2TokenValidator withIssuer = JwtValidators.createDefaultWithIssuer(issuer);
OAuth2TokenValidator withAudience = new DelegatingOAuth2TokenValidator(withIssuer, audienceValidator);

jwtDecoder.setJwtValidator(withAudience);

return jwtDecoder;
}
}

Может ли кто-нибудь пролить свет, с помощью Node я могу просто установить Issuer-uri в виде массива строк, и это работает «из коробки». Надеетесь, что в Spring будет что-то подобное?
РЕДАКТИРОВАТЬ:
В случае необходимости вот мой файл сборки для версий:
plugins {
id "org.springframework.boot" version "2.5.4"
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "com.github.davidmc24.gradle.plugin.avro" version "1.2.0"
id "idea"
id 'com.google.cloud.tools.jib' version '3.0.0'
}

apply plugin: 'idea'

group 'org.example'
version '1.0'

java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}

jib.from.image = 'openjdk:15-jdk-buster'
jib.to.image = 'gcr.io/thefullstack/tfs-project-service'

ext {
avroVersion = "1.10.1"
}

repositories {
mavenCentral()
jcenter()
maven {
url "https://packages.confluent.io/maven/"
}
}

avro {
createSetters = true
fieldVisibility = "PRIVATE"
}

dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-elasticsearch')
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb'
implementation group: 'org.springframework.data', name: 'spring-data-elasticsearch'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.security', name: 'spring-security-oauth2-client'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache'
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation group: 'org.springframework.integration', name: 'spring-integration-core', version: '5.5.3'

// implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging', version: '1.2.8.RELEASE'
implementation("org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.2.5.RELEASE")
implementation("org.springframework.integration:spring-integration-core")

implementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.860'
implementation group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'

implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.12.3'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.3'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'

implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'

implementation group: 'com.auth0', name: 'java-jwt', version: '3.12.0'
implementation "org.apache.avro:avro:1.10.1"
implementation "org.apache.avro:avro:${avroVersion}"

implementation 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'

implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-web'

testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'

testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}


Подробнее здесь: https://stackoverflow.com/questions/691 ... issuer-uri
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»