3 Commits

Author SHA1 Message Date
semantic-release-bot
a1cff78f0c chore(release): 1.2.0 [skip ci]
# [1.2.0](https://git.tools.ldpt.fr/lucasdpt/spring-keycloak-starter/compare/v1.1.0...1.2.0) (2025-09-26)

### Features

* refactor way to get CallerId ([94dd635](94dd6355b4))
2025-09-26 11:06:02 +00:00
lucasdpt
94dd6355b4 feat: refactor way to get CallerId
All checks were successful
Release / release (push) Successful in 1m54s
2025-09-26 13:04:30 +02:00
f2fead959d ci: update semantic-release tagFormat
All checks were successful
Release / release (push) Successful in 1m20s
2025-09-23 06:52:38 +00:00
5 changed files with 14 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
{ {
"branches": ["master"], "branches": ["master"],
"tagFormat": "${version}",
"plugins": [ "plugins": [
"@semantic-release/commit-analyzer", "@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator", "@semantic-release/release-notes-generator",

View File

@@ -1,3 +1,10 @@
# [1.2.0](https://git.tools.ldpt.fr/lucasdpt/spring-keycloak-starter/compare/v1.1.0...1.2.0) (2025-09-26)
### Features
* refactor way to get CallerId ([94dd635](https://git.tools.ldpt.fr/lucasdpt/spring-keycloak-starter/commit/94dd6355b40e69ef6863a225bbe60f9f8a780047))
# [1.1.0](https://git.tools.ldpt.fr/lucasdpt/spring-keycloak-starter/compare/v1.0.1...v1.1.0) (2025-09-21) # [1.1.0](https://git.tools.ldpt.fr/lucasdpt/spring-keycloak-starter/compare/v1.0.1...v1.1.0) (2025-09-21)

View File

@@ -6,7 +6,7 @@
<groupId>fr.lucasdupont</groupId> <groupId>fr.lucasdupont</groupId>
<artifactId>spring-keycloak-starter</artifactId> <artifactId>spring-keycloak-starter</artifactId>
<version>1.1.0</version> <version>1.2.0</version>
<properties> <properties>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>

View File

@@ -1,28 +1,15 @@
package fr.lucasdupont.security; package fr.lucasdupont.security;
import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
public class CallerIdArgumentResolver implements HandlerMethodArgumentResolver { @Component
public class CallerIdResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return CallerId.class.isAssignableFrom(parameter.getParameterType());
}
@Override
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws IllegalAccessException {
public CallerId get() throws IllegalAccessException {
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof JwtAuthenticationToken jwtAuth)) { if (!(auth instanceof JwtAuthenticationToken jwtAuth)) {
throw new IllegalAccessException("Authentication is not of type JwtAuthenticationToken"); throw new IllegalAccessException("Authentication is not of type JwtAuthenticationToken");
@@ -44,4 +31,5 @@ public class CallerIdArgumentResolver implements HandlerMethodArgumentResolver {
return new CallerId(sub, CallerId.Type.USER); return new CallerId(sub, CallerId.Type.USER);
} }
} }
} }

View File

@@ -9,10 +9,6 @@ import org.springframework.security.config.annotation.web.configurers.AbstractHt
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@AutoConfiguration @AutoConfiguration
@ConditionalOnClass(HttpSecurity.class) @ConditionalOnClass(HttpSecurity.class)
@@ -47,19 +43,4 @@ public class KeycloakAutoConfiguration {
return new RequiredRoleFilter(props); return new RequiredRoleFilter(props);
} }
@Bean
public WebMvcConfigurer callerIdArgumentResolverConfigurer(CallerIdArgumentResolver resolver) {
return new WebMvcConfigurer() {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(resolver);
}
};
}
@Bean
public CallerIdArgumentResolver callerIdArgumentResolver() {
return new CallerIdArgumentResolver();
}
} }