Created
January 5, 2014 18:24
-
-
Save Tembrel/8271929 to your computer and use it in GitHub Desktop.
Serves Freemarker template representation of login form.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import javax.inject.Inject; | |
import org.restlet.data.Form; | |
import org.restlet.data.MediaType; | |
import org.restlet.ext.crypto.CookieAuthenticator; | |
import org.restlet.representation.Representation; | |
import org.restlet.resource.Get; | |
/** | |
* Form resource for supplying credentials. | |
*/ | |
public class LoginFormServerResource extends ServerResource { | |
static final String INITIAL_USER_VALUE = "initialUserValue"; | |
private static final String AUTH_APP_PATH = "/auth"; | |
private static final String TEMPLATE = "auth/LoginForm.ftl"; | |
@Inject private CookieAuthenticator auth; | |
@Get public Representation showForm() { | |
Form query = getQuery(); | |
String redirectQueryName = auth.getRedirectQueryName(); | |
String redirectQueryValue = query.getFirstValue(redirectQueryName); | |
String loginPath = AUTH_APP_PATH + auth.getLoginPath(); | |
String initialUserValue = query.getFirstValue(INITIAL_USER_VALUE, ""); | |
Map<String, String> dataModel = new HashMap<String, String>(); | |
dataModel.put("redirectQueryName", redirectQueryName); | |
dataModel.put("redirectQueryValue", redirectQueryValue); | |
dataModel.put("loginPath", loginPath); | |
dataModel.put("identifierFormName", auth.getIdentifierFormName()); | |
dataModel.put("secretFormName", auth.getSecretFormName()); | |
if (!"".equals(initialUserValue)) { | |
dataModel.put(INITIAL_USER_VALUE, initialUserValue); | |
} | |
return newTemplateRepresentation(TEMPLATE, dataModel, MediaType.TEXT_HTML); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment