2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.logic.security.validators;
|
2018-01-09 12:31:01 +01:00
|
|
|
|
2019-11-13 16:32:55 +01:00
|
|
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
2019-07-12 15:58:17 +02:00
|
|
|
import eu.eudat.logic.security.customproviders.B2Access.B2AccessCustomProvider;
|
2019-11-13 16:32:55 +01:00
|
|
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.ConfigurableProviderCustomProvider;
|
2019-09-30 09:27:42 +02:00
|
|
|
import eu.eudat.logic.security.customproviders.LinkedIn.LinkedInCustomProvider;
|
2019-07-12 15:58:17 +02:00
|
|
|
import eu.eudat.logic.security.customproviders.ORCID.ORCIDCustomProvider;
|
2019-10-23 12:38:27 +02:00
|
|
|
import eu.eudat.logic.security.customproviders.OpenAIRE.OpenAIRECustomProvider;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.security.validators.b2access.B2AccessTokenValidator;
|
2019-11-13 16:32:55 +01:00
|
|
|
import eu.eudat.logic.security.validators.configurableProvider.ConfigurableProviderTokenValidator;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.security.validators.facebook.FacebookTokenValidator;
|
|
|
|
import eu.eudat.logic.security.validators.google.GoogleTokenValidator;
|
|
|
|
import eu.eudat.logic.security.validators.linkedin.LinkedInTokenValidator;
|
2019-10-23 12:38:27 +02:00
|
|
|
import eu.eudat.logic.security.validators.openaire.OpenAIRETokenValidator;
|
2019-07-12 15:58:17 +02:00
|
|
|
import eu.eudat.logic.security.validators.orcid.ORCIDTokenValidator;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.security.validators.twitter.TwitterTokenValidator;
|
2019-07-12 15:58:17 +02:00
|
|
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
2018-01-09 12:31:01 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-08-30 13:09:36 +02:00
|
|
|
import org.springframework.core.env.Environment;
|
2018-01-09 12:31:01 +01:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
2018-02-01 10:08:06 +01:00
|
|
|
|
2018-01-09 12:31:01 +01:00
|
|
|
@Service("tokenValidatorFactory")
|
2018-02-16 11:34:02 +01:00
|
|
|
public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
2018-01-09 12:31:01 +01:00
|
|
|
public enum LoginProvider {
|
2019-11-13 16:32:55 +01:00
|
|
|
GOOGLE(1), FACEBOOK(2), TWITTER(3), LINKEDIN(4), NATIVELOGIN(5), B2_ACCESS(6), ORCID(7), OPENAIRE(8), CONFIGURABLE(9);
|
2018-01-09 12:31:01 +01:00
|
|
|
|
2018-03-21 11:57:56 +01:00
|
|
|
private int value;
|
2018-01-09 12:31:01 +01:00
|
|
|
|
2018-03-21 11:57:56 +01:00
|
|
|
private LoginProvider(int value) {
|
2018-01-09 12:31:01 +01:00
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2018-03-21 11:57:56 +01:00
|
|
|
public int getValue() {
|
2018-01-09 12:31:01 +01:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static LoginProvider fromInteger(int value) {
|
|
|
|
switch (value) {
|
|
|
|
case 1:
|
|
|
|
return GOOGLE;
|
|
|
|
case 2:
|
|
|
|
return FACEBOOK;
|
|
|
|
case 3:
|
|
|
|
return TWITTER;
|
|
|
|
case 4:
|
|
|
|
return LINKEDIN;
|
2018-01-31 16:39:16 +01:00
|
|
|
case 5:
|
|
|
|
return NATIVELOGIN;
|
2018-02-23 11:36:51 +01:00
|
|
|
case 6:
|
|
|
|
return B2_ACCESS;
|
2019-07-12 15:58:17 +02:00
|
|
|
case 7:
|
|
|
|
return ORCID;
|
2019-10-23 12:38:27 +02:00
|
|
|
case 8:
|
|
|
|
return OPENAIRE;
|
2019-11-13 16:32:55 +01:00
|
|
|
case 9:
|
|
|
|
return CONFIGURABLE;
|
2018-01-09 12:31:01 +01:00
|
|
|
default:
|
|
|
|
throw new RuntimeException("Unsupported LoginProvider");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 13:09:36 +02:00
|
|
|
private Environment environment;
|
2019-07-12 15:58:17 +02:00
|
|
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
2018-08-30 13:09:36 +02:00
|
|
|
private B2AccessCustomProvider b2AccessCustomProvider;
|
2019-07-12 15:58:17 +02:00
|
|
|
private ORCIDCustomProvider orcidCustomProvider;
|
2019-09-30 09:27:42 +02:00
|
|
|
private LinkedInCustomProvider linkedInCustomProvider;
|
2019-10-23 12:38:27 +02:00
|
|
|
private OpenAIRECustomProvider openAIRECustomProvider;
|
2019-11-13 16:32:55 +01:00
|
|
|
private ConfigurableProviderCustomProvider configurableProviderCustomProvider;
|
|
|
|
private ConfigLoader configLoader;
|
2018-02-16 11:34:02 +01:00
|
|
|
|
2018-01-09 12:31:01 +01:00
|
|
|
@Autowired
|
2019-09-30 09:27:42 +02:00
|
|
|
public TokenValidatorFactoryImpl(
|
2019-11-11 11:34:28 +01:00
|
|
|
Environment environment,
|
2019-09-30 09:27:42 +02:00
|
|
|
AuthenticationService nonVerifiedUserAuthenticationService, B2AccessCustomProvider b2AccessCustomProvider,
|
2019-11-13 16:32:55 +01:00
|
|
|
ORCIDCustomProvider orcidCustomProvider, LinkedInCustomProvider linkedInCustomProvider, OpenAIRECustomProvider openAIRECustomProvider, ConfigurableProviderCustomProvider configurableProviderCustomProvider, ConfigLoader configLoader) {
|
2018-08-30 13:09:36 +02:00
|
|
|
this.environment = environment;
|
2019-07-12 15:58:17 +02:00
|
|
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
2018-08-30 13:09:36 +02:00
|
|
|
this.b2AccessCustomProvider = b2AccessCustomProvider;
|
2019-07-12 15:58:17 +02:00
|
|
|
this.orcidCustomProvider = orcidCustomProvider;
|
2019-09-30 09:27:42 +02:00
|
|
|
this.linkedInCustomProvider = linkedInCustomProvider;
|
2019-10-23 12:38:27 +02:00
|
|
|
this.openAIRECustomProvider = openAIRECustomProvider;
|
2019-11-13 16:32:55 +01:00
|
|
|
this.configurableProviderCustomProvider = configurableProviderCustomProvider;
|
|
|
|
this.configLoader = configLoader;
|
2018-01-09 12:31:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public TokenValidator getProvider(LoginProvider provider) {
|
|
|
|
switch (provider) {
|
|
|
|
case GOOGLE:
|
2019-11-11 11:34:28 +01:00
|
|
|
return new GoogleTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
2018-01-09 12:31:01 +01:00
|
|
|
case FACEBOOK:
|
2019-11-11 11:34:28 +01:00
|
|
|
return new FacebookTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
2018-01-10 17:05:23 +01:00
|
|
|
case LINKEDIN:
|
2019-09-30 09:27:42 +02:00
|
|
|
return new LinkedInTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, linkedInCustomProvider);
|
2018-01-11 12:13:01 +01:00
|
|
|
case TWITTER:
|
2019-11-11 11:34:28 +01:00
|
|
|
return new TwitterTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
2018-02-23 11:36:51 +01:00
|
|
|
case B2_ACCESS:
|
2019-07-12 15:58:17 +02:00
|
|
|
return new B2AccessTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.b2AccessCustomProvider);
|
|
|
|
case ORCID:
|
2019-09-30 09:27:42 +02:00
|
|
|
return new ORCIDTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.orcidCustomProvider);
|
2019-10-23 12:38:27 +02:00
|
|
|
case OPENAIRE:
|
|
|
|
return new OpenAIRETokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.openAIRECustomProvider);
|
2019-11-13 16:32:55 +01:00
|
|
|
case CONFIGURABLE:
|
|
|
|
return new ConfigurableProviderTokenValidator(this.configurableProviderCustomProvider, this.nonVerifiedUserAuthenticationService, this.configLoader);
|
2018-01-09 12:31:01 +01:00
|
|
|
default:
|
|
|
|
throw new RuntimeException("Login Provider Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|