jsf - 使用 Spring Security 和 Java Server Faces 成功登录后不显示用户名
问题描述
使用 Spring Security 和 JSF 成功登录后,我在“成功”页面上看不到“用户名”属性。“成功”页面如下所示:
<h:body>
Welcome, #{users.username}
<a href='j_spring_security_logout'>logout</a>
</h:body>
使用用户名“John”登录后,我希望看到“Welcome, John”,但文本是“Welcome, #{users.username}”。
登录表格为:
<h:form id="loginForm" prependId="false">
<!-- Messages must be global here, to show bad credentials -->
<h:messages globalOnly="true"/>
<!-- Id's must not be changed to support spring security check -->
<h:panelGrid columns="3">
<h:outputLabel for="j_username" value="User: * " />
<h:inputText id="j_username" required="true" label="username" value="#{users.username}" />
<h:message for="j_username" style="color:red"/>
<h:outputLabel for="j_password" value="Password: * " />
<h:inputSecret id="j_password" label="password" required="true" value="#{users.password}" />
<h:message for="j_password" style="color:red"/>
<h:outputLabel for="_spring_security_remember_me" value="Remember me: " />
<h:selectBooleanCheckbox id="_spring_security_remember_me" />
</h:panelGrid>
<h:commandButton type="submit" id="login" value="Login"
action="#{users.login}" />
</h:form>
我使用 JSF 2.2,bean 类是这样的:
@ManagedBean
@Component
@SessionScoped
public class Users implements Serializable {
private int id;
private String username;
private String password;
private int enabled;
@Autowired
private LoginService loginService;
// getters and setters
public String login() throws ServletException, IOException {
return loginService.doLogin();
}
解决方案
推荐阅读
- dictionary - 为什么我的标记未显示在 Google 地图活动中
- node.js - 如何在 Windows 上锁定 NodeJS 中的文件,因为 ft-ext 在 Windows 上不起作用
- sql - 没有与 SQL 'WHERE' 子句一起使用的运算符?
- pagination - 如何在 GraphQL 中强制分页
- excel - phpspreadsheet setFormatCode 性能问题
- python - 如何定义文件 .exe 读取的多个参数?
- hyperledger-fabric - 隐式策略评估失败 - 满足 1 个子策略,但此策略需要满足 2 个“背书”子策略
- python - 无法在 http://localhost:5000 访问 Dockerized Flask 应用程序
- c++ - `std::async` 用于 C++ 中的异步回复
- vhdl - 为什么这个 vhdl 代码会陷入无限循环?