Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Fix authentication creation in example project #86385

Merged
merged 3 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void testAuthorizeRunAs() {
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
// unauthorized
{
Authentication authentication =
new Authentication(new User("joe", new String[]{"custom_superuser"}, new User("bar", "not_superuser")),
new RealmRef("test", "test", "node"), new RealmRef("test", "test", "node"));
Authentication authentication = Authentication
.newRealmAuthentication(new User("bar", "not_superuser"), new RealmRef("test", "test", "node"))
.runAs(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

RequestInfo info = new RequestInfo(authentication, request, action, null);
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
engine.resolveAuthorizationInfo(info, future);
Expand All @@ -69,9 +69,9 @@ public void testAuthorizeRunAs() {

// authorized
{
Authentication authentication =
new Authentication(new User("joe", new String[]{"not_superuser"}, new User("bar", "custom_superuser")),
new RealmRef("test", "test", "node"), new RealmRef("test", "test", "node"));
Authentication authentication = Authentication
.newRealmAuthentication(new User("bar", "custom_superuser"), new RealmRef("test", "test", "node"))
.runAs(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"));
RequestInfo info = new RequestInfo(authentication, request, action, null);
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
engine.resolveAuthorizationInfo(info, future);
Expand Down Expand Up @@ -103,7 +103,8 @@ public void testAuthorizeClusterAction() {
// unauthorized
{
RequestInfo unauthReqInfo =
new RequestInfo(new Authentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"), null),
new RequestInfo(
Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")),
requestInfo.getRequest(), requestInfo.getAction(), null);
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
engine.resolveAuthorizationInfo(unauthReqInfo, future);
Expand All @@ -128,7 +129,8 @@ public void testAuthorizeIndexAction() {
// authorized
{
RequestInfo requestInfo =
new RequestInfo(new Authentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"), null),
new RequestInfo(
Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")),
new SearchRequest(), "indices:data/read/search", null);
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
engine.resolveAuthorizationInfo(requestInfo, future);
Expand All @@ -149,7 +151,8 @@ public void testAuthorizeIndexAction() {
// unauthorized
{
RequestInfo requestInfo =
new RequestInfo(new Authentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"), null),
new RequestInfo(
Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")),
new SearchRequest(), "indices:data/read/search", null);
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
engine.resolveAuthorizationInfo(requestInfo, future);
Expand All @@ -171,7 +174,7 @@ private RequestInfo getRequestInfo() {
final String action = "cluster:monitor/foo";
final TransportRequest request = new TransportRequest() {};
final Authentication authentication =
new Authentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"), null);
Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"));
return new RequestInfo(authentication, request, action, null);
}
}
6 changes: 1 addition & 5 deletions plugins/examples/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ plugins {
}

// Include all subdirectories as example projects
rootDir.listFiles().findAll { it.directory && new File(it, 'build.gradle').exists() }
// filter out failing project till https://github.com/elastic/elasticsearch/issues/86378
// is addressed
.findAll {projectDir -> (projectDir.name == 'security-authorization-engine') == false }
.each { subDir ->
rootDir.listFiles().findAll { it.directory && new File(it, 'build.gradle').exists() }.each { subDir ->
include ":${subDir.name}"
}

Expand Down