You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a Micronaut newbie trying to understand the framework. I want to implement mtls, couldn't find existing security mechanisms which can do that, so wrote a simple filter to check for client certificate.
@Filter("/hello/**")
public class MTLSFilter implements HttpServerFilter {
private static final Logger LOG = LoggerFactory.getLogger(MTLSFilter.class);
private final AuthService authService;
public MTLSFilter(AuthService authService) {
this.authService = authService;
}
@Override
public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
LOG.info("inside doFilter of MTLSFilter");
return authService.authenticate(request)
.switchMap(aBoolean -> chain.proceed(request));
}
}
Corresponding code from AuthService
Flowable<Boolean> authenticate(HttpRequest<?> httpRequest){
return Flowable.fromCallable(() -> {
LOG.info("inside AuthService");
Certificate cert = httpRequest.getCertificate().isPresent() ?
httpRequest.getCertificate().get() : null;
if (cert == null) {
LOG.error("no certificate found in the request");
return false;
}
LOG.info("setting {} as principal in request", ((X509Certificate)cert).getSubjectX500Principal().getName());
httpRequest.setAttribute("micronaut-demo.principal", ((X509Certificate)cert).getSubjectX500Principal().getName());
return true;
});
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am a Micronaut newbie trying to understand the framework. I want to implement mtls, couldn't find existing security mechanisms which can do that, so wrote a simple filter to check for client certificate.
Corresponding code from AuthService
And I am making a request using curl
But I dont see certificate in the request, and code always end with cert == null condition.
micronautVersion=2.4.1
micronaut-cli.yml
What am I missing here?
TIA.
Beta Was this translation helpful? Give feedback.
All reactions