Programming [fleXive] in Seam

You can use all the [fleXive] JSF and EJB components just like in a stand-alone application. There are, however, some issues where extra thought is required for seamless integration between both frameworks.

To use [fleXive] security features, you need to combine the Seam and [fleXive] logins. This also means that any user that should have more than guest user rights must have a valid [fleXive] account.

For example, this code requires a valid [fleXive] account for the authentication to succeed. You could also ignore the exception, which will leave guest user rights if your own authentication succeeds. In a default Seam application, Authenticator#authenticate might look like this:

public boolean authenticate() {
    log.info("authenticating #0", identity.getUsername());
    //write your authentication logic here,
    //return true if the authentication was
    //successful, false otherwise
    try {
       FxContext.get().login(identity.getUsername(), identity.getPassword(), true);
    } catch (LoginException e) {
        facesMessages.add("Failed to perform [fleXive] login: " + e.getMessage());
        return false;
    }
    return true;
}

To ensure that the user is logged out from [fleXive], you need to extend Seam's Identity component. For example:

@Name("org.jboss.seam.security.identity")
@Scope(ScopeType.SESSION)
@Install(precedence = Install.APPLICATION)
@BypassInterceptors
@Startup
public class FlexiveIdentity extends RuleBasedIdentity {
    @In
    FacesMessages facesMessages;

    @Override
    public void logout() {
        super.logout();
        try {
            FxContext.get().logout();
        } catch (FxLogoutFailedException e) {
            facesMessages.add("Failed to perform [fleXive] logout: " + e.getMessage());
        }
    }
}