argos/dmp-backend/src/main/java/eu/eudat/security/validators/TokenValidatorFactoryImpl.java

81 lines
3.0 KiB
Java

package eu.eudat.security.validators;
import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
import eu.eudat.security.validators.facebook.FacebookTokenValidator;
import eu.eudat.security.validators.google.GoogleTokenValidator;
import eu.eudat.security.validators.linkedin.LinkedInTokenValidator;
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("tokenValidatorFactory")
public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
public enum LoginProvider {
GOOGLE((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4), NATIVELOGIN((short) 5), B2_ACCESS((short) 6);
private short value;
private LoginProvider(short value) {
this.value = value;
}
public short getValue() {
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;
case 5:
return NATIVELOGIN;
case 6:
return B2_ACCESS;
default:
throw new RuntimeException("Unsupported LoginProvider");
}
}
}
private GoogleTokenValidator googleTokenValidator;
private FacebookTokenValidator facebookTokenValidator;
private LinkedInTokenValidator linkedInTokenValidator;
private TwitterTokenValidator twitterTokenValidator;
private B2AccessTokenValidator b2AccessTokenValidator;
@Autowired
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator,
LinkedInTokenValidator linkedInTokenValidator, TwitterTokenValidator twitterTokenValidator,B2AccessTokenValidator b2AccessTokenValidator) {
this.googleTokenValidator = googleTokenValidator;
this.facebookTokenValidator = facebookTokenValidator;
this.linkedInTokenValidator = linkedInTokenValidator;
this.twitterTokenValidator = twitterTokenValidator;
this.b2AccessTokenValidator = b2AccessTokenValidator;
}
public TokenValidator getProvider(LoginProvider provider) {
switch (provider) {
case GOOGLE:
return this.googleTokenValidator;
case FACEBOOK:
return this.facebookTokenValidator;
case LINKEDIN:
return this.linkedInTokenValidator;
case TWITTER:
return this.twitterTokenValidator;
case B2_ACCESS:
return this.b2AccessTokenValidator;
default:
throw new RuntimeException("Login Provider Not Implemented");
}
}
}