Skip to content

Commit 46bc3d3

Browse files
committed
Add Microsoft Graph Delegated Authorization Realm Plugin
1 parent 99f67fa commit 46bc3d3

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
apply plugin: 'elasticsearch.internal-java-rest-test'
11+
12+
esplugin {
13+
name = "microsoft-graph-authz"
14+
description = "Microsoft Graph Delegated Authorization Realm Plugin"
15+
classname = "org.elasticsearch.plugin.security.authz.MicrosoftGraphAuthzPlugin"
16+
extendedPlugins = ["x-pack-security"]
17+
}
18+
19+
dependencies {
20+
compileOnly project(':x-pack:plugin:core')
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
module org.elasticsearch.plugin.security.authz {
11+
requires org.elasticsearch.base;
12+
requires org.elasticsearch.server;
13+
requires org.elasticsearch.xcore;
14+
requires org.elasticsearch.logging;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.plugin.security.authz;
11+
12+
import org.elasticsearch.common.settings.Setting;
13+
import org.elasticsearch.plugins.Plugin;
14+
import org.elasticsearch.xpack.core.security.SecurityExtension;
15+
import org.elasticsearch.xpack.core.security.authc.Realm;
16+
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
public class MicrosoftGraphAuthzPlugin extends Plugin implements SecurityExtension {
21+
@Override
22+
public Map<String, Realm.Factory> getRealms(SecurityComponents components) {
23+
return Map.of(MicrosoftGraphAuthzRealmSettings.REALM_TYPE, MicrosoftGraphAuthzRealm::new);
24+
}
25+
26+
@Override
27+
public List<Setting<?>> getSettings() {
28+
return MicrosoftGraphAuthzRealmSettings.getSettings();
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.plugin.security.authz;
11+
12+
import org.elasticsearch.action.ActionListener;
13+
import org.elasticsearch.common.util.concurrent.ThreadContext;
14+
import org.elasticsearch.logging.LogManager;
15+
import org.elasticsearch.logging.Logger;
16+
import org.elasticsearch.xpack.core.security.authc.AuthenticationResult;
17+
import org.elasticsearch.xpack.core.security.authc.AuthenticationToken;
18+
import org.elasticsearch.xpack.core.security.authc.Realm;
19+
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
20+
import org.elasticsearch.xpack.core.security.user.User;
21+
22+
public class MicrosoftGraphAuthzRealm extends Realm {
23+
24+
private static final Logger logger = LogManager.getLogger(MicrosoftGraphAuthzRealm.class);
25+
26+
public MicrosoftGraphAuthzRealm(RealmConfig config) {
27+
super(config);
28+
}
29+
30+
@Override
31+
public boolean supports(AuthenticationToken token) {
32+
return false;
33+
}
34+
35+
@Override
36+
public AuthenticationToken token(ThreadContext context) {
37+
return null;
38+
}
39+
40+
@Override
41+
public void authenticate(AuthenticationToken token, ActionListener<AuthenticationResult<User>> listener) {
42+
listener.onResponse(AuthenticationResult.notHandled());
43+
}
44+
45+
@Override
46+
public void lookupUser(String username, ActionListener<User> listener) {
47+
logger.info("Looking up user... Not yet implemented so no roles resolved");
48+
listener.onResponse(new User(username));
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.plugin.security.authz;
11+
12+
import org.elasticsearch.common.settings.Setting;
13+
import org.elasticsearch.xpack.core.security.authc.RealmSettings;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class MicrosoftGraphAuthzRealmSettings {
19+
public static final String REALM_TYPE = "microsoft_graph";
20+
21+
public static List<Setting<?>> getSettings() {
22+
return new ArrayList<>(RealmSettings.getStandardSettings(REALM_TYPE));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.elasticsearch.plugin.security.authz.MicrosoftGraphAuthzPlugin

0 commit comments

Comments
 (0)