[CRV-19] Working version

parent a2b2641f
......@@ -16,17 +16,20 @@
package eu.chorevolution.idm.connid.federationserver;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserServicePathAnnotated;
import eu.chorevolution.securitytokenservice.federationserver.api.EndUser;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.identityconnectors.common.Pair;
import org.identityconnectors.common.StringUtil;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.framework.common.objects.Attribute;
......@@ -90,15 +93,14 @@ public class FederationServerConnector implements Connector,
}
private FederationServerEndUserService getClient() {
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
FederationServerEndUserService client = JAXRSClientFactory.create(
getConfiguration().getBaseAddress(),
FederationServerEndUserService.class,
providers,
configuration.getPrincipal(),
configuration.getPassword(),
null);
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(getConfiguration().getBaseAddress());
bean.setServiceClass(FederationServerEndUserServicePathAnnotated.class);
bean.setUsername(configuration.getPrincipal());
bean.setPassword(configuration.getPassword());
bean.setProvider(new JacksonJaxbJsonProvider());
FederationServerEndUserService client =
bean.create(FederationServerEndUserServicePathAnnotated.class, configuration.getDomain());
WebClient.client(client).accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE);
return client;
......@@ -108,6 +110,8 @@ public class FederationServerConnector implements Connector,
EndUser endUser = new EndUser();
endUser.setUsername(username);
Map<String, Map.Entry<String, String>> serviceCredentials = new HashMap<>();
attrs.stream().forEach((attr) -> {
if (attr.getName().equals(OperationalAttributes.PASSWORD_NAME)) {
if (attr.getValue() != null && !attr.getValue().isEmpty()) {
......@@ -119,18 +123,36 @@ public class FederationServerConnector implements Connector,
if (attr.getValue() != null && !attr.getValue().isEmpty()) {
endUser.setActive(((Boolean) attr.getValue().get(0)));
}
} else if (attr.getName().equals(FederationServerConstants.GROUPS_NAME)) {
} else if (attr.getName().equals(FederationServerConstants.CHOREOGRAPHIES_NAME)) {
if (attr.getValue() != null) {
attr.getValue().stream().forEach((value) -> {
endUser.getGroups().add(value.toString());
endUser.getChoreographies().add(value.toString());
});
}
} else if (attr.getName().equals(FederationServerConstants.CHOREOGRAPHIES_NAME)) {
} else if (attr.getName().equals(FederationServerConstants.GROUPS_NAME)) {
if (attr.getValue() != null) {
attr.getValue().stream().forEach((value) -> {
endUser.getChoreographies().add(value.toString());
endUser.getGroups().add(value.toString());
});
}
} else if (attr.getName().contains("#")) {
if (attr.getValue() != null) {
String[] parts = attr.getName().split("#");
if (parts != null && parts.length == 2) {
Map.Entry<String, String> credentials = serviceCredentials.get(parts[0]);
if (credentials == null) {
credentials = new Pair<>();
serviceCredentials.put(parts[0], credentials);
}
if (attr.getValue() != null && !attr.getValue().isEmpty()) {
if (parts[1].equals(FederationServerConstants.SERVICE_USERNAME_SUFFIX)) {
((Pair<String, String>) credentials).first = attr.getValue().get(0).toString();
} else if (parts[1].equals(FederationServerConstants.SERVICE_PASSWORD_SUFFIX)) {
((Pair<String, String>) credentials).second = attr.getValue().get(0).toString();
}
}
}
}
} else if (!attr.getName().equals(Uid.NAME) && !attr.getName().equals(Name.NAME)) {
Set<String> values = new HashSet<>();
if (attr.getValue() != null) {
......@@ -142,6 +164,8 @@ public class FederationServerConnector implements Connector,
}
});
endUser.getServiceCredentials().putAll(serviceCredentials);
return endUser;
}
......@@ -243,6 +267,15 @@ public class FederationServerConnector implements Connector,
attrs.add(AttributeBuilder.build(FederationServerConstants.GROUPS_NAME, endUser.getGroups()));
attrs.add(AttributeBuilder.build(FederationServerConstants.CHOREOGRAPHIES_NAME, endUser.getChoreographies()));
endUser.getServiceCredentials().entrySet().stream().forEach((entry) -> {
attrs.add(AttributeBuilder.build(
entry.getKey() + "#" + FederationServerConstants.SERVICE_USERNAME_SUFFIX,
entry.getValue().getKey()));
attrs.add(AttributeBuilder.build(
entry.getKey() + "#" + FederationServerConstants.SERVICE_PASSWORD_SUFFIX,
entry.getValue().getValue()));
});
endUser.getAttributes().entrySet().stream().forEach((entry) -> {
attrs.add(AttributeBuilder.build(entry.getKey(), entry.getValue()));
});
......@@ -268,7 +301,7 @@ public class FederationServerConnector implements Connector,
});
} else {
Response response = client.read(getConfiguration().getDomain(), query.getUsername());
if (response.hasEntity()) {
if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) {
EndUser found = response.readEntity(EndUser.class);
if (found != null) {
handler.handle(getConnectorObject(found));
......
......@@ -21,6 +21,10 @@ public final class FederationServerConstants {
public static final String CHOREOGRAPHIES_NAME = "__CHOREOGRAPHIES__";
public static final String SERVICE_USERNAME_SUFFIX = "Username";
public static final String SERVICE_PASSWORD_SUFFIX = "Password";
private FederationServerConstants() {
// private constructor for static utility class
}
......
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.idm.connid.federationserver.api;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import javax.ws.rs.Path;
@Path("/domains/{domain}/endusers")
public interface FederationServerEndUserServicePathAnnotated extends FederationServerEndUserService {
}
......@@ -18,7 +18,9 @@ federationserver.connector.display=CHOReVOLUTION: Federation Server Connector
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)
domain.help=Federation Server domain (for multi-tenant environment)
aesKey.display=AES encryption key for password values
aesKey.help=AES encryption key for password values
principal.display=Principal
principal.help=Provide credential to access services
password.display=Password
......
......@@ -18,7 +18,9 @@ federationserver.connector.display=CHOReVOLUTION: Connettore Federation Server
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)
domain.help=Dominio Federation Server (per ambienti multi-tenant)
aesKey.display=Chiave di crittazione AES per le password
aesKey.help=Chiave di crittazione AES per le password
principal.display=Principal
principal.help=Fornire le credenziali di accesso ai servizi
password.display=Password
......
......@@ -19,7 +19,7 @@
package eu.chorevolution.idm.connid.federationserver;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserServicePathAnnotated;
import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.endpoint.Server;
......@@ -37,13 +37,13 @@ public abstract class AbstractTests {
@BeforeClass
public static void startServer() throws Exception {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(FederationServerEndUserService.class);
sf.setResourceClasses(FederationServerEndUserServicePathAnnotated.class);
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
sf.setProviders(providers);
sf.setResourceProvider(FederationServerEndUserService.class,
sf.setResourceProvider(FederationServerEndUserServicePathAnnotated.class,
new SingletonResourceProvider(new TestFederationServerEndUserService(), true));
sf.setAddress(BASE_ADDRESS);
......
......@@ -18,20 +18,18 @@
*/
package eu.chorevolution.idm.connid.federationserver;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserServicePathAnnotated;
import eu.chorevolution.securitytokenservice.federationserver.api.EndUser;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.Path;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;
import org.identityconnectors.common.CollectionUtil;
import org.identityconnectors.common.Pair;
@Path("/domains/{domain}/endusers")
public class TestFederationServerEndUserService implements FederationServerEndUserService {
public class TestFederationServerEndUserService implements FederationServerEndUserServicePathAnnotated {
public static final String DEFAULT_USERNAME = "test";
......@@ -48,10 +46,10 @@ public class TestFederationServerEndUserService implements FederationServerEndUs
endUser.getAttributes().put("attr1", CollectionUtil.newSet("value1", "value2"));
endUser.getAttributes().put("attr2", CollectionUtil.newSet("value3", "value4"));
Map<String, String> sc1 = Collections.singletonMap("sc1_" + DEFAULT_USERNAME, "password1");
Map.Entry<String, String> sc1 = Pair.of("sc1_" + DEFAULT_USERNAME, "password1");
endUser.getServiceCredentials().put("sc1", sc1);
Map<String, String> sc2 = Collections.singletonMap("sc2_" + DEFAULT_USERNAME, "password2");
Map.Entry<String, String> sc2 = Pair.of("sc2_" + DEFAULT_USERNAME, "password2");
endUser.getServiceCredentials().put("sc3", sc2);
this.endusers.put(endUser.getUsername(), endUser);
......
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