Commit 663399b2 authored by fabio martelli's avatar fabio martelli

Some fixes processing CRV-3

parent a0bfa404
......@@ -27,6 +27,10 @@ public class FederationServerConfiguration extends AbstractConfiguration {
private String domain;
private String principal;
private String password;
@ConfigurationProperty(displayMessageKey = "baseAddress.display", helpMessageKey = "baseAddress.help", order = 1)
public String getBaseAddress() {
return baseAddress;
......@@ -36,7 +40,8 @@ public class FederationServerConfiguration extends AbstractConfiguration {
this.baseAddress = baseAddress;
}
@ConfigurationProperty(displayMessageKey = "domain.display", helpMessageKey = "domain.help", order = 2)
@ConfigurationProperty(displayMessageKey = "domain.display", helpMessageKey = "domain.help", order = 2,
required = true)
public String getDomain() {
return domain;
}
......@@ -45,6 +50,25 @@ public class FederationServerConfiguration extends AbstractConfiguration {
this.domain = domain;
}
@ConfigurationProperty(displayMessageKey = "principal.display", helpMessageKey = "principal.help", order = 3)
public String getPrincipal() {
return principal;
}
public void setPrincipal(final String principal) {
this.principal = principal;
}
@ConfigurationProperty(displayMessageKey = "password.display", helpMessageKey = "password.help", order = 4,
confidential = true)
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password;
}
@Override
public void validate() {
if (StringUtil.isBlank(baseAddress)) {
......@@ -57,6 +81,10 @@ public class FederationServerConfiguration extends AbstractConfiguration {
if (StringUtil.isBlank(domain)) {
throw new ConfigurationException("domain must not be blank!");
}
if (StringUtil.isBlank(principal)) {
throw new ConfigurationException("principal must not be blank!");
}
}
}
......@@ -22,7 +22,9 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.identityconnectors.common.StringUtil;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.framework.common.objects.Attribute;
......@@ -88,8 +90,16 @@ public class FederationServerConnector implements Connector,
private FederationServerEndUserService getClient() {
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
return JAXRSClientFactory.create(
getConfiguration().getBaseAddress(), FederationServerEndUserService.class, providers);
FederationServerEndUserService client = JAXRSClientFactory.create(
getConfiguration().getBaseAddress(),
FederationServerEndUserService.class,
providers,
configuration.getPrincipal(),
configuration.getPassword(),
null);
WebClient.client(client).accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE);
return client;
}
private EndUser getEndUser(final String username, final Set<Attribute> attrs) {
......@@ -100,9 +110,7 @@ public class FederationServerConnector implements Connector,
if (attr.getName().equals(OperationalAttributes.PASSWORD_NAME)) {
if (attr.getValue() != null && !attr.getValue().isEmpty()) {
StringBuilder clearPwd = new StringBuilder();
AttributeUtil.getGuardedStringValue(attr).access(clearPwd::append);
endUser.setPassword(clearPwd.toString());
}
} else if (attr.getName().equals(OperationalAttributes.ENABLE_NAME)) {
......@@ -115,6 +123,12 @@ public class FederationServerConnector implements Connector,
endUser.getGroups().add(value.toString());
});
}
} else if (attr.getName().equals(FederationServerConstants.CHOREOGRAPHIES_NAME)) {
if (attr.getValue() != null) {
attr.getValue().stream().forEach((value) -> {
endUser.getChoreographies().add(value.toString());
});
}
} else if (!attr.getName().equals(Uid.NAME) && !attr.getName().equals(Name.NAME)) {
Set<String> values = new HashSet<>();
if (attr.getValue() != null) {
......@@ -185,6 +199,7 @@ public class FederationServerConnector implements Connector,
public Schema schema() {
Set<AttributeInfo> attrInfo = new HashSet<>();
attrInfo.add(AttributeInfoBuilder.build(FederationServerConstants.GROUPS_NAME, String.class));
attrInfo.add(AttributeInfoBuilder.build(FederationServerConstants.CHOREOGRAPHIES_NAME, String.class));
SchemaBuilder schemaBuilder = new SchemaBuilder(FederationServerConnector.class);
schemaBuilder.defineObjectClass(ObjectClass.ACCOUNT.getObjectClassValue(), attrInfo);
......@@ -224,6 +239,7 @@ public class FederationServerConnector implements Connector,
attrs.add(AttributeBuilder.buildEnabled(endUser.isActive()));
attrs.add(AttributeBuilder.build(FederationServerConstants.GROUPS_NAME, endUser.getGroups()));
attrs.add(AttributeBuilder.build(FederationServerConstants.CHOREOGRAPHIES_NAME, endUser.getChoreographies()));
endUser.getAttributes().entrySet().stream().forEach((entry) -> {
attrs.add(AttributeBuilder.build(entry.getKey(), entry.getValue()));
......
......@@ -19,6 +19,8 @@ public final class FederationServerConstants {
public static final String GROUPS_NAME = "__GROUPS__";
public static final String CHOREOGRAPHIES_NAME = "__CHOREOGRAPHIES__";
private FederationServerConstants() {
// private constructor for static utility class
}
......
......@@ -33,6 +33,8 @@ public class EndUser implements Serializable {
private final Set<String> groups = new HashSet<>();
private final Set<String> choreographies = new HashSet<>();
private final Map<String, Set<String>> attributes = new HashMap<>();
public String getUsername() {
......@@ -63,6 +65,10 @@ public class EndUser implements Serializable {
return groups;
}
public Set<String> getChoreographies() {
return choreographies;
}
public Map<String, Set<String>> getAttributes() {
return attributes;
}
......
......@@ -19,3 +19,7 @@ baseAddress.display=Base Federation Server address
baseAddress.help=Base URI where the Federation Server exposes its end-user REST endpoint. If service is published at 'http://host:port/domains/domain1/endusers', then this property expected value is 'http://host:port'
domain.display=Federation Server domain
domain.help=Federation Server domain (for multi-tenancy environment)
principal.display=Principal
principal.help=Provide credential to access services
password.display=Password
password.help=Provide credential to access services
......@@ -19,3 +19,7 @@ baseAddress.display=Indirizzo di base per il Federation Server
baseAddress.help=URI di base su cui il Federation Server pubblica il servizio REST per la gestione degli end-user. Se il servizio \u00e8 raggiungibile all'indirizzo 'http://host:port/domains/domain1/endusers', allora il valore atteso di questa propriet\u00e0 \u00e8 'http://host:port'
domain.display=Dominio Federation Server
domain.help=Dominio Federation Server (per ambienti multi-tenancy)
principal.display=Principal
principal.help=Fornire le credenziali di accesso ai servizi
password.display=Password
password.help=Fornire le credenziali di accesso ai servizi
......@@ -68,19 +68,22 @@ public class ConnectorTests extends AbstractTests {
ObjectClassInfo ocinfo = schema.getObjectClassInfo().iterator().next();
assertEquals(ObjectClass.ACCOUNT_NAME, ocinfo.getType());
assertEquals(2, ocinfo.getAttributeInfo().size());
assertEquals(3, ocinfo.getAttributeInfo().size());
int counter = 0;
for (AttributeInfo attrinfo : ocinfo.getAttributeInfo()) {
if (FederationServerConstants.GROUPS_NAME.equals(attrinfo.getName())) {
assertEquals(String.class, attrinfo.getType());
counter++;
} else if (FederationServerConstants.CHOREOGRAPHIES_NAME.equals(attrinfo.getName())) {
assertEquals(String.class, attrinfo.getType());
counter++;
} else if (Name.NAME.equals(attrinfo.getName())) {
assertTrue(attrinfo.isRequired());
counter++;
}
}
assertEquals(2, counter);
assertEquals(3, counter);
}
@Test
......@@ -131,6 +134,7 @@ public class ConnectorTests extends AbstractTests {
attrs.add(AttributeBuilder.buildPassword(uuid.toCharArray()));
attrs.add(AttributeBuilder.buildEnabled(true));
attrs.add(AttributeBuilder.build(FederationServerConstants.GROUPS_NAME, CollectionUtil.newSet("group1")));
attrs.add(AttributeBuilder.build(FederationServerConstants.CHOREOGRAPHIES_NAME, CollectionUtil.newSet()));
attrs.add(AttributeBuilder.build("attrX", CollectionUtil.newSet("valueX")));
attrs.add(AttributeBuilder.build("attrY", CollectionUtil.newSet("valueX", "valueY")));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment