Skip to content

Commit 2fc5fcd

Browse files
address review comments
1 parent fc93217 commit 2fc5fcd

File tree

10 files changed

+31
-35
lines changed

10 files changed

+31
-35
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
package org.elasticsearch.gradle.internal.dependencies.patches.hdfs;
10+
package org.elasticsearch.gradle.internal.dependencies.patches;
1111

1212
import org.objectweb.asm.MethodVisitor;
1313
import org.objectweb.asm.Opcodes;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/azurecore/AzureCoreClassPatcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.gradle.internal.dependencies.patches.PatcherInfo;
1313
import org.elasticsearch.gradle.internal.dependencies.patches.Utils;
14+
import org.gradle.api.artifacts.transform.CacheableTransform;
1415
import org.gradle.api.artifacts.transform.InputArtifact;
1516
import org.gradle.api.artifacts.transform.TransformAction;
1617
import org.gradle.api.artifacts.transform.TransformOutputs;
@@ -26,6 +27,7 @@
2627

2728
import static org.elasticsearch.gradle.internal.dependencies.patches.PatcherInfo.classPatcher;
2829

30+
@CacheableTransform
2931
public abstract class AzureCoreClassPatcher implements TransformAction<TransformParameters.None> {
3032

3133
private static final String JAR_FILE_TO_PATCH = "azure-core-[\\d.]*\\.jar";

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/azurecore/ImplUtilsPatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package org.elasticsearch.gradle.internal.dependencies.patches.azurecore;
1111

12-
import org.elasticsearch.gradle.internal.dependencies.patches.hdfs.MethodReplacement;
12+
import org.elasticsearch.gradle.internal.dependencies.patches.MethodReplacement;
1313
import org.objectweb.asm.ClassVisitor;
1414
import org.objectweb.asm.MethodVisitor;
1515
import org.objectweb.asm.Opcodes;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/hdfs/ShellPatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.gradle.internal.dependencies.patches.hdfs;
1111

12+
import org.elasticsearch.gradle.internal.dependencies.patches.MethodReplacement;
1213
import org.objectweb.asm.ClassVisitor;
1314
import org.objectweb.asm.ClassWriter;
1415
import org.objectweb.asm.MethodVisitor;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/hdfs/ShutdownHookManagerPatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.gradle.internal.dependencies.patches.hdfs;
1111

12+
import org.elasticsearch.gradle.internal.dependencies.patches.MethodReplacement;
1213
import org.objectweb.asm.ClassVisitor;
1314
import org.objectweb.asm.ClassWriter;
1415
import org.objectweb.asm.MethodVisitor;

gradle/verification-metadata.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,11 +3063,6 @@
30633063
<sha256 value="015d5c229f3cd5c0ebf175c1da08d596d94043362ae9d92637d88848c90537c8" origin="Generated by Gradle"/>
30643064
</artifact>
30653065
</component>
3066-
<component group="org.apache.logging.log4j" name="log4j-slf4j2-impl" version="2.24.3">
3067-
<artifact name="log4j-slf4j2-impl-2.24.3.jar">
3068-
<sha256 value="cdaac22e40ec30c4096e1ebe8c454c8826c0d1c378d7db5d7b3ad166354b0bd3" origin="Generated by Gradle"/>
3069-
</artifact>
3070-
</component>
30713066
<component group="org.apache.lucene" name="lucene-analysis-common" version="10.2.1">
30723067
<artifact name="lucene-analysis-common-10.2.1.jar">
30733068
<sha256 value="73e5dfac4c64ea5af6a0e70276c4cf3216085c05de3a6547d4240145bb362a7d" origin="Generated by Gradle"/>

plugins/microsoft-graph-authz/src/main/java/org/elasticsearch/xpack/security/authz/microsoft/MicrosoftGraphAuthzRealm.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.microsoft.graph.core.tasks.PageIterator;
1515
import com.microsoft.graph.models.Group;
1616
import com.microsoft.graph.models.GroupCollectionResponse;
17+
import com.microsoft.graph.models.odataerrors.ODataError;
1718
import com.microsoft.graph.serviceclient.GraphServiceClient;
1819
import com.microsoft.kiota.authentication.AzureIdentityAuthenticationProvider;
1920

@@ -43,7 +44,7 @@
4344
import java.util.ArrayList;
4445
import java.util.List;
4546
import java.util.Map;
46-
import java.util.concurrent.ExecutorService;
47+
import java.util.stream.Collectors;
4748

4849
public class MicrosoftGraphAuthzRealm extends Realm {
4950

@@ -64,7 +65,7 @@ public class MicrosoftGraphAuthzRealm extends Realm {
6465
private final UserRoleMapper roleMapper;
6566
private final GraphServiceClient client;
6667
private final XPackLicenseState licenseState;
67-
private final ExecutorService genericExecutor;
68+
private final ThreadPool threadPool;
6869

6970
public MicrosoftGraphAuthzRealm(UserRoleMapper roleMapper, RealmConfig config, ThreadPool threadPool) {
7071
super(config);
@@ -74,19 +75,12 @@ public MicrosoftGraphAuthzRealm(UserRoleMapper roleMapper, RealmConfig config, T
7475
var clientSecret = config.getSetting(MicrosoftGraphAuthzRealmSettings.CLIENT_SECRET);
7576

7677
require(MicrosoftGraphAuthzRealmSettings.CLIENT_ID);
78+
require(MicrosoftGraphAuthzRealmSettings.CLIENT_SECRET);
7779
require(MicrosoftGraphAuthzRealmSettings.TENANT_ID);
7880

79-
if (clientSecret.isEmpty()) {
80-
throw new SettingsException(
81-
"The configuration setting ["
82-
+ RealmSettings.getFullSettingKey(config, MicrosoftGraphAuthzRealmSettings.CLIENT_SECRET)
83-
+ "] is required"
84-
);
85-
}
86-
8781
this.client = buildClient(clientSecret);
8882
this.licenseState = XPackPlugin.getSharedLicenseState();
89-
this.genericExecutor = threadPool.generic();
83+
this.threadPool = threadPool;
9084
}
9185

9286
// for testing
@@ -102,12 +96,12 @@ public MicrosoftGraphAuthzRealm(UserRoleMapper roleMapper, RealmConfig config, T
10296
this.roleMapper = roleMapper;
10397
this.client = client;
10498
this.licenseState = licenseState;
105-
this.genericExecutor = threadPool.generic();
99+
this.threadPool = threadPool;
106100
}
107101

108-
private void require(Setting.AffixSetting<String> setting) {
102+
private <T> void require(Setting.AffixSetting<T> setting) {
109103
final var value = config.getSetting(setting);
110-
if (value.isEmpty()) {
104+
if (value.toString().isEmpty()) {
111105
throw new SettingsException("The configuration setting [" + RealmSettings.getFullSettingKey(config, setting) + "] is required");
112106
}
113107
}
@@ -134,12 +128,11 @@ public void lookupUser(String principal, ActionListener<User> listener) {
134128
return;
135129
}
136130

137-
genericExecutor.execute(() -> {
131+
threadPool.generic().execute(() -> {
138132
try {
139-
final var userProperties = sdkFetchUserProperties(client, principal);
140-
final var groups = sdkFetchGroupMembership(client, principal);
133+
final var userProperties = fetchUserProperties(client, principal);
134+
final var groups = fetchGroupMembership(client, principal);
141135

142-
// TODO confirm we don't need any other fields
143136
final var userData = new UserRoleMapper.UserData(principal, null, groups, Map.of(), config);
144137

145138
roleMapper.resolveRoles(userData, listener.delegateFailureAndWrap((l, roles) -> {
@@ -151,18 +144,17 @@ public void lookupUser(String principal, ActionListener<User> listener) {
151144
Map.of(),
152145
true
153146
);
154-
logger.trace("Entra ID user {}", user);
147+
logger.trace("Authorized user from Microsoft Graph {}", user);
155148
l.onResponse(user);
156149
}));
157-
} catch (Exception e) {
150+
} catch (ReflectiveOperationException | ODataError e) {
158151
logger.error("failed to authenticate with realm", e);
159152
listener.onFailure(e);
160153
}
161154
});
162155
}
163156

164157
private GraphServiceClient buildClient(SecureString clientSecret) {
165-
logger.trace("building client");
166158
final var credentialProviderBuilder = new ClientSecretCredentialBuilder().clientId(
167159
config.getSetting(MicrosoftGraphAuthzRealmSettings.CLIENT_ID)
168160
)
@@ -183,17 +175,17 @@ private GraphServiceClient buildClient(SecureString clientSecret) {
183175
);
184176
}
185177

186-
private Tuple<String, String> sdkFetchUserProperties(GraphServiceClient client, String userId) {
178+
private Tuple<String, String> fetchUserProperties(GraphServiceClient client, String userId) {
187179
var response = client.users()
188180
.byUserId(userId)
189181
.get(requestConfig -> requestConfig.queryParameters.select = new String[] { "displayName", "mail" });
190182

191-
logger.trace("User [{}] has email [{}]", response.getDisplayName(), response.getMail());
183+
logger.trace("Fetched user with name [{}] and email [{}] from Microsoft Graph", response.getDisplayName(), response.getMail());
192184

193185
return Tuple.tuple(response.getDisplayName(), response.getMail());
194186
}
195187

196-
private List<String> sdkFetchGroupMembership(GraphServiceClient client, String userId) throws ReflectiveOperationException {
188+
private List<String> fetchGroupMembership(GraphServiceClient client, String userId) throws ReflectiveOperationException {
197189
List<String> groups = new ArrayList<>();
198190

199191
var groupMembership = client.users().byUserId(userId).transitiveMemberOf().graphGroup().get(requestConfig -> {
@@ -217,6 +209,10 @@ private List<String> sdkFetchGroupMembership(GraphServiceClient client, String u
217209

218210
pageIterator.iterate();
219211

212+
if (logger.isTraceEnabled()) {
213+
logger.trace("Fetched [{}] groups from Microsoft Graph: [{}]", groups.size(), String.join(", ", groups));
214+
}
215+
220216
return groups;
221217
}
222218
}

x-pack/plugin/security/qa/microsoft-graph-authz-tests/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ dependencies {
99
}
1010

1111
tasks.named("javaRestTest").configure {
12+
// disable tests in FIPS mode as we need to use a custom truststore containing the certs used in MicrosoftGraphHttpFixture
1213
buildParams.withFipsEnabledOnly(it)
1314
}

x-pack/plugin/security/qa/microsoft-graph-authz-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/authz/microsoft/MicrosoftGraphAuthzPluginIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
6868
new TestUser("User3", "User 3", "[email protected]", List.of(), List.of())
6969
);
7070

71-
private static final MsGraphHttpFixture graphFixture = new MsGraphHttpFixture(TENANT_ID, CLIENT_ID, CLIENT_SECRET, TEST_USERS, 3);
71+
private static final MicrosoftGraphHttpFixture graphFixture = new MicrosoftGraphHttpFixture(TENANT_ID, CLIENT_ID, CLIENT_SECRET, TEST_USERS, 3);
7272

7373
public static ElasticsearchCluster cluster = initTestCluster();
7474

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
import javax.net.ssl.KeyManager;
4242
import javax.net.ssl.SSLContext;
4343

44-
public class MsGraphHttpFixture extends ExternalResource {
44+
public class MicrosoftGraphHttpFixture extends ExternalResource {
4545

46-
private static final Logger logger = LogManager.getLogger(MsGraphHttpFixture.class);
46+
private static final Logger logger = LogManager.getLogger(MicrosoftGraphHttpFixture.class);
4747

4848
private final String tenantId;
4949
private final String clientId;
@@ -58,7 +58,7 @@ public class MsGraphHttpFixture extends ExternalResource {
5858

5959
private HttpsServer server;
6060

61-
public MsGraphHttpFixture(String tenantId, String clientId, String clientSecret, List<TestUser> users, int groupsPageSize) {
61+
public MicrosoftGraphHttpFixture(String tenantId, String clientId, String clientSecret, List<TestUser> users, int groupsPageSize) {
6262
this.tenantId = tenantId;
6363
this.clientId = clientId;
6464
this.clientSecret = clientSecret;

0 commit comments

Comments
 (0)