2022-05-25 18:56:42 +02:00
|
|
|
package org.gcube.smartgears.security.defaults;
|
|
|
|
|
2024-02-17 01:24:03 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2022-07-26 15:46:43 +02:00
|
|
|
import org.gcube.common.security.credentials.Credentials;
|
2024-02-17 01:24:03 +01:00
|
|
|
import org.gcube.common.validator.ValidationError;
|
|
|
|
import org.gcube.common.validator.ValidatorFactory;
|
2022-06-22 18:50:54 +02:00
|
|
|
import org.gcube.common.validator.annotations.NotEmpty;
|
2022-05-25 18:56:42 +02:00
|
|
|
import org.gcube.smartgears.security.AuthorizationProviderFactory;
|
|
|
|
import org.gcube.smartgears.security.SimpleCredentials;
|
|
|
|
|
|
|
|
public class DefaultAuthorizationProviderFactory implements AuthorizationProviderFactory<DefaultAuthorizationProvider>{
|
|
|
|
|
2022-06-22 18:50:54 +02:00
|
|
|
@NotEmpty
|
|
|
|
private String endpoint;
|
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
@Override
|
2022-06-22 18:50:54 +02:00
|
|
|
public DefaultAuthorizationProvider connect(Credentials credentials) {
|
2022-05-25 18:56:42 +02:00
|
|
|
if (!SimpleCredentials.class.isInstance(credentials))
|
|
|
|
throw new IllegalArgumentException("invalid credential type passed");
|
2024-02-17 01:24:03 +01:00
|
|
|
List<ValidationError> errors = ValidatorFactory.validator().validate(credentials);
|
|
|
|
if (!errors.isEmpty())
|
|
|
|
throw new IllegalArgumentException(String.format("invalid credential: %s", errors));
|
2022-06-22 18:50:54 +02:00
|
|
|
if (this.endpoint == null || this.endpoint.isEmpty())
|
|
|
|
throw new IllegalArgumentException("invalid enpoint passed");
|
|
|
|
return new DefaultAuthorizationProvider((SimpleCredentials)credentials, this.endpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "DefaultAuthorizationProviderFactory [endpoint=" + endpoint + "]";
|
2022-05-25 18:56:42 +02:00
|
|
|
}
|
|
|
|
|
2022-06-22 18:50:54 +02:00
|
|
|
public String getEndpoint() {
|
|
|
|
return endpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEndpoint(String endpoint) {
|
|
|
|
this.endpoint = endpoint;
|
|
|
|
}
|
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
|
|
|
|
}
|