mitreid-connect
静的公開メンバ関数 | 非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.mitre.discovery.util.WebfingerURLNormalizer クラス
org.mitre.discovery.util.WebfingerURLNormalizer 連携図
Collaboration graph

静的公開メンバ関数

static UriComponents normalizeResource (String identifier)
 
static String serializeURL (UriComponents uri)
 

非公開メンバ関数

 WebfingerURLNormalizer ()
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(WebfingerURLNormalizer.class)
 
static final Pattern pattern
 

詳解

Provides utility methods for normalizing and parsing URIs for use with Webfinger Discovery.

著者
wkim

構築子と解体子

◆ WebfingerURLNormalizer()

org.mitre.discovery.util.WebfingerURLNormalizer.WebfingerURLNormalizer ( )
inlineprivate

Private constructor to prevent instantiation.

63  {
64  // intentionally blank
65  }

関数詳解

◆ normalizeResource()

static UriComponents org.mitre.discovery.util.WebfingerURLNormalizer.normalizeResource ( String  identifier)
inlinestatic

Normalize the resource string as per OIDC Discovery.

引数
identifier
戻り値
the normalized string, or null if the string can't be normalized
72  {
73  // try to parse the URI
74  // NOTE: we can't use the Java built-in URI class because it doesn't split the parts appropriately
75 
76  if (Strings.isNullOrEmpty(identifier)) {
77  logger.warn("Can't normalize null or empty URI: " + identifier);
78  return null; // nothing we can do
79  } else {
80 
81  //UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(identifier);
82  UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
83 
84  Matcher m = pattern.matcher(identifier);
85  if (m.matches()) {
86  builder.scheme(m.group(2));
87  builder.userInfo(m.group(6));
88  builder.host(m.group(8));
89  String port = m.group(10);
90  if (!Strings.isNullOrEmpty(port)) {
91  builder.port(Integer.parseInt(port));
92  }
93  builder.path(m.group(11));
94  builder.query(m.group(13));
95  builder.fragment(m.group(15)); // we throw away the hash, but this is the group it would be if we kept it
96  } else {
97  // doesn't match the pattern, throw it out
98  logger.warn("Parser couldn't match input: " + identifier);
99  return null;
100  }
101 
102  UriComponents n = builder.build();
103 
104  if (Strings.isNullOrEmpty(n.getScheme())) {
105  if (!Strings.isNullOrEmpty(n.getUserInfo())
106  && Strings.isNullOrEmpty(n.getPath())
107  && Strings.isNullOrEmpty(n.getQuery())
108  && n.getPort() < 0) {
109 
110  // scheme empty, userinfo is not empty, path/query/port are empty
111  // set to "acct" (rule 2)
112  builder.scheme("acct");
113 
114  } else {
115  // scheme is empty, but rule 2 doesn't apply
116  // set scheme to "https" (rule 3)
117  builder.scheme("https");
118  }
119  }
120 
121  // fragment must be stripped (rule 4)
122  builder.fragment(null);
123 
124  return builder.build();
125  }
126 
127 
128  }
static final Pattern pattern
Definition: WebfingerURLNormalizer.java:45
static final Logger logger
Definition: WebfingerURLNormalizer.java:42

◆ serializeURL()

static String org.mitre.discovery.util.WebfingerURLNormalizer.serializeURL ( UriComponents  uri)
inlinestatic
131  {
132  if (uri.getScheme() != null &&
133  (uri.getScheme().equals("acct") ||
134  uri.getScheme().equals("mailto") ||
135  uri.getScheme().equals("tel") ||
136  uri.getScheme().equals("device")
137  )) {
138 
139  // serializer copied from HierarchicalUriComponents but with "//" removed
140 
141  StringBuilder uriBuilder = new StringBuilder();
142 
143  if (uri.getScheme() != null) {
144  uriBuilder.append(uri.getScheme());
145  uriBuilder.append(':');
146  }
147 
148  if (uri.getUserInfo() != null || uri.getHost() != null) {
149  if (uri.getUserInfo() != null) {
150  uriBuilder.append(uri.getUserInfo());
151  uriBuilder.append('@');
152  }
153  if (uri.getHost() != null) {
154  uriBuilder.append(uri.getHost());
155  }
156  if (uri.getPort() != -1) {
157  uriBuilder.append(':');
158  uriBuilder.append(uri.getPort());
159  }
160  }
161 
162  String path = uri.getPath();
163  if (StringUtils.hasLength(path)) {
164  if (uriBuilder.length() != 0 && path.charAt(0) != '/') {
165  uriBuilder.append('/');
166  }
167  uriBuilder.append(path);
168  }
169 
170  String query = uri.getQuery();
171  if (query != null) {
172  uriBuilder.append('?');
173  uriBuilder.append(query);
174  }
175 
176  if (uri.getFragment() != null) {
177  uriBuilder.append('#');
178  uriBuilder.append(uri.getFragment());
179  }
180 
181  return uriBuilder.toString();
182  } else {
183  return uri.toUriString();
184  }
185 
186  }

メンバ詳解

◆ logger

final Logger org.mitre.discovery.util.WebfingerURLNormalizer.logger = LoggerFactory.getLogger(WebfingerURLNormalizer.class)
staticprivate

Logger for this class

◆ pattern

final Pattern org.mitre.discovery.util.WebfingerURLNormalizer.pattern
staticprivate
初期値:
= Pattern.compile("^" +
"((https|acct|http|mailto|tel|device):(//)?)?" +
"(" +
"(([^@]+)@)?" +
"(([^\\?#:/]+)" +
"(:(\\d*))?)" +
")" +
"([^\\?#]+)?" +
"(\\?([^#]+))?" +
"(#(.*))?" +
"$"
)

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