Java – in identity The @ picketlink annotation class is not used in login()
•
Java
I'm trying to use the @ picketlinked class that extends baseauthenticator
My setting is about wildlife 9.0 2. Final ear project
I'm in my JBoss deployment structure Use it in XML
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
<module name="org.picketlink.core.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.core" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.common" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.schema" Meta-inf="import" annotations="true"/>
</dependencies>
</deployment>
<sub-deployment name="prestiz-web.war">
<dependencies>
<!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
<module name="org.picketlink.core.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.core" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.common" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.schema" Meta-inf="import" annotations="true"/>
</dependencies>
</sub-deployment>
<sub-deployment name="prestiz-ejb.jar">
<dependencies>
<!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
<module name="org.picketlink.core.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.core" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.api" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.common" Meta-inf="import" annotations="true"/>
<module name="org.picketlink.idm.schema" Meta-inf="import" annotations="true"/>
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
My baseauthenticator class is in my EJB Jar is declared as the following
@RequestScoped @PicketLink public class PicketlinkAuthenticator extends BaseAuthenticator
My logincontroller configuration is as follows:
@Path("/login")
public class LoginController {
@Inject
private Identity identity;
@Inject
private DefaultLoginCredentials credentials;
@GET
@Path("/dologin/{username}/{password}")
@Produces(MediaType.TEXT_PLAIN)
@Transactional(TxType.required)
public String doLogin(@PathParam("username") String username,@PathParam("password") String password){
credentials.setUserId(username);
credentials.setPassword(password);
AuthenticationResult authResult=identity.login();
if(authResult.equals(AuthenticationResult.SUCCESS)){
return "success";
}else{
return "Failed";
}
}
After calling identity After login (), I saw this in the log:
11:49:09,630 INFO [org.picketlink.idm] (default task-2) PLIDM001000: Bootstrapping PicketLink IDM Partition Manager 11:49:09,667 INFO [org.picketlink.idm.identity.store] (default task-2) PLIDM001001: Initializing Identity Store [class org.picketlink.idm.file.internal.FileIdentityStore] 11:49:09,679 WARN [org.picketlink.idm.identity.store.file] (default task-2) PLIDM001101: Working directory [C:\Users\bgadeyne\AppData\Local\Temp\pl-idm] is marked to be always created. All your existing data will be lost. 11:49:09,688 INFO [org.picketlink.idm.identity.store.file] (default task-2) PLIDM001100: Using working directory [C:\Users\bgadeyne\AppData\Local\Temp\pl-idm].
The authentication method of my authenticator also has some log records, but it is not displayed
What did I miss here?
Solution
The solution is that you need authenticator selector to select your authenticator This allows you to have multiple authenticators:
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import lombok.Setter;
import org.picketlink.annotations.PicketLink;
import org.picketlink.authentication.Authenticator;
import org.picketlink.authentication.internal.IdmAuthenticator;
@RequestScoped
@Named
public class AuthenticatorSelector {
@Inject private Instance<SingleSignOnAuthenticator> ssoAuthenticator;
@Inject private Instance<IdmAuthenticator> idmAuthenticator;
@Inject private Instance<TokenAuthenticator> tokenAuthenticator;
@Setter private boolean singleSignOn = false;
@Setter private boolean tokenAuth = false;
public boolean getSingleSignOn() {return singleSignOn;}
@Produces
@PicketLink
public Authenticator selectAuthenticator() {
if (singleSignOn) {
return ssoAuthenticator.get();
} else if (tokenAuth) {
return tokenAuthenticator.get();
} else {
return idmAuthenticator.get();
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
