keycloak
公開メンバ関数 | 限定公開メンバ関数 | 非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.common.util.PathMatcher< P > クラステンプレートabstract
org.keycloak.common.util.PathMatcher< P > 連携図
Collaboration graph

公開メンバ関数

matches (final String targetUri)
 
boolean endsWithWildcard (String expectedUri)
 

限定公開メンバ関数

abstract String getPath (P entry)
 
abstract Collection< P > getPaths ()
 
String buildUriFromTemplate (String template, String targetUri, boolean onlyFirstParam)
 
resolvePathConfig (P entry, String path)
 

非公開メンバ関数

boolean exactMatch (String expectedUri, String targetUri, String value)
 
boolean isTemplate (String uri)
 

静的非公開変数類

static final char WILDCARD = '*'
 

詳解

著者
Pedro Igor

関数詳解

◆ buildUriFromTemplate()

String org.keycloak.common.util.PathMatcher< P >.buildUriFromTemplate ( String  template,
String  targetUri,
boolean  onlyFirstParam 
)
inlineprotected
147  {
148  String expectedUri = template;
149  int patternStartIndex = expectedUri.indexOf("{");
150 
151  if (expectedUri.endsWith("/*")) {
152  expectedUri = expectedUri.substring(0, expectedUri.length() - 2);
153  }
154 
155  if (patternStartIndex == -1 || patternStartIndex >= targetUri.length()) {
156  return null;
157  }
158 
159  if (expectedUri.split("/").length > targetUri.split("/").length) {
160  return null;
161  }
162 
163  char[] expectedUriChars = expectedUri.toCharArray();
164  char[] matchingUri = Arrays.copyOfRange(expectedUriChars, 0, patternStartIndex);
165  int matchingUriLastIndex = matchingUri.length;
166  String targetUriParams = targetUri.substring(patternStartIndex);
167 
168  if (Arrays.equals(matchingUri, Arrays.copyOf(targetUri.toCharArray(), matchingUri.length))) {
169  matchingUri = Arrays.copyOf(matchingUri, targetUri.length());
170  int paramIndex = 0;
171 
172  for (int i = patternStartIndex; i < expectedUriChars.length; i++) {
173  if (matchingUriLastIndex >= matchingUri.length) {
174  break;
175  }
176 
177  char c = expectedUriChars[i];
178 
179  if (c == '{' || c == '*') {
180  String[] params = targetUriParams.split("/");
181 
182  for (int k = paramIndex; k <= (c == '*' ? params.length : paramIndex); k++) {
183  if (k == params.length) {
184  break;
185  }
186 
187  int paramLength = params[k].length();
188 
189  if (matchingUriLastIndex + paramLength > matchingUri.length) {
190  return null;
191  }
192 
193  for (int j = 0; j < paramLength; j++) {
194  matchingUri[matchingUriLastIndex++] = params[k].charAt(j);
195  }
196 
197  if (c == '*' && matchingUriLastIndex < matchingUri.length) {
198  matchingUri[matchingUriLastIndex++] = '/';
199  }
200  }
201 
202  i = expectedUri.indexOf('}', i);
203 
204  if (i == expectedUri.lastIndexOf('}') && onlyFirstParam) {
205  return String.valueOf(matchingUri).substring(0, matchingUriLastIndex);
206  }
207  } else {
208  if (c == '/') {
209  paramIndex++;
210  }
211  matchingUri[matchingUriLastIndex++] = c;
212  }
213  }
214 
215  if (matchingUri[matchingUri.length - 1] == '\u0000') {
216  if (template.endsWith("*")) {
217  StringBuilder firstParam = new StringBuilder(String.valueOf(matchingUri).substring(0, matchingUriLastIndex));
218 
219  firstParam.append(targetUri.substring(firstParam.length()));
220 
221  return firstParam.toString();
222  }
223  return null;
224  }
225 
226  return String.valueOf(matchingUri);
227  }
228 
229  return null;
230  }

◆ endsWithWildcard()

boolean org.keycloak.common.util.PathMatcher< P >.endsWithWildcard ( String  expectedUri)
inline
232  {
233  int length = expectedUri.length();
234  return length > 0 && WILDCARD == expectedUri.charAt(length - 1);
235  }
static final char WILDCARD
Definition: PathMatcher.java:27

◆ exactMatch()

boolean org.keycloak.common.util.PathMatcher< P >.exactMatch ( String  expectedUri,
String  targetUri,
String  value 
)
inlineprivate
128  {
129  if (targetUri.equals(value)) {
130  return value.equals(targetUri);
131  }
132 
133  if (endsWithWildcard(expectedUri)) {
134  return targetUri.startsWith(expectedUri.substring(0, expectedUri.length() - 2));
135  }
136 
137  String suffix = "/*.";
138  int suffixIndex = expectedUri.indexOf(suffix);
139 
140  if (suffixIndex != -1) {
141  return targetUri.endsWith(expectedUri.substring(suffixIndex + suffix.length() - 1));
142  }
143 
144  return false;
145  }
boolean endsWithWildcard(String expectedUri)
Definition: PathMatcher.java:232

◆ getPath()

abstract String org.keycloak.common.util.PathMatcher< P >.getPath ( entry)
abstractprotected

◆ getPaths()

abstract Collection<P> org.keycloak.common.util.PathMatcher< P >.getPaths ( )
abstractprotected

◆ isTemplate()

boolean org.keycloak.common.util.PathMatcher< P >.isTemplate ( String  uri)
inlineprivate
237  {
238  return uri.indexOf("{") != -1;
239  }

◆ matches()

P org.keycloak.common.util.PathMatcher< P >.matches ( final String  targetUri)
inline
29  {
30  int patternCount = 0;
31  P matchingPath = null;
32  P matchingAnyPath = null;
33  P matchingAnySuffixPath = null;
34 
35  for (P entry : getPaths()) {
36  String expectedUri = getPath(entry);
37 
38  if (expectedUri == null) {
39  continue;
40  }
41 
42  String matchingUri = null;
43 
44  if (exactMatch(expectedUri, targetUri, expectedUri)) {
45  matchingUri = expectedUri;
46  }
47 
48  if (isTemplate(expectedUri)) {
49  String templateUri = buildUriFromTemplate(expectedUri, targetUri, false);
50 
51  if (templateUri != null) {
52  int length = expectedUri.split("\\/").length;
53 
54  if (exactMatch(expectedUri, targetUri, templateUri) && (patternCount == 0 || length > patternCount)) {
55  matchingUri = templateUri;
56  P resolved = resolvePathConfig(entry, targetUri);
57 
58  if (resolved != null) {
59  entry = resolved;
60  }
61 
62  patternCount = length;
63  }
64  }
65  }
66 
67  if (matchingUri != null) {
68  StringBuilder path = new StringBuilder(expectedUri);
69  int patternIndex = path.indexOf("/" + WILDCARD);
70 
71  if (patternIndex != -1) {
72  path.delete(patternIndex, path.length());
73  }
74 
75  patternIndex = path.indexOf("{");
76 
77  if (patternIndex != -1) {
78  path.delete(patternIndex, path.length());
79  }
80 
81  String pathString = path.toString();
82 
83  if ("".equals(pathString)) {
84  pathString = "/";
85  }
86 
87  if (matchingUri.equals(targetUri) || pathString.equals(targetUri)) {
88  if (patternCount == 0) {
89  return entry;
90  } else {
91  matchingPath = entry;
92  }
93  }
94 
95  if (WILDCARD == expectedUri.charAt(expectedUri.length() - 1)) {
96  if (matchingAnyPath == null || getPath(matchingAnyPath).length() < matchingUri.length()) {
97  matchingAnyPath = entry;
98  }
99  } else {
100  int suffixIndex = expectedUri.indexOf(WILDCARD + ".");
101 
102  if (suffixIndex != -1) {
103  String protectedSuffix = expectedUri.substring(suffixIndex + 1);
104 
105  if (targetUri.endsWith(protectedSuffix)) {
106  matchingAnySuffixPath = entry;
107  }
108  }
109  }
110  }
111  }
112 
113  if (matchingPath != null) {
114  return matchingPath;
115  }
116 
117  if (matchingAnySuffixPath != null) {
118  return matchingAnySuffixPath;
119  }
120 
121  return matchingAnyPath;
122  }
boolean isTemplate(String uri)
Definition: PathMatcher.java:237
String buildUriFromTemplate(String template, String targetUri, boolean onlyFirstParam)
Definition: PathMatcher.java:147
static final char WILDCARD
Definition: PathMatcher.java:27
abstract String getPath(P entry)
P resolvePathConfig(P entry, String path)
Definition: PathMatcher.java:241
abstract Collection< P > getPaths()
boolean exactMatch(String expectedUri, String targetUri, String value)
Definition: PathMatcher.java:128

◆ resolvePathConfig()

P org.keycloak.common.util.PathMatcher< P >.resolvePathConfig ( entry,
String  path 
)
inlineprotected
241  {
242  return entry;
243  }

メンバ詳解

◆ WILDCARD

final char org.keycloak.common.util.PathMatcher< P >.WILDCARD = '*'
staticprivate

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