在我的托管 bean 中,我希望获取j_security_check
LDAP 服务器的用户名作为 bean 属性。
本质上,我想从中提取用户名
<input type="text" name="j_username" />
一旦提交并全部验证并在以下情况下使用它:
@Override
public String getName() {
return getId();
}
我将如何使用
FacesContext.getExternalContext().getUserPrincipal();
获取用户名作为 bean 属性?
如果您需要知道在做什么,这是完整的支持 bean。我曾经手动让用户在文本框中输入用户名,我现在想停止它并让它自动提取用户名。
//@Named("user")
@SessionScoped
public class UserBean implements Serializable, Principal {
private static final long serialVersionUID = 1L;
@NotNull(message = "The username can not be blank")
@Size(min = 6, max = 12, message = "Please enter a valid username (6-12 characters)")
//@Pattern(regexp = "[a-zA-Z0-9_]", message = "Please enter a valid username consiting of only characters that are from the alphabet or are numeric ")
//@Pattern(regexp = "(a-z)(A-Z)(0-9))", message = "Please enter a valid username consiting of only characters that are from the alphabet or are numeric ")
private String id;
public String getId() {
return id;
}
public void setId(String newValue) {
id = newValue;
}
private String fileText;
@NotNull(message = "You must select a file to upload")
public String getFileText() {
return fileText;
}
public void setFileText(String fileText) {
this.fileText = fileText;
}
/**
* public void getName(HttpServletRequest req, HttpServletResponse res)
* throws ServletException, java.io.IOException { id = req.getRemoteUser();
* }
*/
@Override
public String getName() {
return getId();
}
/*
* @Override
*
* public String request.remoteUser() { return getId();
*
* }
* .
*/
}