Skip to content

Commit

Permalink
[spi] Creating IThirdEyePrincipal interface for auth. +refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
suvodeep-pyne committed Nov 8, 2023
1 parent 12578ed commit b08e39e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;

import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.auth.oauth.OAuthConfiguration;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.auth.Authenticator.OauthAuthenticatorFactory;
import ai.startree.thirdeye.spi.auth.OpenIdConfigurationProvider;
import ai.startree.thirdeye.spi.auth.OpenIdConfigurationProvider.Factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import static ai.startree.thirdeye.spi.util.SpiUtils.optional;

import ai.startree.thirdeye.alert.AlertTemplateRenderer;
import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.datalayer.dao.SubEntities;
import ai.startree.thirdeye.spi.auth.AccessControl;
import ai.startree.thirdeye.spi.auth.AccessType;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.auth.ResourceIdentifier;
import ai.startree.thirdeye.spi.datalayer.dto.AbstractDTO;
import ai.startree.thirdeye.spi.datalayer.dto.AlertDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static ai.startree.thirdeye.spi.util.SpiUtils.optional;

import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import io.dropwizard.auth.Authenticator;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
*/
package ai.startree.thirdeye.auth;

import java.security.Principal;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.auth.IThirdEyePrincipal;

public class ThirdEyePrincipal implements Principal {

public enum AuthenticationType {
BASIC_AUTH, OAUTH, INTERNAL, DISABLED
}
public class ThirdEyePrincipal implements IThirdEyePrincipal {

private final String name;
private final String authToken;
private final AuthenticationType authenticationType;

public ThirdEyePrincipal(final String name, final String authToken, final AuthenticationType authenticationType) {
public ThirdEyePrincipal(final String name,
final String authToken,
final AuthenticationType authenticationType) {
this.name = name;
this.authToken = authToken;
this.authenticationType = authenticationType;
Expand All @@ -36,10 +35,12 @@ public String getName() {
return name;
}

@Override
public String getAuthToken() {
return authToken;
}

@Override
public AuthenticationType getAuthenticationType() {
return authenticationType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package ai.startree.thirdeye.auth.basic;

import ai.startree.thirdeye.auth.ThirdEyePrincipal;
import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import com.google.inject.Inject;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import ai.startree.thirdeye.auth.AuthorizationManager;
import ai.startree.thirdeye.auth.NamespaceResolver;
import ai.startree.thirdeye.auth.ThirdEyePrincipal;
import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.service.AlertService;
import ai.startree.thirdeye.service.AppAnalyticsService;
import ai.startree.thirdeye.spi.api.AlertApi;
Expand All @@ -39,6 +38,7 @@
import ai.startree.thirdeye.spi.api.PlanNodeApi;
import ai.startree.thirdeye.spi.auth.AccessControl;
import ai.startree.thirdeye.spi.auth.AccessType;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.auth.ResourceIdentifier;
import ai.startree.thirdeye.spi.datalayer.bao.AlertManager;
import ai.startree.thirdeye.spi.datalayer.bao.AlertTemplateManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import ai.startree.thirdeye.auth.AuthorizationManager;
import ai.startree.thirdeye.auth.NamespaceResolver;
import ai.startree.thirdeye.auth.ThirdEyePrincipal;
import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.datalayer.bao.AbstractManagerImpl;
import ai.startree.thirdeye.datalayer.dao.GenericPojoDao;
import ai.startree.thirdeye.service.CrudService;
import ai.startree.thirdeye.spi.api.ThirdEyeCrudApi;
import ai.startree.thirdeye.spi.auth.AccessControl;
import ai.startree.thirdeye.spi.auth.AccessType;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.auth.ResourceIdentifier;
import ai.startree.thirdeye.spi.datalayer.bao.AbstractManager;
import ai.startree.thirdeye.spi.datalayer.dto.AbstractDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import ai.startree.thirdeye.auth.AuthorizationManager;
import ai.startree.thirdeye.auth.NamespaceResolver;
import ai.startree.thirdeye.auth.ThirdEyePrincipal;
import ai.startree.thirdeye.auth.ThirdEyePrincipal.AuthenticationType;
import ai.startree.thirdeye.core.DataSourceOnboarder;
import ai.startree.thirdeye.datasource.cache.DataSourceCache;
import ai.startree.thirdeye.service.DataSourceService;
import ai.startree.thirdeye.spi.ThirdEyeStatus;
import ai.startree.thirdeye.spi.api.StatusApi;
import ai.startree.thirdeye.spi.api.StatusListApi;
import ai.startree.thirdeye.spi.auth.AuthenticationType;
import ai.startree.thirdeye.spi.datalayer.bao.DataSourceManager;
import ai.startree.thirdeye.spi.datasource.ThirdEyeDataSource;
import javax.ws.rs.core.Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ai.startree.thirdeye.spi.auth;

public enum AuthenticationType {
BASIC_AUTH, OAUTH, INTERNAL, DISABLED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ai.startree.thirdeye.spi.auth;

import java.security.Principal;

public interface IThirdEyePrincipal extends Principal {

@Override
String getName();

String getAuthToken();

AuthenticationType getAuthenticationType();
}

0 comments on commit b08e39e

Please sign in to comment.