Skip to content

Instantly share code, notes, and snippets.

@Tembrel
Created January 5, 2014 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tembrel/8271929 to your computer and use it in GitHub Desktop.
Save Tembrel/8271929 to your computer and use it in GitHub Desktop.
Serves Freemarker template representation of login form.
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