private final static String DOMAIN_ATTRIBUTE_NAME = "Domain";
public static void rememberSerialized() {
HttpContext context = Request.getCurrent().getHttpContext();
if (context instanceof ServletWebBridge) {
ServletWebBridge bridge = (ServletWebBridge) context;
// base 64 encode it and store as a cookie:
DefaultSerializer<PrincipalCollection> serializer = new DefaultSerializer<PrincipalCollection>();
byte[] serialized = serializer.serialize(SecurityUtils.getSubject().getPrincipals());
serialized = encrypt(serialized);
String base64 = Base64.encodeToString(serialized);
String name = DEFAULT_REMEMBER_ME_COOKIE_NAME;
String value = base64;
String domain = context.getServerName();
String path = context.getContextPath();
int maxAge = ONE_YEAR; // always zero for deletion
final String headerValue = buildHeaderValue(name, value, domain.trim(), path.trim(), maxAge);
bridge.getResponse().setHeader(COOKIE_HEADER_NAME, headerValue);
}
}