keycloak
静的公開メンバ関数 | 静的公開変数類 | 静的変数 | 静的非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.common.util.ServerCookie クラス
org.keycloak.common.util.ServerCookie の継承関係図
Inheritance graph
org.keycloak.common.util.ServerCookie 連携図
Collaboration graph

静的公開メンバ関数

static boolean isToken (String value)
 
static boolean containsCTL (String value, int version)
 
static boolean isToken2 (String value)
 
static boolean checkName (String name)
 
static String getCookieHeaderName (int version)
 
static String formatOldCookie (Date d)
 
static void formatOldCookie (Date d, StringBuffer sb, FieldPosition fp)
 
static void appendCookieValue (StringBuffer headerBuf, int version, String name, String value, String path, String domain, String comment, int maxAge, boolean isSecure, boolean httpOnly)
 
static void maybeQuote (int version, StringBuffer buf, String value)
 
static boolean alreadyQuoted (String value)
 
static void maybeQuote2 (int version, StringBuffer buf, String value)
 

静的公開変数類

static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT")
 

静的変数

 static
 

静的非公開メンバ関数

static String escapeDoubleQuotes (String s, int beginIndex, int endIndex)
 

静的非公開変数類

static final String tspecials = ",; "
 
static final String tspecials2 = "()<>@,;:\\\"/[]?={} \t"
 
static final Locale LOCALE_US = Locale.US
 
static final String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z"
 
static final DateFormat OLD_COOKIE_FORMAT = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US)
 
static final String ancientDate = formatOldCookie(new Date(10000))
 

詳解

Server-side cookie representation. borrowed from Tomcat.

関数詳解

◆ alreadyQuoted()

static boolean org.keycloak.common.util.ServerCookie.alreadyQuoted ( String  value)
inlinestatic
259  {
260  if (value == null || value.length() == 0) return false;
261  return (value.charAt(0) == '\"' && value.charAt(value.length() - 1) == '\"');
262  }

◆ appendCookieValue()

static void org.keycloak.common.util.ServerCookie.appendCookieValue ( StringBuffer  headerBuf,
int  version,
String  name,
String  value,
String  path,
String  domain,
String  comment,
int  maxAge,
boolean  isSecure,
boolean  httpOnly 
)
inlinestatic
176  {
177  StringBuffer buf = new StringBuffer();
178  // Servlet implementation checks name
179  buf.append(name);
180  buf.append("=");
181  // Servlet implementation does not check anything else
182 
183  // NOTE!!! BROWSERS REALLY DON'T LIKE QUOTING
184  //maybeQuote2(version, buf, value);
185  buf.append(value);
186 
187  // Add version 1 specific information
188  if (version == 1) {
189  // Version=1 ... required
190  buf.append("; Version=1");
191 
192  // Comment=comment
193  if (comment != null) {
194  buf.append("; Comment=");
195  //maybeQuote2(version, buf, comment);
196  buf.append(comment);
197  }
198  }
199 
200  // Add domain information, if present
201  if (domain != null) {
202  buf.append("; Domain=");
203  //maybeQuote2(version, buf, domain);
204  buf.append(domain);
205  }
206 
207  // Max-Age=secs ... or use old "Expires" format
208  // TODO RFC2965 Discard
209  if (maxAge >= 0) {
210  // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires Netscape format )
211  buf.append("; Expires=");
212  // To expire immediately we need to set the time in past
213  if (maxAge == 0)
214  buf.append(ancientDate);
215  else
217  (new Date(System.currentTimeMillis() +
218  maxAge * 1000L), buf,
219  new FieldPosition(0));
220 
221  buf.append("; Max-Age=");
222  buf.append(maxAge);
223  }
224 
225  // Path=path
226  if (path != null) {
227  buf.append("; Path=");
228  buf.append(path);
229  }
230 
231  // Secure
232  if (isSecure) {
233  buf.append("; Secure");
234  }
235 
236  // HttpOnly
237  if (httpOnly) {
238  buf.append("; HttpOnly");
239  }
240 
241  headerBuf.append(buf);
242  }
static String formatOldCookie(Date d)
Definition: ServerCookie.java:147
static final String ancientDate
Definition: ServerCookie.java:163

◆ checkName()

static boolean org.keycloak.common.util.ServerCookie.checkName ( String  name)
inlinestatic
非推奨:
  • Not used
87  {
88  if (!isToken(name)
89  || name.equalsIgnoreCase("Comment") // rfc2019
90  || name.equalsIgnoreCase("Discard") // rfc2965
91  || name.equalsIgnoreCase("Domain") // rfc2019
92  || name.equalsIgnoreCase("Expires") // Netscape
93  || name.equalsIgnoreCase("Max-Age") // rfc2019
94  || name.equalsIgnoreCase("Path") // rfc2019
95  || name.equalsIgnoreCase("Secure") // rfc2019
96  || name.equalsIgnoreCase("Version") // rfc2019
97  // TODO remaining RFC2965 attributes
98  ) {
99  return false;
100  }
101  return true;
102  }
static boolean isToken(String value)
Definition: ServerCookie.java:44

◆ containsCTL()

static boolean org.keycloak.common.util.ServerCookie.containsCTL ( String  value,
int  version 
)
inlinestatic
57  {
58  if (value == null) return false;
59  int len = value.length();
60  for (int i = 0; i < len; i++) {
61  char c = value.charAt(i);
62  if (c < 0x20 || c >= 0x7f) {
63  if (c == 0x09)
64  continue; //allow horizontal tabs
65  return true;
66  }
67  }
68  return false;
69  }

◆ escapeDoubleQuotes()

static String org.keycloak.common.util.ServerCookie.escapeDoubleQuotes ( String  s,
int  beginIndex,
int  endIndex 
)
inlinestaticprivate

Escapes any double quotes in the given string.

引数
sthe input string
beginIndexstart index inclusive
endIndexexclusive
戻り値
The (possibly) escaped string
302  {
303 
304  if (s == null || s.length() == 0 || s.indexOf('"') == -1) {
305  return s;
306  }
307 
308  StringBuffer b = new StringBuffer();
309  for (int i = beginIndex; i < endIndex; i++) {
310  char c = s.charAt(i);
311  if (c == '\\') {
312  b.append(c);
313  //ignore the character after an escape, just append it
314  if (++i >= endIndex) throw new IllegalArgumentException("Invalid escape character in cookie value.");
315  b.append(s.charAt(i));
316  } else if (c == '"')
317  b.append('\\').append('"');
318  else
319  b.append(c);
320  }
321 
322  return b.toString();
323  }

◆ formatOldCookie() [1/2]

static String org.keycloak.common.util.ServerCookie.formatOldCookie ( Date  d)
inlinestatic
147  {
148  String ocf = null;
149  synchronized (OLD_COOKIE_FORMAT) {
150  ocf = OLD_COOKIE_FORMAT.format(d);
151  }
152  return ocf;
153  }
static final DateFormat OLD_COOKIE_FORMAT
Definition: ServerCookie.java:142

◆ formatOldCookie() [2/2]

static void org.keycloak.common.util.ServerCookie.formatOldCookie ( Date  d,
StringBuffer  sb,
FieldPosition  fp 
)
inlinestatic
156  {
157  synchronized (OLD_COOKIE_FORMAT) {
158  OLD_COOKIE_FORMAT.format(d, sb, fp);
159  }
160  }
static final DateFormat OLD_COOKIE_FORMAT
Definition: ServerCookie.java:142

◆ getCookieHeaderName()

static String org.keycloak.common.util.ServerCookie.getCookieHeaderName ( int  version)
inlinestatic

Return the header name to set the cookie, based on cookie version.

110  {
111  // TODO Re-enable logging when RFC2965 is implemented
112  // log( (version==1) ? "Set-Cookie2" : "Set-Cookie");
113  if (version == 1) {
114  // XXX RFC2965 not referenced in Servlet Spec
115  // Set-Cookie2 is not supported by Netscape 4, 6, IE 3, 5
116  // Set-Cookie2 is supported by Lynx and Opera
117  // Need to check on later IE and FF releases but for now...
118  // RFC2109
119  return "Set-Cookie";
120  // return "Set-Cookie2";
121  } else {
122  // Old Netscape
123  return "Set-Cookie";
124  }
125  }

◆ isToken()

static boolean org.keycloak.common.util.ServerCookie.isToken ( String  value)
inlinestatic
44  {
45  if (value == null) return true;
46  int len = value.length();
47 
48  for (int i = 0; i < len; i++) {
49  char c = value.charAt(i);
50 
51  if (tspecials.indexOf(c) != -1)
52  return false;
53  }
54  return true;
55  }
static final String tspecials
Definition: ServerCookie.java:32

◆ isToken2()

static boolean org.keycloak.common.util.ServerCookie.isToken2 ( String  value)
inlinestatic
72  {
73  if (value == null) return true;
74  int len = value.length();
75 
76  for (int i = 0; i < len; i++) {
77  char c = value.charAt(i);
78  if (tspecials2.indexOf(c) != -1)
79  return false;
80  }
81  return true;
82  }
static final String tspecials2
Definition: ServerCookie.java:33

◆ maybeQuote()

static void org.keycloak.common.util.ServerCookie.maybeQuote ( int  version,
StringBuffer  buf,
String  value 
)
inlinestatic
非推奨:
  • Not used
248  {
249  // special case - a \n or \r shouldn't happen in any case
250  if (isToken(value)) {
251  buf.append(value);
252  } else {
253  buf.append('"');
254  buf.append(escapeDoubleQuotes(value, 0, value.length()));
255  buf.append('"');
256  }
257  }
static String escapeDoubleQuotes(String s, int beginIndex, int endIndex)
Definition: ServerCookie.java:302
static boolean isToken(String value)
Definition: ServerCookie.java:44

◆ maybeQuote2()

static void org.keycloak.common.util.ServerCookie.maybeQuote2 ( int  version,
StringBuffer  buf,
String  value 
)
inlinestatic

Quotes values using rules that vary depending on Cookie version.

引数
version
buf
value
271  {
272  if (value == null || value.length() == 0) {
273  buf.append("\"\"");
274  } else if (containsCTL(value, version))
275  throw new IllegalArgumentException("Control character in cookie value, consider BASE64 encoding your value");
276  else if (alreadyQuoted(value)) {
277  buf.append('"');
278  buf.append(escapeDoubleQuotes(value, 1, value.length() - 1));
279  buf.append('"');
280  } else if (version == 0 && !isToken(value)) {
281  buf.append('"');
282  buf.append(escapeDoubleQuotes(value, 0, value.length()));
283  buf.append('"');
284  } else if (version == 1 && !isToken2(value)) {
285  buf.append('"');
286  buf.append(escapeDoubleQuotes(value, 0, value.length()));
287  buf.append('"');
288  } else {
289  buf.append(value);
290  }
291  }
static String escapeDoubleQuotes(String s, int beginIndex, int endIndex)
Definition: ServerCookie.java:302
static boolean isToken(String value)
Definition: ServerCookie.java:44
static boolean alreadyQuoted(String value)
Definition: ServerCookie.java:259
static boolean containsCTL(String value, int version)
Definition: ServerCookie.java:57
static boolean isToken2(String value)
Definition: ServerCookie.java:72

メンバ詳解

◆ ancientDate

final String org.keycloak.common.util.ServerCookie.ancientDate = formatOldCookie(new Date(10000))
staticprivate

◆ GMT_ZONE

final TimeZone org.keycloak.common.util.ServerCookie.GMT_ZONE = TimeZone.getTimeZone("GMT")
static

GMT timezone - all HTTP dates are on GMT

◆ LOCALE_US

final Locale org.keycloak.common.util.ServerCookie.LOCALE_US = Locale.US
staticprivate

US locale - all HTTP dates are in english

◆ OLD_COOKIE_FORMAT

final DateFormat org.keycloak.common.util.ServerCookie.OLD_COOKIE_FORMAT = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US)
staticprivate

◆ OLD_COOKIE_PATTERN

final String org.keycloak.common.util.ServerCookie.OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z"
staticprivate

Pattern used for old cookies

◆ static

org.keycloak.common.util.ServerCookie.static
staticpackage
初期値:

◆ tspecials

final String org.keycloak.common.util.ServerCookie.tspecials = ",; "
staticprivate

◆ tspecials2

final String org.keycloak.common.util.ServerCookie.tspecials2 = "()<>@,;:\\\"/[]?={} \t"
staticprivate

このクラス詳解は次のファイルから抽出されました: