Thymeleafで、Spring Securityのダイアレクトでユーザ名を表示したい。
Thymeleafで[sec:authentication]を使ってweb上にユーザ名を表示したいのですが、
「Hello, displayName!」と表示されてしまいます。(本来ならdisplayNameにユーザ名が入る想定)
HTMLソースを確認すると、sec:authenticationがそのまま残ってしまいます。
おそらくHTMLか、build.gradleの設定で問題があると思うのですが、、、
navi.html
<html lang="ja" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security4"> <header th:fragment="globalnavi"> <nav class="navbar navbar-expand-lg navbar-default"> <a class="navbar-brand" href="/">Spring Social Demo</a> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li sec:authorize="isAuthenticated()">Hello, <span sec:authentication="principal.user.displayName">displayName</span>! </li> </ul> <form th:action="@{/logout}" method="post" class="form-inline my-2 my-lg-0"> <div sec:authorize="isAnonymous()"> <a class="btn btn-outline-success my-2 my-sm-0" href="/signin">Sign in</a> </div> <div sec:authorize="isAuthenticated()"> <input type="submit" class="btn btn-outline-success my-2 my-sm-0" value="Log out"> </div> </form> </div> </nav> </header>
build.gradle
buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'idea' group = 'com.example.demo' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 targetCompatibility = 1.8 jar { baseName = 'gs-accessing-twitter' version = '0.1.0' } task wrapper(type: Wrapper) { gradleVersion = '4.6' } repositories { mavenCentral() } ext['thymeleaf.version'] = '3.0.2.RELEASE' ext['thymeleaf-layout-dialect.version'] = '2.1.1' jar.baseName = 'thymeleaf' dependencies { compile("org.springframework.boot:spring-boot-starter-web") compile('org.springframework.boot:spring-boot-starter-social-twitter') compile('org.springframework.social:spring-social-core') compile('org.springframework.social:spring-social-config') compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4') compile("org.springframework.security:spring-security-core") compile("org.springframework.security:spring-security-config") compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-jdbc') compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.security:spring-security-web") compile('org.springframework.social:spring-social-security') compile('org.springframework.boot:spring-boot-starter-data-redis') compile('org.springframework.session:spring-session') compile('org.projectlombok:lombok:1.16.10') compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.apache.commons:commons-text:1.1') compile('org.webjars:bootstrap:3.3.6') compile('org.webjars:startbootstrap-sb-admin-2:3.3.7+1') compile('org.springframework.boot:spring-boot-devtools') compile('org.springframework.boot:spring-boot-starter-test') runtime('org.postgresql:postgresql') testCompile('org.springframework.boot:spring-boot-starter-test') }
試したこと
色々調べた結果、Thymeleafのバージョン等が影響しているようなので、Thymeleafのバージョンを3にしたり、2にしたり試したのですが、うまくいかず
補足情報(FW/ツールのバージョンなど)
言語:java1.8
FW:SpringBoot
Thymeleaf
ツール:eclipse
ご教授お願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/06 12:51
2018/08/06 13:26