2017-04-20 1 views
0

Je suis intégré le keycloak avec l'application printanière. J'ai ajouté l'adaptateur de sécurité keycloak spring à mon fichier pom.xml et ajouté la configuration de sécurité. Après tout, je suis en mesure d'accéder à l'api de repos sans jeton. Comment je résous ce problème?le repos de la sécurité du printemps api pas sécurisé avec keycloak

@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"; 
    } 

Répondre

0

"/ bonjour" ne correspond pas ""/école-admin * » spécifiée dans la méthode de configuration.

+0

«/bonjour » est à l'intérieur de la cartographie de la demande de niveau de classe «/école-admin * » – boycod3

+0

Et avez-vous essayé avec l'ajout d'une barre oblique avant le * «/école-admin/* » –

+0

J'ai essayé aussi. – boycod3

2

Pourriez-vous s'il vous plaît t ry, suivant la fonction de configuration.

@Override 
protected void configure(HttpSecurity http) throws Exception { 
     super.configure(http); 
     http.authorizeRequests() 
      .anyRequest().fullyAuthenticated(); 
} 

vous pouvez utiliser, @PreAuthorize ("hasRole (ADMIN)") annotation sur la fonction de contrôleur, avec la configuration suivante de printemps;

@EnableGlobalMethodSecurity(prePostEnabled = true) 
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter