sec: authorize i sec: adnotacje uwierzytelniania nie działają

Mam projekt Spring + Thymeleaf z następującym kodem widoku.

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring3-3.dtd">
<html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org"
        xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
    <title>Contacts</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="content">
    <h1>Welcome to the site!</h1>
    <p th:if="${loginError}">Wrong user or password</p>
    <form th:action="@{/j_spring_security_check}" method="post">
        <label for="j_username">Email address</label>:
        <input type="text" id="j_username" name="j_username"/> <br/>
        <label for="j_password">Password</label>:
        <input type="password" id="j_password" name="j_password"/> <br/>
        <input type="submit" value="Log in"/>
    </form>
</div>

<div sec:authorize="isAuthenticated()">
    User: <span sec:authentication="name">miquel</span>
</div>
</body>
</html>

Atrybuty sec: authorize i sec: authentication nie działają zgodnie z oczekiwaniami - div jest zawsze wyświetlany, nawet jeśli żaden użytkownik nie jest zalogowany, a zakres zawsze brzmi „miquel”.

Podąża za odpowiednim fragmentem z mojej klasy kontrolera.

@RequestMapping(value = "/welcome.html") 
public String wellcome() { 
    Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
    System.out.println("username: " + auth.getName()); 

    return "home"; 
}

Instrukcja println działa zgodnie z oczekiwaniami - jeśli żaden użytkownik nie jest zalogowany, wypisuje „anonymousUser”, w przeciwnym razie nazwa użytkownika.

Co ja robię źle?

questionAnswers(4)

yourAnswerToTheQuestion