Welcome. Ask away! Unless otherwise specified we assume you're using the latest 6.x version of Spring Security
org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices
protected String[] decodeCookie(String cookieValue) throws InvalidCookieException {
for (int j = 0; j < cookieValue.length() % 4; j++) {
cookieValue = cookieValue + "=";
}
//here
try {
Base64.getDecoder().decode(cookieValue.getBytes());
}
catch (IllegalArgumentException e) {
throw new InvalidCookieException(
"Cookie token was not Base64 encoded; value was '" + cookieValue
+ "'");
}
//here
String cookieAsPlainText = new String(Base64.getDecoder().decode(cookieValue.getBytes()));
AuthorizedClientServiceOAuth2AuthorizedClientManager
is what I'm looking for
Will copy question from spring-boot room here
Hello, after updating spring boot 2.1.4
to 2.2.0
I encountered a problem on starting application Caused by: java.lang.IllegalStateException: Can't configure antMatchers after anyRequest
nothing changed in code except spring boot version and configuration file where that IllegalStateException
pointing on looks like that
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/something/**")
.csrf().disable()
.authorizeRequests().anyRequest().hasRole(ROLE)
.antMatchers(PUT, "/api/**").hasRole(ROLE)
.and().httpBasic();
}
As I understand spring-security was updated to version 5.2
in boot 2.2.0
, maybe I missed something there ?
Also maybe that related to that this project have several security configuration files with @Order
annotation ?
Is it expected that @EnableGlobalMethodSecurity
cannot be used at the same time as @EnableReactiveMethodSecurity
within the same application? They both declare a bean named methodSecurityInterceptor
, so spring boot startup fails with:
The bean 'methodSecurityInterceptor', defined in class path resource [org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class] and overriding is disabled.
I know that the former pulls the SecurityContext
from SecurityContextHolder
and the latter pulls it from ReactiveSecurityContextHolder
. However, if I have code that manages propagation of the SecurityContext
between SecurityContextHolder
and ReactiveSecurityContextHolder
, it seems like I should be able to use both @EnableGlobalMethodSecurity
and @EnableReactiveMethodSecurity
SecurityContext
from ReactiveSecurityContextHolder
to SecurityContextHolder
. Ideally, this would allow @PreAuthorize to continue to work in the old code
Hello.
Going deeper understanding features in Spring Security. Here mentioned that UserDetailsService
will be used if
the AuthenticationManagerBuilder has not been populated.
What is meant by populated
?
Does it mean create a bean of that type ?
Injecting the AuthenticationManagerBuilder
does it mean populating it ?
2019-11-07 09:37:11.896 ERROR 6933 --- [ XNIO-1 task-63] o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: SerializationFailedException, Failed to deserialize payload; nested exception is java.io.InvalidClassException: org.springframework.security.core.authority.SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 400, local class serialVersionUID = 510
org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload; nested exception is java.io.InvalidClassException: org.springframework.security.core.authority.SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 400, local class serialVersionUID = 510
public class AuthenticationFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
}
access forbidden code 403
.@org.springframework.context.annotation.Configuration
@EnableWebSecurity
public class Configuration extends WebSecurityConfigurerAdapter {
@Override
public void configure (AuthenticationManagerBuilder auth) throws Exception {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
auth.inMemoryAuthentication()
.withUser("Ian").roles("user").password(encoder.encode("password"))
.and()
.withUser("Charlize").password(encoder.encode("password")).roles("admin","user");
}
@Override
public void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/dir","/dir/*").access("hasRole('user')")
.antMatchers("/","/*").permitAll()
.and().formLogin().loginPage("/login/form").permitAll()
.loginProcessingUrl("/login")
.usernameParameter("userParam")
.passwordParameter("passParam");
}
}
<form method="post" action="/login" >
Username:<br>
<input type="text" name="userParam" id="userParam" value="Mickey">
<br>
Password:<br>
<input type="password" name="passParam" id="passParam" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
// Spaces show where the old code use to be separated.
return http
.csrf()
.disable()
.addFilterBefore(new AuthenticationWebFilter(), SecurityWebFiltersOrder.HTTP_BASIC)
.authorizeExchange()
.pathMatchers("/v1/**")
.authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(authenticationExceptionHandler)
.accessDeniedHandler(customAccessDeniedHandler)
// This used to be part of configure() in SecurityConfiguration()
.and()
.authenticationManager(customAuthenticationProvider)
.cors()
.and()
.build();
}