Java Community | Help. Code. Learn.

JCH

Java Community | Help. Code. Learn.

With more than 20,000 members, join one of the biggest and most active Java Communities on Discord! ☕

Join

java-help

❓︱qotw-answers

java

help with implementing a menu

Trying to implement CSRF protection with Spring Security and React frontend

I'm trying to get CSRF protection to work using spring security but I keep getting a 403 forbidden error when trying to make a post request to a csrf protected endpoint using postman. I followed the docs to the letter - this one to be specific with the only change being I replaced this line .addFilterAfter(new CsrfCookieFilter(), BasicAuthenticationFilter.class); with .addFilterAfter(new CsrfCookieFilter(), customUsernamePasswordAuthFilter.getClass()) as I have implemented a custom UsernamePasswordAuthenticationFilter to work with my frontend SPA built using react. On postman, there are two cookies present - SESSION and XSRF-TOKEN and I also include a X-XSRF-TOKEN header while making the post request and still get a forbidden error. I'm not currently sending any requests from the SPA directly. Just using postman for now....

Need help setting up CSRF on spring backend with a react frontend

I was just going through the spring docs to setup csrf protection with a SPA (react) frontend and found this code here that they suggested I use, ```java @Configuration @EnableWebSecurity...

how to use login credentials for spring app in postman?

hey guys. can smb help me out? i cant use login and password auth in postman for my spring app. i have this websecurityconfig: ```java @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {...

JWT return Dto. Login and Register REST Endpoints

```java @PostMapping("/register") public AuthenticationResponseDto register(@RequestBody Command command) { return authenticationService.register(command); }...

Spring MVC

I am Trying To Upload image and save it but i got error Code : ```@PostMapping("/registration") public String registration( @Valid @ModelAttribute("finderUserPojo") MovieFinderUserPojo finderUserPojo , BindingResult bindingResult , HttpSession httpSession , @RequestParam("image") MultipartFile image , Model model) { ...

DionysisT

Hi guys i am implementing a website with bcakend as rest-api with spriongboot and i have made the auth as session but i want the static files to served by apache but before send them to client to use the auth from springboot on tomcat how could i done it?

Apache Mina SSHD server

hi guys.. I built a SSH server using Apache Mina and StackOverflow. Now, I ran into the problem, that I am unable to get the String which was input as username or password... This is annoying and the documentation is pure shit. If anyone can tell me what I need to read the client input properly, please help me. CNCServer: https://pastebin.com/Ab1mkdEM Commands: https://pastebin.com/C0yzEvsG PasswordAuth: ```public class CNCPasswordAuthenticator implements PasswordAuthenticator{ ...
No description

Will Pay for Help

The highlighted part is the problem but idk how to stop it from happening ```import java.util.Scanner; import java.util.Random; ...
No description

where do config values come from?

usually in configs you have smth like this: . where you specify from where the value comes from. in this screenshot it comes from application.yaml file. but idk where it comes from in my BankAccountConfig?: ```java @Component...
No description

what the hell is model and why controller returns random string?

hey guys. can smb explain what the hell model is? bc i tried googling and its just vaguely said that model is your data. yes, i know its from MVC pattern, but it still doesnt make any sense, can smb explain what the f is going on here: ```java @GetMapping("/importBgwEod") public String importBgwEod(Model model) throws JAXBException, IOException { importService.importBgwEod(getUserId());...

Spring MVC checking user password

I am Trying to check the user is already registered or not as well as the password is correct or not but i am getting error as i mentioned down here is the both controller -> ```@GetMapping("/login") public String loginPage(Model model) { model.addAttribute("movieFinderLoginUserPojo", new MovieFinderLoginUserPojo());...

how to store XML if i want to change its values in my service?

hey guys. in my service want to use XML. in the service Id change needed values of my XML tags. how can i do that? i was thinking about storing the XMLsomewhere, and then 'importing'/using it in my service methods. how can i do that? thanks

Spring MVC Static files

i dont know why but my browser is not adding the css file to my jsp file.. I dont Know How to resolve the issue can anyone help ?
No description

using String to represent date

hey guys. i want to have a method that accepts fromDate and toDate args. and then later in this method i will concat the args to the string:
"<FrDt>"+fromDate+"</FrDt>\n" +
"<ToDt>"+toDate+"</ToDt>\n"
"<FrDt>"+fromDate+"</FrDt>\n" +
"<ToDt>"+toDate+"</ToDt>\n"
...

Richardson Mapping With Spring Security

Hi, Im curious about, how to properly create mappings for security endpoints. I have now a UserController. So where would you like to put mappings like "login, register and verify email", to UserController or AuthController. And how would you like to create endpoints. ...

Apache Mina weird session behaviour

Hello there, I am building a CNC / Telnet server using Apache Mina and ran into some issues from the very beginng... First, I will be showing my Classes which are in the relation of the CNC... CNCServerHandler: https://pastebin.com/A5ea3AgF (Class with the username Input) CNCServer: https://pastebin.com/HEJedJ1F CNCClient: https://pastebin.com/qk2Au8Bf...
No description

Session not being created after explicitly authenticating user in spring security

I'm currently trying to implement a session based authentication using spring security and have managed to get the registration and email verification functionality working. I want the user to be authenticated after verifying their email and then be redirected to the onboarding page and then to dashboard on completion of onboarding. I have logged the authentication to console to debug and when there isn't any user then I get a console log with the authentication object containing anonymousUser and also a sessionId. But, when I explicitly try to authenticate the user, the authentication object contains all the info about the user such as principal, etc but not sessionId. any help, please? ...

Autocomplete not working

Java extension autocomplete doesn´t work VS-code