Parses a URI string, applies validation rules described in SPIFFE standard, and, in case of success, returns parsed TrustDomain and Path. @param uri a String representing a SPIFFE ID
(String uri)
| 66 | * @param uri a String representing a SPIFFE ID |
| 67 | */ |
| 68 | public static SpiffeId parse(String uri) { |
| 69 | doInitialUriValidation(uri); |
| 70 | checkArgument(uri.toLowerCase(Locale.US).startsWith(PREFIX), "Spiffe Id must start with " |
| 71 | + PREFIX); |
| 72 | String domainAndPath = uri.substring(PREFIX.length()); |
| 73 | String trustDomain; |
| 74 | String path; |
| 75 | if (!domainAndPath.contains("/")) { |
| 76 | trustDomain = domainAndPath; |
| 77 | path = ""; |
| 78 | } else { |
| 79 | String[] parts = domainAndPath.split("/", 2); |
| 80 | trustDomain = parts[0]; |
| 81 | path = parts[1]; |
| 82 | checkArgument(!path.isEmpty(), "Path must not include a trailing '/'"); |
| 83 | } |
| 84 | validateTrustDomain(trustDomain); |
| 85 | validatePath(path); |
| 86 | if (!path.isEmpty()) { |
| 87 | path = "/" + path; |
| 88 | } |
| 89 | return new SpiffeId(trustDomain, path); |
| 90 | } |
| 91 | |
| 92 | private static void doInitialUriValidation(String uri) { |
| 93 | checkArgument(checkNotNull(uri, "uri").length() > 0, "Spiffe Id can't be empty"); |