1 package net.trajano.twiff.internal.token.entity;
2
3 import java.io.Serializable;
4 import java.net.URL;
5
6 /***
7 * This is an entity that stores the session token data.
8 *
9 * @author Archimedes Trajano
10 */
11 public class SessionToken implements Serializable {
12 /***
13 * Unique id.
14 */
15 private long id;
16
17 /***
18 * Page bean.
19 */
20 private Serializable pageBean;
21
22 /***
23 * Redirect URL.
24 */
25 private URL redirectUrl;
26
27 /***
28 * Number of times the page bean data was requested. This does not increment
29 * if the redirect URL is read though.
30 */
31 private short requestCount = 0;
32
33 /***
34 * The session ID.
35 */
36 private String sessionId;
37
38 /***
39 * This is Token ID which is a {@link java.security.SecureRandom} number
40 * encoded as hexadecimal string. This combined with the {@link #sessionId}
41 * to form the lookup on this table.
42 */
43 private String tokenId;
44
45 /***
46 * Version for optimistic locking.
47 */
48 private int version;
49
50 /***
51 * @return the unique id.
52 */
53 public final long getId() {
54 return id;
55 }
56
57 /***
58 * This returns the page bean data as a serializable object. It also
59 * increments the request counter.
60 *
61 * @return the pageBean.
62 */
63 public final Serializable getPageBean() {
64 ++requestCount;
65 return pageBean;
66 }
67
68 /***
69 * @return Returns the redirectUrl.
70 */
71 public final URL getRedirectUrl() {
72 return redirectUrl;
73 }
74
75 /***
76 * @return Returns the sessionId.
77 */
78 public final String getSessionId() {
79 return sessionId;
80 }
81
82 /***
83 * @return Returns the tokenId.
84 */
85 public final String getTokenId() {
86 return tokenId;
87 }
88
89 /***
90 * @return Returns the valid.
91 */
92 public final boolean isValid() {
93 return redirectUrl != null && pageBean != null;
94 }
95
96 /***
97 * @param pageBean
98 * The pageBean to set.
99 */
100 public final void setPageBean(final Serializable pageBean) {
101 this.pageBean = pageBean;
102 }
103
104 /***
105 * @param redirectUrl
106 * The redirectUrl to set.
107 */
108 public final void setRedirectUrl(final URL redirectUrl) {
109 this.redirectUrl = redirectUrl;
110 }
111
112 /***
113 * Sets the session Id for the SessionToken.
114 *
115 * @param sessionId
116 * The sessionId to set.
117 */
118 public final void setSessionId(final String sessionId) {
119 this.sessionId = sessionId;
120 }
121
122 /***
123 * Sets the token Id for the SessionToken.
124 *
125 * @param tokenId
126 * The tokenId to set.
127 */
128 public final void setTokenId(final String tokenId) {
129 this.tokenId = tokenId;
130 }
131
132 /***
133 * Returns the number of times the data was requested.
134 *
135 * @return number of times the data was requested.
136 */
137 public final int getRequestCount() {
138 return requestCount;
139 }
140 }