I have a requirement to get the details of the current user who has been loggedIn. To get the details, we can use the SecurityContextHolder.getContext() and extract the details. According to, SecurityContextHolder, SecurityContext and Authentication Objects By default, the SecurityContextHolder uses a ThreadLocal to store these details, which means that the security context is always available to methods in the
Tag: spring
How to mock JWT authentication in a Spring Boot Unit Test?
I have added JWT Authentication using Auth0 to my Spring Boot REST API following this example. Now, as expected, my previously working Controller unit tests give a response code of401 Unauthorized rather than 200 OK as I am not passing any JWT in the tests. How can I mock the JWT/Authentication part of my REST Controller tests? Unit test class
How to create pointcut to feign client that supports interface inheritance?
In a Spring Boot project I have a simple feign client I need to intercept all calls and for this and I’m creating a common library that can be used in different projects. To achieve it I try to use Spring AOP. I created an aspect that wraps all public methods of the object annotated with MyAnnotation It works correctly
How to properly access a secured Spring Data REST Repository in a ApplicationRunner?
I followed the documentation on how to secure REST repositories with @PreAuthorize. However, the following repository needs to be accessed by an ApplicationRunner to perform some initial setup tasks after application startup. Since there’s no security context active when this runner is executed the application won’t start at all What are my options to access the REST repository properly? I’m
Calculate the percentage of value using Collection framework
I have List of TrainingRequest where each and every element has List of Feedback. I need to get all given result of Q1,Q2 and calculate percentage of each value. To flat all the feedback To calculate each value of Q1 and Q2, I’m grouping it and getting the count. I need to get the percentage of each Q1, Q2 value
Why are there so many SessionFactoryImpl objects in the dump?
I have ~15,000 identical SessionFactoryImpl objects in my dump: One of the objects with incoming references: One of the objects with outbound references: I don’t have the following parameters …
Spring Data @Query use VARCHAR instead of NVARCHAR
The code that I posted is not the code that our companies uses, it is just example code to correctly illustrate the problem. I have the following Spring Data Query: For entity Customer: and Name: This works okay, but Spring data passes these parameters as NVARCHAR instead of VARCHAR. Therefore, the DB has to perform expensive conversion that is very
Spring actuator ‘/auditevents’ endpoint returns 404
I am getting a 404 error when invoking /actuator/auditevents endpoint. Upon closer look, I see that available endpoint listing doesn’t include /auditevents endpoint. pom.xml dependencies application.properties management.endpoints.web.exposure.include=* http://localhost:8080/actuator output Spring-boot version: 2.2.6.RELEASE Not sure whether I am missing any required configuration. Answer Auditing can be enabled by providing a bean of type AuditEventRepository in your application’s configuration. Try to add
Script for IBM Rhapsody made with Java and Spring autowiring not working
I developed a script for IBM Rhapsody using it’s API for java. The script is working fine when is run from my IDE. When I run the script from Rhapsody using the JAR and HEP file I get …
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release
I’m starting a new Spring 5 project with Java 14. It compiled, but gave me a warning: Any ideas how to solve it? Answer It’s just a warning because JVM’s verifies are much faster then before. If you are really not willing to see that, you could just remove -Xverify:none and -noverify from your JVM options. In IDEA you can