update for 4.0.0
This commit is contained in:
parent
454533abcd
commit
9947bfbc7d
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<smartgears version="${project.version}"/>
|
5
pom.xml
5
pom.xml
|
@ -57,6 +57,11 @@
|
|||
</dependency>
|
||||
<!-- END gCube Jackson -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>keycloak-client</artifactId>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
|
|
|
@ -28,7 +28,7 @@ public class Constants {
|
|||
/**
|
||||
* The container configuration file path, relative to the container configuration directory.
|
||||
*/
|
||||
public static final String container_configuraton_file_path = "smartgears-node.ini";
|
||||
public static final String container_configuraton_file_path = "container.ini";
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,14 +3,18 @@ package org.gcube.smartgears.configuration.library;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.validator.ValidationError;
|
||||
import org.gcube.common.validator.Validator;
|
||||
import org.gcube.common.validator.ValidatorFactory;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
|
||||
@XmlRootElement(name="smartgears")
|
||||
public class SmartGearsConfiguration {
|
||||
|
||||
@NotEmpty
|
||||
@XmlAttribute @NotEmpty
|
||||
private String version;
|
||||
|
||||
public SmartGearsConfiguration(){
|
||||
|
|
|
@ -349,13 +349,18 @@ public class DefaultProvider implements Provider {
|
|||
|
||||
try {
|
||||
|
||||
SmartGearsConfiguration configuration = new SmartGearsConfiguration();
|
||||
configuration.version(System.getProperty("projectVersion"));
|
||||
|
||||
InputStream config = getClass().getResourceAsStream(library_configuration_file_path);
|
||||
|
||||
if (config == null)
|
||||
throw new IllegalStateException("invalid distribution: cannot find " + library_configuration_file_path);
|
||||
|
||||
SmartGearsConfigurationBinder binder = new SmartGearsConfigurationBinder();
|
||||
|
||||
SmartGearsConfiguration configuration = binder.bind(config);
|
||||
|
||||
configuration.validate();
|
||||
|
||||
return configuration;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
throw new RuntimeException("cannot read library configuration (see cause) ", e);
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
package org.gcube.smartgears.security;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.keycloak.KeycloakClient;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.model.AccessToken.Access;
|
||||
import org.gcube.common.keycloak.model.ModelUtils;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DefaultAuthorizationProvider implements AuthorizationProvider {
|
||||
|
||||
SimpleCredentials credentials;
|
||||
private static Logger LOG = LoggerFactory.getLogger(DefaultAuthorizationProvider.class);
|
||||
|
||||
private SimpleCredentials credentials;
|
||||
|
||||
private KeycloakClient client = KeycloakClientFactory.newInstance();
|
||||
|
||||
@Override
|
||||
public void connect(Credentials credentials) {
|
||||
|
@ -13,7 +29,23 @@ public class DefaultAuthorizationProvider implements AuthorizationProvider {
|
|||
|
||||
@Override
|
||||
public Set<String> getAllowedContexts() {
|
||||
return null;
|
||||
Set<String> contexts = new HashSet<String>();
|
||||
try {
|
||||
TokenResponse response = client.queryOIDCToken(credentials.getClientID(), credentials.getSecret());
|
||||
Map<String, Access> resourceAccess = ModelUtils.getAccessTokenFrom(response).getResourceAccess();
|
||||
for (String context : resourceAccess.keySet()) {
|
||||
try {
|
||||
ScopeBean scope = new ScopeBean(context.replaceAll("%2F", "/"));
|
||||
contexts.add(scope.toString());
|
||||
}catch (IllegalArgumentException e) {
|
||||
LOG.warn("invalid context found in token: {}", context);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("error getting OIDToken from keycloak",e);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue