1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.webapp;
21
22 import org.apache.myfaces.tobago.internal.util.RandomUtils;
23 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
24
25 import javax.enterprise.context.SessionScoped;
26 import javax.inject.Named;
27 import java.io.IOException;
28 import java.io.Serializable;
29
30 @Named
31 @SessionScoped
32 public class Secret implements Serializable {
33
34 private static final long serialVersionUID = 1L;
35
36 public static final String KEY = Secret.class.getName();
37
38 private final String secret;
39
40 public Secret() {
41 secret = RandomUtils.nextString();
42 }
43
44 public boolean check(final String test) {
45 return secret.equals(test);
46 }
47
48 public void encode(TobagoResponseWriter writer) throws IOException {
49 writer.writeAttribute(HtmlAttributes.VALUE, this.secret, false);
50 }
51 }