我选择利用海姆证书进行认证的项目,但现在一些要求(按惯例)有所改变,需要自动认证用户。 See example bellow:
用户打电话:。 该页必须打上海平面部分,并用参数填充全权证书。 用户名称,但不按预期使用。
页: 1
<page view-id="*" action="#{authenticator.authenticate}" >
<rewrite pattern="/index/{cpf}" />
<rewrite pattern="/home/{cpf}" />
<param name="#{credentials.username}" value="123456" />
<param name="authenticator.teste" value="#{param[ cpf ]}" />
<param name="cpf" value="#{param[ cpf ]}" />
<param name="token" value="#{param[ cpf ]}" />
<navigation >
<rule if-outcome="home">
<redirect view-id="/home.xhtml" />
</rule>
<rule if-outcome="index">
<redirect view-id="#{authenticator.authenticate}" include-page-params="true" />
</rule>
</navigation>
</page>
我的核证人 Bean(这里有许多试验,即尝试一切):
@Stateless
@Name("authenticator")
public class AuthenticatorBean implements Authenticator {
@Out String token;
@Out String cpf;
@Out String xyz;
@Out String teste;
@Logger private Log log;
@In EntityManager entityManager;
@In Identity identity;
@In Credentials credentials;
public boolean authenticate() {
System.out.println(credentials.getUsername());
System.out.println(cpf);
System.out.println(xyz);
System.out.println(teste);
@SuppressWarnings("unused")
FacesContext fcx = FacesContext.getCurrentInstance();
String cpf = fcx.getExternalContext().getRequestContextPath();
String cpf2 = fcx.getExternalContext().getRequestParameterMap().get("token");
String cpf21 = fcx.getExternalContext().getRequestParameterMap().get("cpf");
String cpf22 = fcx.getExternalContext().getRequestParameterMap().get("xyz");
String cpf23 = fcx.getExternalContext().getRequestParameterMap().get("teste");
String cpf3 = fcx.getExternalContext().getInitParameter("cpf");
String cpf4 = fcx.getExternalContext().getRequestPathInfo();
String cpf5 = fcx.getExternalContext().getRequestServletPath();
Object cpf6 = fcx.getExternalContext().getRequest();
Object cpf7 = fcx.getExternalContext().getContext();
Object cpf8 = fcx.getExternalContext().getRequestMap();
Object cpf9 = fcx.getExternalContext().getRequestParameterNames();
log.info("authenticating {0}", credentials.getUsername());
Usuario usuario = (Usuario) entityManager.createQuery("select u from Usuario u where u.cpf = :cpf")
.setParameter("cpf", credentials.getUsername())
.getSingleResult();
log.info("authenticating {0}", credentials.getUsername());
if (usuario != null) {
identity.addRole("admin");
return Boolean.TRUE;
}
return false;
}
}
谁能帮助我? i 可在认证人中获取参数 Bean
感谢!