Skip to content

Commit

Permalink
move authenticate into plugin level
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <[email protected]>
  • Loading branch information
stephen-crawford committed Oct 13, 2023
1 parent 6b57759 commit eace8a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.shiro.mgt.SecurityManager;
import org.opensearch.common.settings.Settings;
import org.opensearch.identity.Subject;
import org.opensearch.identity.tokens.AuthToken;
import org.opensearch.identity.tokens.TokenManager;
import org.opensearch.plugins.IdentityPlugin;
import org.opensearch.plugins.Plugin;
Expand Down Expand Up @@ -61,4 +62,12 @@ public Subject getSubject() {
public TokenManager getTokenManager() {
return this.authTokenHandler;
}

/**
* passthrough for test module
* @param subject
* @param authToken
*/
@Override
public void authenticate(Subject subject, AuthToken authToken) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opensearch.OpenSearchException;
import org.opensearch.common.settings.Settings;
import org.opensearch.identity.noop.NoopIdentityPlugin;
import org.opensearch.identity.tokens.AuthToken;
import org.opensearch.identity.tokens.TokenManager;
import org.opensearch.plugins.IdentityPlugin;

Expand Down Expand Up @@ -57,4 +58,11 @@ public Subject getSubject() {
public TokenManager getTokenManager() {
return identityPlugin.getTokenManager();
}

/**
* Attempts to authenticate the provided subject using the provided token
*/
public void authenticate(Subject subject, AuthToken token) {
identityPlugin.authenticate(subject, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.identity.noop;

import org.opensearch.identity.Subject;
import org.opensearch.identity.tokens.AuthToken;
import org.opensearch.identity.tokens.TokenManager;
import org.opensearch.plugins.IdentityPlugin;

Expand Down Expand Up @@ -38,4 +39,9 @@ public Subject getSubject() {
public TokenManager getTokenManager() {
return new NoopTokenManager();
}

@Override
public void authenticate(Subject subject, AuthToken authToken) {
// Do nothing since noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.plugins;

import org.opensearch.identity.Subject;
import org.opensearch.identity.tokens.AuthToken;
import org.opensearch.identity.tokens.TokenManager;

/**
Expand All @@ -29,4 +30,9 @@ public interface IdentityPlugin {
* @return Should never return null.
*/
public TokenManager getTokenManager();

/**
* Attempt to authenticate the provided subject using the provided authToken
*/
public void authenticate(Subject subject, AuthToken authToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ private boolean handleAuthenticateUser(final RestRequest request, final RestChan
return true;
}
final Subject currentSubject = identityService.getSubject();
currentSubject.authenticate(token);
identityService.authenticate(currentSubject, token);
logger.debug("Logged in as user " + currentSubject);
} catch (final Exception e) {
try {
Expand Down

0 comments on commit eace8a3

Please sign in to comment.