package net.trajano.openidconnect.sample;

import java.io.IOException;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.trajano.openidconnect.provider.spi.AuthenticationResponseProvider;
import net.trajano.openidconnect.provider.spi.Authenticator;

// TODO get rid of this use the same strat as /logout
@WebServlet(urlPatterns = "/doLogin")
@Stateless
public class LoginServlet extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = -129656605271663835L;

    @EJB
    Authenticator authenticator;

    @Override
    protected void doPost(HttpServletRequest req,
            HttpServletResponse resp) throws ServletException,
            IOException {

        String subject = req.getParameter("username");
        req.getSession()
                .setAttribute("sub", subject);

        redirector.doCallback(req, resp, subject);
    }

    @EJB
    private AuthenticationResponseProvider redirector;

}

@@ -469,16 +469,66 @@
 ticator;
+%0Aimport net.trajano.openidconnect.crypto.Encoding;
 %0A%0A// TOD
@@ -991,16 +991,41 @@
 bject = 
+Encoding.base64urlEncode(
 req.getP
@@ -1044,16 +1044,17 @@
 ername%22)
+)
 ;%0A      

Encoded user name as subject