Closed fedegibut closed 2 years ago
Thanks for getting in touch, but as you probably guessed since you also created a ticket on StackOverflow, it feels like this is a question that would be better suited to Stack Overflow. Please work with the community on finding an answer to your questions.
On the other site I get no answer.
Dear rwinch, This is not a stackoverflow question. I opened the discussion on that forum but I have not received any response. The documentation does not allow you to understand how to use your framework or your framework does not work and has some bugs. If you deprecate a class you should explain how to fix the framework code. I don't know if the problem is the documentation or the code. I didn't create Spring Security. I am also surprised not to see an answer from you. If you know Spring Security you can answer my question in seconds. If you do not want to answer this question because you consider me an unbearable or unpleasant person is another matter. I can't solve this problem myself because I didn't write Spring Security myself.
It has been 3 months since I opened the discussion. Nobody knows how to log in automatically after registration, or after password change or name change. Why don't the Spring Boot developers explain how to do this? Why is there no comprehensive technical documentation?
With the old version of Spring Boot I added a very convenient login() method to the class marked with the @Controller
annotation.
It seems to me a big mistake to mark a class as deprecated and not explain what is to be used in place of it.
@Autowired
private AuthenticationManager authManager;
public void login(HttpServletRequest req, String user, String pass) {
UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken(user, pass);
Authentication auth = authManager.authenticate(authReq);
SecurityContext sc = SecurityContextHolder.getContext();
sc.setAuthentication(auth);
}
// login after registratiom:
login(
request,
user,
password
);
// with the new version of spring boot and spring security everything is an unknown... :(
Thanks for getting in touch, but as you probably guessed since you also created a ticket on StackOverflow, it feels like this is a question that would be better suited to Stack Overflow. Please work with the community on finding an answer to your questions.
@rwinch It has been 3 months since I opened the discussion!
Don't you think there is some problem with the new version or something important is missing from the documentation?
You dismissed my call for help right away.
My IDE reports two errors in the following class: 1.WebSecurityConfigurerAdapter is a deprecated class; 2.Could not autowire. No beans of 'DataSource' type found. Locally the code works but I would still like to update the class with the new specifications. The code "private DataSource dataSource;" by IntelliJ in red worries me a lot. How should I rewrite this class?
I updated the class by reading the following official documentation but in the page I found there are deprecated classes and methods.
https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
I think I have everything corrected but it remains to understand how to configure Spring Security so that the "remember my password" button works. I have marked the code with question marks. I use PostgreSQL as a database and I put the database connection parameters in the .properties files. Here is the new class code:
With codes 1, 2, 3 and 4 I get a compile error:
java: method does not override or implement a method from a supertype
Without the codes 1, 2, 3 and 4 I get a WebApp startup error:I believe it is some bug in the framework. I also opened a Stackoverflow thread with no success.
https://stackoverflow.com/questions/72427751/update-the-spring-security-configuration-class-with-spring-boot-2-7-0
Thanks for the support Federico