Wpis z mikrobloga

Jest tutaj jakis wyjadacz Springa, a konkretniej Spring Security? #java #spring #programowanie

Mam sobie API. Access na podstawie JWT.
Niektore sciezki musza byc dostepne tylko jesli w JWT sa odpowiednie claimy.
Za cholere nie moge tego ogarnac.

Priviledges sa dostepne w SecurityContextHolder.getContext().getAuthentication().getAuthorities()
Moj konfig:

http
.csrf().disable()
.addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class)
.exceptionHandling()
.authenticationEntryPoint(this.restAuthEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "**").permitAll()
.antMatchers(FORM_BASED_REGISTRATION_ENTRY_POINT).permitAll()
.antMatchers(FORM_BASED_LOGIN_ENTRY_POINT).permitAll()
.and()
.authorizeRequests()
.antMatchers(TOKEN_BASED_AUTH_ENTRY_POINT).authenticated()
.antMatchers("/api/route/to/protect").hasAuthority("PRIVILIGE_TO_CHECK")
.and()
.addFilterBefore(buildJWTLoginFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(buildJWTAuthFilter(), UsernamePasswordAuthenticationFilter.class);
}
  • 6