Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring multitenancy Api-Server not working for external issuer #62

Open
igorroman777 opened this issue Jun 8, 2022 · 0 comments
Open

Comments

@igorroman777
Copy link

igorroman777 commented Jun 8, 2022

I have a problem. I have made api-Server (spring boot) as multi-tenancy. It works locally:
`

Map<String, AuthenticationManager> authenticationManagers = new HashMap<>();
JwtIssuerAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerAuthenticationManagerResolver(
		authenticationManagers::get);

protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers(AUTH_WHITELIST).permitAll(); // whitelist Swagger UI resources
// .antMatchers("/admin/**").permitAll();

	// for customergui :: customergui -> apiserver issuer uri
	authenticationManagers.put(customerguiIssuerUriAntragsportal, jwt(apiserverIssuerUriAntragsportal));

	// for configurationgui :: configurationgui -> apiserver issuer uri
	authenticationManagers.put(configurationguiIssuerUriConfigGui, jwt(apiserveriIssuerUriConfigGui));

	http
			.csrf().disable()
			.authorizeRequests(authorize -> authorize
					// .mvcMatchers("/**/message/**").hasAuthority("SCOPE_message:read")
					.antMatchers("/admin/**").hasRole("ACCESS_ADMIN_API")
					.anyRequest().authenticated())
			.oauth2ResourceServer(oauth2ResourceServer -> oauth2ResourceServer
					.authenticationManagerResolver(this.authenticationManagerResolver));

}

AuthenticationManager jwt(String issuerUri) {
	JwtAuthenticationProvider authenticationProvider = new JwtAuthenticationProvider(
			JwtDecoders.fromOidcIssuerLocation(issuerUri));
	authenticationProvider.setJwtAuthenticationConverter(getJwtAuthenticationConverter());

	return authenticationProvider::authenticate;
}

JwtAuthenticationConverter getJwtAuthenticationConverter() {
	JwtAuthenticationConverter conv = new JwtAuthenticationConverter();

	conv.setJwtGrantedAuthoritiesConverter(jwt -> mapKeycloakRealmRoles(jwt));
	return conv;
}

`

but productively not. there comes api-call from getaway-client. And this client is in other external network. I.e host in issuer is different than in api server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant