Ich habe den keycloak mit legacy spring app integriert. Ich habe den keycloak Spring Security Adapter zu meiner pom.xml-Datei hinzugefügt und die Sicherheitskonfiguration hinzugefügt. Nachdem alles erledigt ist, kann ich ohne Token auf die Rest-API zugreifen. Wie löse ich dieses Problem?spring security rest api nicht mit keycloak gesichert
@Configuration
@EnableWebSecurity
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class)
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter
{
/**
* Registers the KeycloakAuthenticationProvider with the authentication manager.
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(keycloakAuthenticationProvider());
}
/**
* Defines the session authentication strategy.
*/
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
super.configure(http);
http
.authorizeRequests()
.antMatchers("/school-admin*").hasRole("ADMIN")
.anyRequest().permitAll();
}
}
keycloak.json
{
"realm": "appscook",
"bearer-only": true,
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "external",
"resource": "ssd-backend"
}
Api
@RequestMapping(value="/hello",method=RequestMethod.GET)
@ResponseBody
public String getStandards(){
return "hello";
}
"/ hallo" ist innerhalb der Klassenstufe Anfrage mapping "/ school-admin *" – boycod3
Und haben Sie versuchen, einen Schrägstrich vor dem * "/ Schule-admin/*" –
mit dem Hinzufügen ich das auch versucht. – boycod3