【发布时间】:2015-01-15 06:31:09
【问题描述】:
使用 Spring Boot、spring security starter 和 thymeleaf,我在登录后无法访问 #authentication 实用程序(更准确地说,它是 null)。我没有做任何特殊的配置(假设初学者会为我做这些)并且我没有在我的模板中包含 sec: 命名空间(再次,假设我不需要它 - 我到目前为止看到的所有示例都没有'也不需要它)。
我想打电话给:{#authentication.expression('isAuthenticated()')}
作为参考,这里是认证后被调用的控制器:
import java.security.Principal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/site-admin")
public class VZSiteAdminController {
@RequestMapping(method=RequestMethod.GET)
public String mainScreen(Principal principal){
return "site-admin";
}
}
【问题讨论】:
-
如果你只有启动器,你仍然需要添加对
thymeleaf-extras-springsecurity3jar 的依赖。其中包含注册与 thymeleaf 的安全集成的类。 -
是不是...仍然没有成功。我必须将其添加到我的模板中吗?
-
您确定您的日志记录工作正常吗?表达式不应该类似于
${#authentication},请注意$。
标签: java spring-security spring-boot thymeleaf