Removing duplicate API classes and use eu.chorevolution.sts:sts-provision-data

parent 71b35b1d
......@@ -112,6 +112,12 @@ limitations under the License.
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>eu.chorevolution.sts</groupId>
<artifactId>sts-provision-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- TEST -->
<dependency>
<groupId>org.apache.cxf</groupId>
......
......@@ -16,13 +16,15 @@
package eu.chorevolution.idm.connid.federationserver;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import eu.chorevolution.idm.connid.federationserver.api.EndUser;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserService;
import eu.chorevolution.securitytokenservice.federationserver.api.EndUser;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
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.WebClient;
import org.identityconnectors.common.StringUtil;
......@@ -223,8 +225,8 @@ public class FederationServerConnector implements Connector,
protected FederationServerFilter createEqualsExpression(final EqualsFilter filter, final boolean not) {
return filter.getAttribute() == null || filter.getAttribute().getValue() == null
|| filter.getAttribute().getValue().isEmpty()
? super.createEqualsExpression(filter, not)
: new FederationServerFilter(filter.getAttribute().getValue().get(0).toString());
? super.createEqualsExpression(filter, not)
: new FederationServerFilter(filter.getAttribute().getValue().get(0).toString());
}
};
}
......@@ -260,13 +262,17 @@ public class FederationServerConnector implements Connector,
FederationServerEndUserService client = getClient();
if (query == null || StringUtil.isBlank(query.getUsername())) {
client.list(getConfiguration().getDomain()).stream().forEach((endUser) -> {
client.list(getConfiguration().getDomain()).readEntity(new GenericType<List<EndUser>>() {
}).stream().forEach((endUser) -> {
handler.handle(getConnectorObject(endUser));
});
} else {
EndUser found = client.read(getConfiguration().getDomain(), query.getUsername());
if (found != null) {
handler.handle(getConnectorObject(found));
Response response = client.read(getConfiguration().getDomain(), query.getUsername());
if (response.hasEntity()) {
EndUser found = response.readEntity(EndUser.class);
if (found != null) {
handler.handle(getConnectorObject(found));
}
}
}
}
......
/*
* Copyright 2015 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 java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class EndUser implements Serializable {
private static final long serialVersionUID = -3901863997664130719L;
private String username;
private String password;
private boolean active = true;
private final Set<String> choreographies = new HashSet<>();
private final Set<String> groups = new HashSet<>();
private final Map<String, ServiceCredentials> serviceCredentials = new HashMap<>();
private final Map<String, Set<String>> attributes = new HashMap<>();
public String getUsername() {
return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public boolean isActive() {
return active;
}
public void setActive(final boolean active) {
this.active = active;
}
public void setPassword(final String password) {
this.password = password;
}
public Set<String> getChoreographies() {
return choreographies;
}
public Set<String> getGroups() {
return groups;
}
public Map<String, ServiceCredentials> getServiceCredentials() {
return serviceCredentials;
}
public Map<String, Set<String>> getAttributes() {
return attributes;
}
}
/*
* Copyright 2015 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 java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* REST operations for end-user management.
*/
@Path("/domains/{domain}/endusers")
public interface FederationServerEndUserService {
@GET
@Produces({ MediaType.APPLICATION_JSON })
List<EndUser> list(@PathParam("domain") String domain);
@POST
@Consumes({ MediaType.APPLICATION_JSON })
void create(@PathParam("domain") String domain, EndUser enduser);
@GET
@Path("{username}")
@Produces({ MediaType.APPLICATION_JSON })
EndUser read(@PathParam("domain") String domain, @PathParam("username") String username);
@PUT
@Path("{username}")
@Consumes({ MediaType.APPLICATION_JSON })
void update(@PathParam("domain") String domain, @PathParam("username") String username, EndUser enduser);
@DELETE
@Path("{username}")
void delete(@PathParam("domain") String domain, @PathParam("username") String username);
}
/*
* Copyright 2015 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 java.io.Serializable;
public class ServiceCredentials implements Serializable {
private static final long serialVersionUID = 5267708910761478567L;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password;
}
}
......@@ -19,7 +19,7 @@
package eu.chorevolution.idm.connid.federationserver;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserService;
import eu.chorevolution.securitytokenservice.federationserver.api.FederationServerEndUserService;
import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.endpoint.Server;
......
......@@ -18,13 +18,15 @@
*/
package eu.chorevolution.idm.connid.federationserver;
import eu.chorevolution.idm.connid.federationserver.api.EndUser;
import eu.chorevolution.idm.connid.federationserver.api.FederationServerEndUserService;
import eu.chorevolution.idm.connid.federationserver.api.ServiceCredentials;
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.core.GenericEntity;
import javax.ws.rs.core.Response;
import org.identityconnectors.common.CollectionUtil;
public class TestFederationServerEndUserService implements FederationServerEndUserService {
......@@ -44,43 +46,46 @@ public class TestFederationServerEndUserService implements FederationServerEndUs
endUser.getAttributes().put("attr1", CollectionUtil.newSet("value1", "value2"));
endUser.getAttributes().put("attr2", CollectionUtil.newSet("value3", "value4"));
ServiceCredentials sc1 = new ServiceCredentials();
sc1.setUsername("sc1_" + DEFAULT_USERNAME);
sc1.setPassword("password1");
Map<String, String> sc1 = Collections.singletonMap("sc1_" + DEFAULT_USERNAME, "password1");
endUser.getServiceCredentials().put("sc1", sc1);
ServiceCredentials sc2 = new ServiceCredentials();
sc2.setUsername("sc2_" + DEFAULT_USERNAME);
sc2.setPassword("password2");
Map<String, String> sc2 = Collections.singletonMap("sc2_" + DEFAULT_USERNAME, "password2");
endUser.getServiceCredentials().put("sc3", sc2);
this.endusers.put(endUser.getUsername(), endUser);
}
@Override
public List<EndUser> list(final String domain) {
return new ArrayList<>(endusers.values());
public Response list(final String domain) {
return Response.ok(new GenericEntity<List<EndUser>>(new ArrayList<>(endusers.values())) {
}).build();
}
@Override
public void create(final String domain, final EndUser enduser) {
public Response create(final String domain, final EndUser enduser) {
endusers.put(enduser.getUsername(), enduser);
return Response.status(Response.Status.NO_CONTENT).build();
}
@Override
public EndUser read(final String domain, final String username) {
return endusers.get(username);
public Response read(final String domain, final String username) {
EndUser user = endusers.get(username);
return user == null
? Response.status(Response.Status.NOT_FOUND).build()
: Response.ok(user).build();
}
@Override
public void update(final String domain, final String username, final EndUser enduser) {
public Response update(final String domain, final String username, final EndUser enduser) {
endusers.remove(username);
endusers.put(enduser.getUsername(), enduser);
return Response.status(Response.Status.NO_CONTENT).build();
}
@Override
public void delete(final String domain, final String username) {
public Response delete(final String domain, final String username) {
endusers.remove(username);
return Response.status(Response.Status.NO_CONTENT).build();
}
}
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