#Spring Boot Security / Request = 500

93 messages · Page 1 of 1 (latest)

pseudo verge
#

Hello guys, I'm a beginner here who's trying Spring Boot security.

I'm trying to sign in with the httpSecurity but when I do my sign-in request, SPring boot redirects me to the famous ```Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Jul 20 23:12:55 CEST 2024
There was an unexpected error (type=Internal Server Error, status=500).``` issue.

The thing is in my security configuration I understand I have to modify this line :

.formLogin(form -> form

               // Redirect the user if successfull authentication
                           .defaultSuccessUrl("/",true)
                           
               )
               .logout(config-> config.logoutSuccessUrl("/"))
               // Redirect the user if log the fuck out
               .build();```

But my home URL is `http://localhost:8080/` do you know how to modify the url to at least redirect it to the homepage ( I built my environment with Maven ) ?
plain sageBOT
#

⌛ This post has been reserved for your question.

Hey @pseudo verge! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mellow olive
#

Can you show the stack trace?

pseudo verge
#

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "$(_csrf.parameterName)" (template: "index" - line 39, col 42)```

Basically an exception
#

and this is my code at line 39 in my index.html :

<form action="/logout" method="post" sec:authorize="isAuthenticated()">
                    <input type="hidden" th:name="$(_csrf.parameterName)" 
                           th:value="${_csrf.token}" />
plain sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

mellow olive
#

Can you show the full stack trace instead of a part of it?

#

Also for the security configuration, did you show the complete security configuration or is there more to it?

warped plover
plain sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

pseudo verge
mellow olive
#

yeah I saw that ;)

#

maybe I should increase my font size lol

pseudo verge
#

Do you know if there's a way to personalize the errorMessage function ?

mellow olive
#

which function exactly?

pseudo verge
#

I think I should do that too, because I wasn't even aware of the slack track, I was pretty sure I had to configure my security config and not my static file lol

mellow olive
#

it isn't a static file

#

it's a template

pseudo verge
#

Here in my Account controller :


    @PostMapping("/register")
    public String register(
        Model model, 
        @Valid @ModelAttribute RegisterDto registerDto,
        BindingResult result
        ){
            // Handling authentification errors if its equals to the Password field and Confirm password are different 
            if(!registerDto.getPassword().equals(registerDto.getConfirmPassword())){
                result.addError(
                    new FieldError("registerDto", "confirmPassword"
                    , "Password and confirm password do not match")
                );
            }

            AppUser appUser = repo.findByEmail(registerDto.getEmail());
            if(appUser != null){
                result.addError(
                    new FieldError("registerDto","email"
                    ,"Email adress is already used")
                );
            }

I call the addError but the thing is on the client side, it appears in black and I would like to change the color or the font-size and I've done research to personnalize it but can't find any

pseudo verge
mellow olive
#

You have thymeleaf which processes/transforms it before sending it to the client

mellow olive
#

You should be able to use CSS or similar things on it

pseudo verge
mellow olive
#

idk how exactly thymeleaf does it but with JSP, you are essentially generating Java code dynamically IIRC

pseudo verge
#

Yes but I mean the terminology of static files

#

let me check how I read the error in th

mellow olive
#

Essentially with Thymeleaf, you define a template and thymeleaf renders the template (idk whether it uses some intermediate representation or other internals though)

pseudo verge
#

Ok thanks for the explanation, I'm still a bit confused about the whole Spring Boot environement

plain sageBOT
pseudo verge
#
                    , "Password and confirm password do not match")
                );```
#

( sorry for the indentation ) I'm generating the message with the FieldError function

mellow olive
#

So you are still talking about the errors displayed in a way you don't want, right?

pseudo verge
#

Yes but I think I find it

#

I think instead of writing codes I don't understand, I need to learn the entire Spring Boot architecture from the Controller to the DTO

mellow olive
#

Yeah Spring has many things to it

#

I think in isolation, most are pretty understandable

#

but doing many at once are complicated

#

On the other hand, that's the big advantage - Spring provides all of these things to developers

pseudo verge
#

Yes I totally agree with you, I just find the solution to my problem but I can't really modify everything ( I've figured out how to change my error messages color, but the the style etc )
I'm still confused about the DTO and the entities to me it does the same thing

mellow olive
#

Which problem? Is it the errors being displayed in a way you don't want or is it something different?

pseudo verge
#

I mean I would to put other font style in the same attribute but this gives me an error ( it's the same thymeleaf attribute where I changed the color ) I tried to put an italic style but this rendered me an error

#
<p th:if="${#fields.hasErrors('phone')}" th:errorclass="text-red-700 " th:errors="${registerDto.phone}"></p>```
mellow olive
#

What exactly did you change and what's the exact error it resulted in?

pseudo verge
#

I've changed this class in a Tailwind class th:errorclass="text-red-700 "

mellow olive
#

I don't think tailwind knows about Thymeleaf so adding a th:something in Tailwind probably isn't useful

pseudo verge
#

and I've discovered that if you set the annotation with no message in the DTO, it render a default message in my native language ( whch is weird because I set the html tag in english

pseudo verge
#

with a Tailwind utility class

#

but I don't know if it's fully compatible between Thymeleaf and Tailwind tbh

mellow olive
#

Instead of th:errorclass="text-red-700 ", can you try class="text-red-700"?

pseudo verge
#

It doesn't render me in red anymore so I have to leave it that way

mellow olive
#

?

plain sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

pseudo verge
mellow olive
#

Which utility class?

pseudo verge
#

The text-red-700, it's a Tailwind class

mellow olive
#

Did you try with class= as well instead of just th:errorclass=?

#

Does adding a custom style= work?

pseudo verge
mellow olive
#

what error are you getting?

pseudo verge
mellow olive
mellow olive
pseudo verge
#

Let me do this tomorrow because I'm not at home rn, I will ping you with the code you want

plain sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

pseudo verge
#

@mellow olive
in this code, as I said yesterday, I tried to add another Tailwind class to modify my element

th:errorclass="text-red-700 font-semibold"

The font-semibold is the other class I wanted to add or font-italic, in both cases and based on the Tailwind documentation it should work but as you said maybe Thymeleaf is only compatible with only one class

mellow olive
#

You still didn't specify whether it works with class instead of th:errorclass

#

and also not whether non-Tailwind stuff works

pseudo verge
mellow olive
#

ah then I overlooked that

#

Does it work with non-Tailwind stuff?

pseudo verge
#

no problem, I think thymeleaf doen't allow me to have more than one utlity class

mellow olive
#

because knowing that would help finding what causes the issue

mellow olive
#

Does the ont-semibold have any effect?

#

Also can you check the HTML sent to the client in the devtools with th:errorclass="text-red-700 font-semibold"?

pseudo verge
#

it basically change your element in bold

pseudo verge
mellow olive
#

almost

#

in the inspector

pseudo verge
#

ok let me check after compile time

mellow olive
#

though the network tab should work as well

pseudo verge
#

Ok so at run time I have this exception which is directly in correlation with my tailwind classes

#

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "text-red-700 font-semibold" (template: "register" - line 56, col 70)

mellow olive
#

ok yeah then you can probably not use th:errorclass there

#

but that wouldn't explain class= not working (without a th:)

pseudo verge
#

I think it's because I'm using a thymeleaf element that has a thymeleaf object as a parent

#

but it's ok I think, it's not a big deal

plain sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.