Skip to content
Advertisement

Tag: spring-security

spring security hasAuthority(“SCOPE_xxx”) method not working with spring authorization server version 0.2.0

I have created an authorization server using the new spring authorization server module. I am able to get the token successfully but when I try to use the token against a protected endpoint with hasAuthority() I get forbidden 403 error. Below my pom.xml file Below is my Authorization Server config And this is my Security Config Here is my user

How do I get a JwtAuthenticationToken for my HandlerMethodArgumentResolver from the request’s Authorization header?

I have a Spring Boot application that requires a JwtAuthenticationToken passed in a HTTP Authorization header. The header itself provides a bearer token; Spring is doing some magic that I am currently unaware of to convert that bearer token string into a JwtAuthenticationToken. I have some code that extracts the user id from the token, which is used to locate

Spring Security injecting null @AuthenticatedPrincipal into controllers

Java 11, Spring Security here. I have the following endpoint/method in my @RestController: When I set a breakpoint inside this method and login to my app, token is null (meaning it was not properly injected as an @AuthenticatedPrincipal) however SecurityContextHolder.getContext().getAuthentication() returns an Authentication instance that looks totally fine. I get a NPE when the token.getCredentials() gets called at the bottom

How to design two seperate authorization/authentication configurations in spring boot?

I want to implement authentication and authorization for spring boot application with this design: First group of endpoints (“/api/**) will have authorization by passing the api-secret-key through requests headers. Authentication should be permitted for all. Second group (/admin/**) will have authentication by hitting the /login endpoint passing username and password where I will have custom UserDetailService. If the authentication is

Using ant patterns to match on path variable

I have several different controllers, configured with endpoints like below. Where {id} is a numeric @PathVariable. Using HttpSecurity, I want to implement security around all endpoints that have {id} in them. So I created an ant pattern like this: The ant pattern is correctly matching on the endpoints with {id} in them. However, the ant pattern is also matching on

Spring Security Expression: “authenticated” vs. “isAuthenticated()”

According to the Spring Security docs, the expression to check whether a user is authenticated is isAuthenticated(). So we would do @PreAuthorize(“isAuthenticated()”), for example. However, according to the official example and confirmed by my own testing, @PreAuthorize(“authenticated”) also works. Is it a Spring Security feature or perhaps simply a Java feature (e.g. authenticated is the field that backs the getter

endpoint for authentication with spring security

I wanna create custom endpoint for login. It works fine when password and username are correct but returns 200 and login form instead 401 for incorrect data. public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private final UserDetailsService userDetailsService; } Answer Try something like that: Don’t forget to Autowire AuthenticationManager and other services!

Advertisement