Having this in my web.xml:
<security-constraint>
        <display-name>Amministrazione</display-name>
        <web-resource-collection>
            <web-resource-name>wrcollAdmin</web-resource-name>
            <description/>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.htm</form-login-page>
            <form-error-page>/login.htm</form-error-page>
        </form-login-config>
    </login-config>
allows me to protect a secure area of my webapp.
So I get redirected to /login.htm trying to access /admin/page.htm , for example.
Then I have a JSF2 form with the input fields for username and password. The login button triggers a "login()" method in a controller, like:
public void login() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext externalContext = context.getExternalContext();
    // HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    logged = false;
    // request.login(username, password);
    if ( users.get(username)!= null && users.get(username).equals(password) ) {
        logged = true;
        externalContext.redirect("/admin/");
    } else {
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Failed","Error"));
     }
}
Now this is obviously not working, because I don't know how to tell the Java EE: "Hey! I tell you this user is valid! Just... log him in!"
I suppose the API just supports request.login() but I don't wanna use MemoryRealm, JDBCRealm and so on... I determine other ways the user validity!
If there's not a way to programmatically log in a user, what is the best workaround? Maybe creating a realm with a single username+password couple and using always them for request.login()?
 
    