2021-08-20 10:58:07 -07:00
|
|
|
package auth.sso;
|
2021-08-20 07:42:18 -07:00
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2023-12-06 11:02:42 +05:30
|
|
|
/** Singleton class that stores & serves reference to a single {@link SsoProvider} if one exists. */
|
2021-08-20 07:42:18 -07:00
|
|
|
public class SsoManager {
|
|
|
|
|
|
|
|
private SsoProvider<?> _provider; // Only one active provider at a time.
|
|
|
|
|
2023-12-06 11:02:42 +05:30
|
|
|
public SsoManager() {}
|
2021-08-20 07:42:18 -07:00
|
|
|
|
|
|
|
/**
|
2023-12-06 11:02:42 +05:30
|
|
|
* Returns true if SSO is enabled, meaning a non-null {@link SsoProvider} has been provided to the
|
|
|
|
* manager.
|
2021-08-20 07:42:18 -07:00
|
|
|
*
|
|
|
|
* @return true if SSO logic is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isSsoEnabled() {
|
|
|
|
return _provider != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets or replace a SsoProvider.
|
|
|
|
*
|
|
|
|
* @param provider the new {@link SsoProvider} to be used during authentication.
|
|
|
|
*/
|
|
|
|
public void setSsoProvider(@Nonnull final SsoProvider<?> provider) {
|
|
|
|
_provider = provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the active {@link SsoProvider} instance.
|
|
|
|
*
|
2023-12-06 11:02:42 +05:30
|
|
|
* @return the {@SsoProvider} that should be used during authentication and on IdP callback, or
|
|
|
|
* null if SSO is not enabled.
|
2021-08-20 07:42:18 -07:00
|
|
|
*/
|
|
|
|
public SsoProvider<?> getSsoProvider() {
|
|
|
|
return _provider;
|
|
|
|
}
|
|
|
|
}
|