-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathKnownMetadataProvider.java
More file actions
81 lines (64 loc) · 2.94 KB
/
KnownMetadataProvider.java
File metadata and controls
81 lines (64 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import java.util.*;
/**
* Provides hardcoded instance discovery metadata for well-known cloud environments.
* This allows correct alias resolution and cache behavior even when the network
* instance discovery endpoint is unreachable.
*
* Mirrors the KnownMetadataProvider in MSAL .NET.
*/
class KnownMetadataProvider {
private static final Map<String, InstanceDiscoveryMetadataEntry> KNOWN_ENTRIES;
static {
Map<String, InstanceDiscoveryMetadataEntry> entries = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
addEntry(entries,
"login.microsoftonline.com", "login.windows.net",
"login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net");
addEntry(entries,
"login.partner.microsoftonline.cn", "login.partner.microsoftonline.cn",
"login.partner.microsoftonline.cn", "login.chinacloudapi.cn");
addEntry(entries,
"login.microsoftonline.de", "login.microsoftonline.de",
"login.microsoftonline.de");
addEntry(entries,
"login.microsoftonline.us", "login.microsoftonline.us",
"login.microsoftonline.us", "login.usgovcloudapi.net");
addEntry(entries,
"login-us.microsoftonline.com", "login-us.microsoftonline.com",
"login-us.microsoftonline.com");
addEntry(entries,
"login.sovcloud-identity.fr", "login.sovcloud-identity.fr",
"login.sovcloud-identity.fr");
addEntry(entries,
"login.sovcloud-identity.de", "login.sovcloud-identity.de",
"login.sovcloud-identity.de");
addEntry(entries,
"login.sovcloud-identity.sg", "login.sovcloud-identity.sg",
"login.sovcloud-identity.sg");
KNOWN_ENTRIES = Collections.unmodifiableMap(entries);
}
private static void addEntry(Map<String, InstanceDiscoveryMetadataEntry> entries,
String preferredNetwork,
String preferredCache,
String... aliases) {
Set<String> aliasSet = new LinkedHashSet<>(Arrays.asList(aliases));
InstanceDiscoveryMetadataEntry entry = new InstanceDiscoveryMetadataEntry(preferredNetwork, preferredCache, aliasSet);
for (String alias : aliases) {
entries.put(alias, entry);
}
}
/**
* Returns the known metadata entry for the given host, or null if unknown.
*/
static InstanceDiscoveryMetadataEntry getMetadataEntry(String host) {
return KNOWN_ENTRIES.get(host);
}
/**
* Returns true if the host is a well-known cloud environment.
*/
static boolean isKnownEnvironment(String host) {
return KNOWN_ENTRIES.containsKey(host);
}
}