Skip to content

Commit

Permalink
Make embedded OAuth authentication model default for both singe and m…
Browse files Browse the repository at this point in the history
…ultiuser che

Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
  • Loading branch information
skabashnyuk committed Jan 25, 2020
1 parent 80df9d9 commit 0e494a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ che.keycloak.username_claim=NULL
# If set to "embedded", then the service work as a wrapper to Che's OAuthAuthenticator ( as in Single User mode).
# If set to "delegated", then the service will use Keycloak IdentityProvider mechanism.
# Runtime Exception wii be thrown, in case if this property is not set properly.
che.oauth.service_mode=delegated
che.oauth.service_mode=embedded
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,41 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.multiuser.keycloak.server.oauth2.DelegatedOAuthAPI;
import org.eclipse.che.security.oauth.EmbeddedOAuthAPI;
import org.eclipse.che.security.oauth.OAuthAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides appropriate OAuth Authentication API depending on configuration.
*
* @author Mykhailo Kuznietsov.
* @author Sergii Kabashniuk.
*/
@Singleton
public class OAuthAPIProvider implements Provider<OAuthAPI> {
private static final Logger LOG = LoggerFactory.getLogger(OAuthAPIProvider.class);
private String oauthType;
private Injector injector;
private final OAuthAPI oAuthAPI;

@Inject
public OAuthAPIProvider(
@Nullable @Named("che.oauth.service_mode") String oauthType, Injector injector) {
this.oauthType = oauthType;
this.injector = injector;
}

@Override
public OAuthAPI get() {
switch (oauthType) {
case "embedded":
return injector.getInstance(EmbeddedOAuthAPI.class);
oAuthAPI = injector.getInstance(EmbeddedOAuthAPI.class);
break;
case "delegated":
return injector.getInstance(DelegatedOAuthAPI.class);
oAuthAPI = injector.getInstance(DelegatedOAuthAPI.class);
break;
default:
throw new RuntimeException(
"Unknown value configured for \"che.oauth.service_mode\", must be either \"embedded\", or \"delegated\"");
}
}

@Override
public OAuthAPI get() {
return oAuthAPI;
}
}

0 comments on commit 0e494a6

Please sign in to comment.