cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1560525 [2/4] - in /cxf/fediz/trunk: ./ services/idp/ services/idp/src/main/java/org/apache/cxf/fediz/service/idp/ services/idp/src/main/java/org/apache/cxf/fediz/service/idp/beans/ services/idp/src/main/java/org/apache/cxf/fediz/service/i...
Date Wed, 22 Jan 2014 21:47:03 GMT
Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpService.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpService.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpService.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+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.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.Claim;
+import org.apache.cxf.fediz.service.idp.domain.Idp;
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+
+@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+@Path("idps")
+public interface IdpService {
+
+    @GET
+    Idps getIdps(@QueryParam("start") int start,
+                 @QueryParam("size") @DefaultValue("2") int size,
+                 @QueryParam("expand") @DefaultValue("all")  List<String> expand,
+                 @Context UriInfo uriInfo);
+
+    @GET
+    @Path("{realm}")
+    Idp getIdp(@PathParam("realm") String realm,
+               @QueryParam("expand") @DefaultValue("all")  List<String> expand);
+
+    @POST
+    Response addIdp(@Context UriInfo ui, Idp idp);
+    
+    @PUT
+    @Path("{realm}")
+    Response updateIdp(@Context UriInfo ui, @PathParam("realm") String realm, Idp idp);
+    
+    @DELETE
+    @Path("{realm}")
+    Response deleteIdp(@PathParam("realm") String realm);
+    
+    @POST
+    @Path("{realm}/applications")
+    Response addApplicationToIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                                 Application application);
+    
+    @DELETE
+    @Path("{realm}/applications")
+    Response removeApplicationFromIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                                      Application application);
+    
+    @POST
+    @Path("{realm}/trusted-idps")
+    Response addTrustedIdpToIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                                TrustedIdp trustedIdp);
+    
+    @DELETE
+    @Path("{realm}/trusted-idps")
+    Response removeTrustedIdpFromIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                                     TrustedIdp trustedIdp);
+    
+    @POST
+    @Path("{realm}/claims")
+    Response addClaimToIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                           Claim claim);
+    
+    @DELETE
+    @Path("{realm}/claims")
+    Response removeClaimFromIdp(@Context UriInfo ui, @PathParam("realm") String realm,
+                                Claim claim);    
+
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpServiceImpl.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpServiceImpl.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IdpServiceImpl.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,232 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ValidationException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.Claim;
+import org.apache.cxf.fediz.service.idp.domain.Idp;
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+import org.apache.cxf.fediz.service.idp.service.ApplicationDAO;
+import org.apache.cxf.fediz.service.idp.service.ClaimDAO;
+import org.apache.cxf.fediz.service.idp.service.IdpDAO;
+import org.apache.cxf.fediz.service.idp.service.TrustedIdpDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class IdpServiceImpl implements IdpService {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(IdpServiceImpl.class);
+
+    @Autowired
+    private IdpDAO idpDAO;
+    
+    @Autowired
+    private ApplicationDAO applicationDAO;
+    
+    @Autowired
+    private TrustedIdpDAO trustedIdpDAO;
+    
+    @Autowired
+    private ClaimDAO claimDAO;
+           
+    @Override
+    public Idps getIdps(int start, int size, List<String> expand, UriInfo uriInfo) {
+        List<Idp> idps = idpDAO.getIdps(start, size, expand);
+        
+        Idps list = new Idps();
+        list.setIdps(idps);
+        return list;
+    }
+    
+    @Override
+    public Idp getIdp(String realm, List<String> expand) {
+        Idp idp = idpDAO.getIdp(realm, expand);
+        if (idp == null) {
+            throw new NotFoundException();
+        } else {
+            return idp;
+        }
+    }
+    
+    @Override
+    public Response addIdp(UriInfo ui, Idp idp) {
+        LOG.info("add IDP config");
+        if (idp.getApplications() != null && idp.getApplications().size() > 0) {
+            LOG.warn("IDP resource contains sub resource 'applications'");
+            throw new WebApplicationException(Status.BAD_REQUEST);
+        }
+        if (idp.getTrustedIdps() != null && idp.getTrustedIdps().size() > 0) {
+            LOG.warn("IDP resource contains sub resource 'trusted-idps'");
+            throw new WebApplicationException(Status.BAD_REQUEST);
+        }
+        Idp createdIdp = idpDAO.addIdp(idp);
+        
+        UriBuilder uriBuilder = UriBuilder.fromUri(ui.getRequestUri());
+        uriBuilder.path("{index}");
+        URI location = uriBuilder.build(createdIdp.getRealm());
+        return Response.created(location).entity(idp).build();
+    }
+    
+    @Override
+    public Response updateIdp(UriInfo ui, String realm, Idp idp) {
+        if (!realm.equals(idp.getRealm().toString())) {
+            throw new ValidationException(Status.BAD_REQUEST);
+        }
+        if (idp.getApplications() != null && idp.getApplications().size() > 0) {
+            LOG.warn("IDP resource contains sub resource 'applications'");
+            throw new WebApplicationException(Status.BAD_REQUEST);
+        }
+        if (idp.getTrustedIdps() != null && idp.getTrustedIdps().size() > 0) {
+            LOG.warn("IDP resource contains sub resource 'trusted-idps'");
+            throw new WebApplicationException(Status.BAD_REQUEST);
+        }
+        idpDAO.updateIdp(realm, idp);
+        
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response deleteIdp(String realm) {
+        idpDAO.deleteIdp(realm);
+        
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response addApplicationToIdp(UriInfo ui, String realm, Application application) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        if (idp.getApplications().contains(application.getRealm())) {
+            LOG.warn("Application '" + application.getRealm() + "' already added");
+            throw new WebApplicationException(Status.CONFLICT);
+        }
+        Application application2 = applicationDAO.getApplication(application.getRealm(), null);
+        idpDAO.addApplicationToIdp(idp, application2);
+        
+        return Response.noContent().build();
+    }
+    
+    @Override
+    public Response removeApplicationFromIdp(UriInfo ui, String realm,  Application application) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        
+        Application foundItem = null; 
+        for (Application item : idp.getApplications()) {
+            if (item.getRealm().equals(application.getRealm())) {
+                foundItem = item;
+                break;
+            }
+        }
+        if (foundItem == null) {
+            LOG.warn("Application '" + application.getRealm() + "' not found");
+            throw new WebApplicationException(Status.NOT_FOUND);
+        }
+        idpDAO.removeApplicationFromIdp(idp, foundItem);
+        
+        return Response.noContent().build();
+    }
+    
+    
+    
+    
+    @Override
+    public Response addTrustedIdpToIdp(UriInfo ui, String realm, TrustedIdp trustedIdp) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        if (idp.getTrustedIdps().contains(trustedIdp.getRealm())) {
+            LOG.warn("Trusted IDP '" + trustedIdp.getRealm() + "' already added");
+            throw new WebApplicationException(Status.CONFLICT);
+        }
+        TrustedIdp trustedIpd2 = trustedIdpDAO.getTrustedIDP(trustedIdp.getRealm());
+        
+        idpDAO.addTrustedIdpToIdp(idp, trustedIpd2);
+        
+        return Response.noContent().build();
+    }
+    
+    @Override
+    public Response removeTrustedIdpFromIdp(UriInfo ui, String realm, TrustedIdp trustedIdp) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        
+        TrustedIdp foundItem = null; 
+        for (TrustedIdp item : idp.getTrustedIdps()) {
+            if (item.getRealm().equals(trustedIdp.getRealm())) {
+                foundItem = item;
+                break;
+            }
+        }
+        if (foundItem == null) {
+            LOG.warn("Trusted IDP '" + trustedIdp.getRealm() + "' not found");
+            throw new WebApplicationException(Status.NOT_FOUND);
+        }
+        idpDAO.removeTrustedIdpFromIdp(idp, foundItem);
+        
+        return Response.noContent().build();
+    }   
+    
+    @Override
+    public Response addClaimToIdp(UriInfo ui, String realm, Claim claim) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        if (idp.getClaimTypesOffered().contains(claim.getClaimType().toString())) {
+            LOG.warn("Claim '" + claim.getClaimType() + "' already added");
+            throw new WebApplicationException(Status.CONFLICT);
+        }
+        Claim claim2 = claimDAO.getClaim(claim.getClaimType().toString());
+        idpDAO.addClaimToIdp(idp, claim2);
+        
+        return Response.noContent().build();
+    }
+    
+    @Override
+    public Response removeClaimFromIdp(UriInfo ui, String realm, Claim claim) {
+        Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
+        
+        Claim foundItem = null; 
+        for (Claim item : idp.getClaimTypesOffered()) {
+            if (item.getClaimType().toString().equals(claim.getClaimType().toString())) {
+                foundItem = item;
+                break;
+            }
+        }
+        if (foundItem == null) {
+            LOG.warn("Claim '" + claim.getClaimType() + "' not found");
+            throw new WebApplicationException(Status.NOT_FOUND);
+        }
+        idpDAO.removeClaimFromIdp(idp, foundItem);
+                
+        return Response.noContent().build();
+    }
+
+
+}
\ No newline at end of file

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/Idps.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/Idps.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/Idps.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/Idps.java Wed Jan 22 21:47:02 2014
@@ -16,28 +16,34 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.model;
 
-import java.io.Serializable;
-import java.net.URI;
+package org.apache.cxf.fediz.service.idp.rest;
 
-public class RequestClaim implements Serializable {
-    
-    private URI claimType;
-    
-    private boolean optional;
-    
-    
-    public void setClaimType(URI claimType) {
-        this.claimType = claimType;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.cxf.fediz.service.idp.domain.Idp;
+
+@XmlRootElement(name = "idps")
+public class Idps {
+
+    private Collection<Idp> idps;
+
+    public Idps() {
     }
-    public URI getClaimType() {
-        return claimType;
+
+    public Idps(Collection<Idp> idps) {
+        this.idps = idps;
     }
-    public void setOptional(boolean optional) {
-        this.optional = optional;
+
+    @XmlElementRef
+    public Collection<Idp> getIdps() {
+        return idps;
     }
-    public boolean isOptional() {
-        return optional;
+
+    public void setIdps(Collection<Idp> idps) {
+        this.idps = idps;
     }
-}
+}
\ No newline at end of file

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/QueryResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/QueryResourceInfoComparator.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/QueryResourceInfoComparator.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/QueryResourceInfoComparator.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.jaxrs.ext.ResourceComparator;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
+
+public class QueryResourceInfoComparator extends OperationResourceInfoComparator implements ResourceComparator {
+
+    public QueryResourceInfoComparator() {
+        super(null, null);
+    }
+
+    @Override
+    public int compare(final ClassResourceInfo cri1, final ClassResourceInfo cri2, final Message message) {
+        // Leave Class selection to CXF
+        return 0;
+    }
+
+    @Override
+    public int compare(final OperationResourceInfo oper1, final OperationResourceInfo oper2, final Message message) {
+        // Check if CXF can make a decision
+        int cxfResult = super.compare(oper1, oper2);
+        if (cxfResult != 0) {
+            return cxfResult;
+        }
+
+        int op1Counter = getMatchingRate(oper1, message);
+        int op2Counter = getMatchingRate(oper2, message);
+
+        return op1Counter == op2Counter
+                ? 0
+                : op1Counter < op2Counter
+                ? 1
+                : -1;
+    }
+
+    /**
+     * This method calculates a number indicating a good or bad match between values provided within the request and
+     * expected method parameters. A higher number means a better match.
+     *
+     * @param operation The operation to be rated, based on contained parameterInfo values.
+     * @param message A message containing query and header values from user request
+     * @return A positive or negative number, indicating a good match between query and method
+     */
+    protected int getMatchingRate(final OperationResourceInfo operation, final Message message) {
+        List<Parameter> params = operation.getParameters();
+        if (params == null || params.isEmpty()) {
+            return 0;
+        }
+
+        // Get Request QueryParams
+        String query = (String) message.get(Message.QUERY_STRING);
+        String path = (String) message.get(Message.REQUEST_URI);
+        Map<String, List<String>> qParams = JAXRSUtils.getStructuredParams(query, "&", true, false);
+        Map<String, List<String>> mParams = JAXRSUtils.getMatrixParams(path, true);
+        // Get Request Headers
+        Map<?, ?> qHeader = (java.util.Map<?, ?>) message.get(Message.PROTOCOL_HEADERS);
+
+        int rate = 0;
+        for (Parameter p : params) {
+            switch (p.getType()) {
+            case QUERY:
+                if (qParams.containsKey(p.getName())) {
+                    rate += 2;
+                } else if (p.getDefaultValue() == null) {
+                    rate -= 1;
+                }
+                break;
+            case MATRIX:
+                if (mParams.containsKey(p.getName())) {
+                    rate += 2;
+                } else if (p.getDefaultValue() == null) {
+                    rate -= 1;
+                }
+                break;
+            case HEADER:
+                if (qHeader.containsKey(p.getName())) {
+                    rate += 2;
+                } else if (p.getDefaultValue() == null) {
+                    rate -= 1;
+                }
+                break;
+            default:
+                break;
+            }
+        }
+        return rate;
+    }
+}

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootService.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootService.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootService.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootService.java Wed Jan 22 21:47:02 2014
@@ -16,18 +16,22 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+package org.apache.cxf.fediz.service.idp.rest;
 
-public interface ConfigService {
 
-    ServiceConfig getServiceConfig(String realm);
+import javax.ws.rs.HEAD;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 
-    IDPConfig getIDPConfig(String realm);
 
-    void setIDPConfig(IDPConfig config);
+@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+public interface RootService {
+
+    @HEAD
+    Response head(@Context UriInfo uriInfo);
 
-    IDPConfig removeIDPConfig(String realm);
 }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootServiceImpl.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootServiceImpl.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RootServiceImpl.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+
+public class RootServiceImpl implements RootService {
+
+    public RootServiceImpl() {
+    }
+    
+    public Response head(UriInfo uriInfo) {
+        UriBuilder absolute = uriInfo.getBaseUriBuilder();
+        URI claimUrl = absolute.clone().path("claims").build();
+        URI idpUrl = absolute.clone().path("idps").build();
+        URI applicationUrl = absolute.clone().path("applications").build();
+        URI trustedIdpUrl = absolute.clone().path("trusted-idps").build();
+        javax.ws.rs.core.Link claims = javax.ws.rs.core.Link.fromUri(claimUrl).rel("claims")
+            .type("application/xml").build();
+        javax.ws.rs.core.Link idps = javax.ws.rs.core.Link.fromUri(idpUrl).rel("idps")
+            .type("application/xml").build();
+        javax.ws.rs.core.Link applications = javax.ws.rs.core.Link.fromUri(applicationUrl).rel("applications")
+            .type("application/xml").build();
+        javax.ws.rs.core.Link trustedIdps = javax.ws.rs.core.Link.fromUri(trustedIdpUrl).rel("trusted-idps")
+            .type("application/xml").build();
+
+        Response.ResponseBuilder builder = Response.ok().links(claims, idps, applications, trustedIdps);
+        return builder.build();
+    }
+
+}
\ No newline at end of file

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpService.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpService.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpService.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+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.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+
+
+@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+@Path("trusted-idps")
+public interface TrustedIdpService {
+
+    @GET
+    TrustedIdps getTrustedIDPs(@QueryParam("start") int start,
+                               @QueryParam("size") @DefaultValue("2") int size,
+                               @Context UriInfo uriInfo);
+
+    @GET
+    @Path("{realm}")
+    TrustedIdp getTrustedIDP(@PathParam("realm") String realm);
+
+    @POST
+    Response addTrustedIDP(@Context UriInfo ui, TrustedIdp trustedIdp);
+    
+    @PUT
+    @Path("{realm}")
+    Response updateTrustedIDP(@Context UriInfo ui, @PathParam("realm") String realm, TrustedIdp trustedIdp);
+    
+    @DELETE
+    @Path("{realm}")
+    Response deleteTrustedIDP(@PathParam("realm") String realm);
+
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpServiceImpl.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpServiceImpl.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdpServiceImpl.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.rest;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.ValidationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+import org.apache.cxf.fediz.service.idp.service.TrustedIdpDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TrustedIdpServiceImpl implements TrustedIdpService {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(TrustedIdpServiceImpl.class);
+
+    @Autowired
+    private TrustedIdpDAO trustedIdpDAO;
+
+    
+    
+    @Override
+    public Response updateTrustedIDP(UriInfo ui, String realm, TrustedIdp trustedIdp) {
+        if (!realm.equals(trustedIdp.getRealm().toString())) {
+            throw new ValidationException(Status.BAD_REQUEST);
+        }
+        trustedIdpDAO.updateTrustedIDP(realm, trustedIdp);
+        
+        return Response.noContent().build();
+    }
+    
+    @Override
+    public TrustedIdps getTrustedIDPs(int start, int size, UriInfo uriInfo) {
+        List<TrustedIdp> trustedIdps = trustedIdpDAO.getTrustedIDPs(start, size);
+        
+        TrustedIdps list = new TrustedIdps();
+        list.setTrustedIDPs(trustedIdps);
+        return list;
+    }
+    
+    @Override
+    public TrustedIdp getTrustedIDP(String realm) {
+        return this.trustedIdpDAO.getTrustedIDP(realm);
+    }
+    
+    @Override
+    public Response addTrustedIDP(UriInfo ui, TrustedIdp trustedIDP) {
+        LOG.info("add Trusted IDP config");
+        
+        TrustedIdp createdTrustedIdp = trustedIdpDAO.addTrustedIDP(trustedIDP);
+        
+        UriBuilder uriBuilder = UriBuilder.fromUri(ui.getRequestUri());
+        uriBuilder.path("{index}");
+        URI location = uriBuilder.build(createdTrustedIdp.getRealm());
+        return Response.created(location).entity(trustedIDP).build();
+    }
+
+    @Override
+    public Response deleteTrustedIDP(String realm) {
+        trustedIdpDAO.deleteTrustedIDP(realm);
+        
+        return Response.noContent().build();
+    }
+           
+    
+
+
+}
\ No newline at end of file

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdps.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdps.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdps.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/TrustedIdps.java Wed Jan 22 21:47:02 2014
@@ -19,45 +19,31 @@
 
 package org.apache.cxf.fediz.service.idp.rest;
 
-import java.util.Map;
+import java.util.Collection;
 
+import javax.xml.bind.annotation.XmlElementRef;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.cxf.fediz.service.idp.model.TrustedIDPConfig;
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
 
-@XmlRootElement
-public class IDPTrustedIdps {
+@XmlRootElement(name = "trustedIdps")
+public class TrustedIdps {
 
-    private Map<String, TrustedIDPConfig> trustedIDPs;
+    private Collection<TrustedIdp> trustedIDPs;
 
-    public IDPTrustedIdps() {
+    public TrustedIdps() {
     }
 
-    public IDPTrustedIdps(Map<String, TrustedIDPConfig> trustedIDPs) {
+    public TrustedIdps(Collection<TrustedIdp> trustedIDPs) {
         this.trustedIDPs = trustedIDPs;
     }
 
-    public Map<String, TrustedIDPConfig> getTrustedIDPs() {
+    @XmlElementRef
+    public Collection<TrustedIdp> getTrustedIDPs() {
         return trustedIDPs;
     }
 
-    public void setTrustedIDPs(Map<String, TrustedIDPConfig> trustedIDPs) {
+    public void setTrustedIDPs(Collection<TrustedIdp> trustedIDPs) {
         this.trustedIDPs = trustedIDPs;
     }
-
-//    @GET
-//    @Path("{whr}")
-//    public TrustedIDPConfig getTrustedIDPConfig(@PathParam("whr") String whr) {
-//        TrustedIDPConfig config = trustedIDPs.get(whr);
-//        if (config == null) {
-//            throw new NotFoundException();
-//        }
-//        return config;
-//    }
-
-//    @GET
-//    public IDPTrustedIdps getState() {   
-//        return this;
-//    }
-    
 }
\ No newline at end of file

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ApplicationDAO.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ApplicationDAO.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ApplicationDAO.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ApplicationDAO.java Wed Jan 22 21:47:02 2014
@@ -16,18 +16,28 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+import java.util.List;
+
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.RequestClaim;
+
+public interface ApplicationDAO {
+
+    List<Application> getApplications(int start, int size, List<String> expand);
+
+    Application getApplication(String realm, List<String> expand);
 
-public interface ConfigService {
+    Application addApplication(Application application);
 
-    ServiceConfig getServiceConfig(String realm);
+    void updateApplication(String realm, Application application);
 
-    IDPConfig getIDPConfig(String realm);
+    void deleteApplication(String realm);
 
-    void setIDPConfig(IDPConfig config);
+    void addClaimToApplication(Application application, RequestClaim claim);
+    
+    void removeClaimFromApplication(Application application, RequestClaim claim);
 
-    IDPConfig removeIDPConfig(String realm);
 }

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ClaimDAO.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ClaimDAO.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ClaimDAO.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ClaimDAO.java Wed Jan 22 21:47:02 2014
@@ -16,18 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+package org.apache.cxf.fediz.service.idp.service;
 
-public interface ConfigService {
+import java.util.List;
 
-    ServiceConfig getServiceConfig(String realm);
+import org.apache.cxf.fediz.service.idp.domain.Claim;
 
-    IDPConfig getIDPConfig(String realm);
+public interface ClaimDAO {
 
-    void setIDPConfig(IDPConfig config);
+    List<Claim> getClaims(int start, int size);
+    
+    Claim getClaim(String claimType);
+    
+    Claim addClaim(Claim claim);
+    
+    void updateClaim(String claimType, Claim claim);
+    
+    void deleteClaim(String claimType);
 
-    IDPConfig removeIDPConfig(String realm);
 }

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java?rev=1560525&r1=1560524&r2=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java Wed Jan 22 21:47:02 2014
@@ -18,16 +18,15 @@
  */
 package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+import org.apache.cxf.fediz.service.idp.domain.Idp;
 
-public interface ConfigService {
 
-    ServiceConfig getServiceConfig(String realm);
+public interface ConfigService {
 
-    IDPConfig getIDPConfig(String realm);
+    Idp getIDP(String realm);
 
-    void setIDPConfig(IDPConfig config);
+    void setIDP(Idp config);
 
-    IDPConfig removeIDPConfig(String realm);
+    void removeIDP(String realm);
+    
 }

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigServiceSpring.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigServiceSpring.java?rev=1560525&r1=1560524&r2=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigServiceSpring.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigServiceSpring.java Wed Jan 22 21:47:02 2014
@@ -23,26 +23,38 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.Idp;
 import org.apache.cxf.fediz.service.idp.model.IDPConfig;
 import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
 
 public class ConfigServiceSpring implements ConfigService {
 
-    private Map<String, ServiceConfig> serviceConfigs = new HashMap<String, ServiceConfig>();
-    private Map<String, IDPConfig> idpConfigs = new HashMap<String, IDPConfig>();
+    private Map<String, Application> serviceConfigs = new HashMap<String, Application>();
+    private Map<String, Idp> idpConfigs = new HashMap<String, Idp>();
+
 
     @Override
-    public ServiceConfig getServiceConfig(String realm) {
-        return serviceConfigs.get(realm);
+    public Idp getIDP(String realm) {
+        if (realm == null || realm.length() == 0) {
+            return this.getIdpConfigs().get(0);
+        } else {
+            return idpConfigs.get(realm);
+        }
     }
 
     @Override
-    public IDPConfig getIDPConfig(String realm) {
-        return idpConfigs.get(realm);
+    public void setIDP(Idp config) {
+        idpConfigs.put(config.getRealm(), config);
     }
 
-    public List<ServiceConfig> getServiceConfigs() {
-        return new ArrayList<ServiceConfig>(serviceConfigs.values());
+    @Override
+    public void removeIDP(String realm) {
+        idpConfigs.remove(realm);
+    }
+
+    public List<Application> getServiceConfigs() {
+        return new ArrayList<Application>(serviceConfigs.values());
     }
 
     public void setServiceConfigs(List<ServiceConfig> serviceList) {
@@ -50,9 +62,9 @@ public class ConfigServiceSpring impleme
             serviceConfigs.put(s.getRealm(), s);
         }
     }
-
-    public List<IDPConfig> getIdpConfigs() {
-        return new ArrayList<IDPConfig>(idpConfigs.values());
+    
+    public List<Idp> getIdpConfigs() {
+        return new ArrayList<Idp>(idpConfigs.values());
     }
 
     public void setIdpConfigs(List<IDPConfig> idpList) {
@@ -61,14 +73,4 @@ public class ConfigServiceSpring impleme
         }
     }
 
-    @Override
-    public void setIDPConfig(IDPConfig config) {
-        idpConfigs.put(config.getRealm(), config);
-    }
-
-    @Override
-    public IDPConfig removeIDPConfig(String realm) {
-        return idpConfigs.remove(realm);
-    }
-
 }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/IdpDAO.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/IdpDAO.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/IdpDAO.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/IdpDAO.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service;
+
+import java.util.List;
+
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.Claim;
+import org.apache.cxf.fediz.service.idp.domain.Idp;
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+
+public interface IdpDAO {
+
+    List<Idp> getIdps(int start, int size, List<String> expand);
+
+    Idp getIdp(String realm, List<String> expand);
+
+    Idp addIdp(Idp idp);
+
+    void updateIdp(String realm, Idp idp);
+
+    void deleteIdp(String realm);
+
+    void addApplicationToIdp(Idp idp, Application application);
+    
+    void removeApplicationFromIdp(Idp idp, Application application);
+    
+    void addTrustedIdpToIdp(Idp idp, TrustedIdp trustedIdp);
+    
+    void removeTrustedIdpFromIdp(Idp idp, TrustedIdp trustedIdp);
+    
+    void addClaimToIdp(Idp idp, Claim claim);
+    
+    void removeClaimFromIdp(Idp idp, Claim claim);
+
+}

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/TrustedIdpDAO.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/TrustedIdpDAO.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/TrustedIdpDAO.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/TrustedIdpDAO.java Wed Jan 22 21:47:02 2014
@@ -16,18 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+import java.util.List;
+
+import org.apache.cxf.fediz.service.idp.domain.TrustedIdp;
+
+public interface TrustedIdpDAO {
+
+    List<TrustedIdp> getTrustedIDPs(int start, int size);
 
-public interface ConfigService {
+    TrustedIdp getTrustedIDP(String realm);
 
-    ServiceConfig getServiceConfig(String realm);
+    TrustedIdp addTrustedIDP(TrustedIdp trustedIdp);
 
-    IDPConfig getIDPConfig(String realm);
+    void updateTrustedIDP(String realm, TrustedIdp trustedIdp);
 
-    void setIDPConfig(IDPConfig config);
+    void deleteTrustedIDP(String realm);
 
-    IDPConfig removeIDPConfig(String realm);
 }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationClaimEntity.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationClaimEntity.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationClaimEntity.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationClaimEntity.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service.jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+@Entity(name = "Application_Claim")
+//@IdClass(ApplicationClaimId.class)
+public class ApplicationClaimEntity {
+    
+    @Id
+    private int id;
+    
+    @ManyToOne
+    @JoinColumn(name = "applicationid")
+    private ApplicationEntity application;
+ 
+    @ManyToOne
+    @JoinColumn(name = "claimid")
+    private ClaimEntity claim;
+ 
+    private boolean optional;
+    
+    public ApplicationClaimEntity() {
+    }
+    
+    public ApplicationClaimEntity(ApplicationEntity application, ClaimEntity claim) {
+        super();
+        this.application = application;
+        this.claim = claim;
+    }
+    
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public boolean isOptional() {
+        return optional;
+    }
+
+    public void setOptional(boolean optional) {
+        this.optional = optional;
+    }
+
+    public ApplicationEntity getApplication() {
+        return application;
+    }
+
+    public void setApplication(ApplicationEntity application) {
+        this.application = application;
+    }
+
+    public ClaimEntity getClaim() {
+        return claim;
+    }
+
+    public void setClaim(ClaimEntity claim) {
+        this.claim = claim;
+    }
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPAImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPAImpl.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPAImpl.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPAImpl.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,250 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service.jpa;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.apache.cxf.fediz.service.idp.domain.Application;
+import org.apache.cxf.fediz.service.idp.domain.Claim;
+import org.apache.cxf.fediz.service.idp.domain.RequestClaim;
+import org.apache.cxf.fediz.service.idp.service.ApplicationDAO;
+import org.apache.cxf.fediz.service.idp.service.ClaimDAO;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+@Component
+@Transactional
+public class ApplicationDAOJPAImpl implements ApplicationDAO {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(ApplicationDAOJPAImpl.class);
+
+    private EntityManager em;
+    
+    @Autowired
+    private ClaimDAO claimDAO;
+    
+    
+    @PersistenceContext
+    public void setEntityManager(EntityManager entityManager) {
+        this.em = entityManager;
+    }
+    
+    @Override
+    public List<Application> getApplications(int start, int size, List<String> expandList) {
+        List<Application> list = new ArrayList<Application>();
+        
+        Query query = null;
+        query = em.createQuery("select a from Application a");
+        
+        //@SuppressWarnings("rawtypes")
+        List serviceEntities = query
+            .setFirstResult(start)
+            .setMaxResults(size)
+            .getResultList();
+    
+        for (Object obj : serviceEntities) {
+            ApplicationEntity entity = (ApplicationEntity) obj;
+            list.add(entity2domain(entity, expandList));
+        }
+        return list;
+    }
+    
+    @Override
+    public Application getApplication(String realm, List<String> expandList) {
+        return entity2domain(getApplicationEntity(realm, em), expandList);
+    }
+    
+    @Override
+    public Application addApplication(Application application) {
+        ApplicationEntity entity = new ApplicationEntity();
+        
+        domain2entity(application, entity);
+        em.persist(entity);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Application '" + application.getRealm() + "' added");
+        }
+        return entity2domain(entity, Arrays.asList("all"));
+    }
+
+    @Override
+    public void updateApplication(String realm, Application application) {
+        Query query = null;
+        query = em.createQuery("select a from Application a where a.realm=:realm");
+        query.setParameter("realm", realm);
+        
+        //@SuppressWarnings("rawtypes")
+        ApplicationEntity applicationEntity = (ApplicationEntity)query.getSingleResult();
+        
+        domain2entity(application, applicationEntity);
+        
+        em.persist(applicationEntity);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Application '" + realm + "' updated");
+        }
+    }
+    
+
+    @Override
+    public void deleteApplication(String realm) {
+        Query query = null;
+        query = em.createQuery("select a from Application a where a.realm=:realm");
+        query.setParameter("realm", realm);
+        
+        //@SuppressWarnings("rawtypes")
+        Object applObj = query.getSingleResult();
+        em.remove(applObj);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Application '" + realm + "' deleted");
+        }
+        
+    }
+    
+    @Override
+    public void addClaimToApplication(Application application, RequestClaim claim) {
+        ApplicationEntity applicationEntity = null;
+        if (application.getId() != 0) {
+            applicationEntity = em.find(ApplicationEntity.class, application.getId());
+        } else {
+            Query query = null;
+            query = em.createQuery("select a from Application a where a.realm=:realm");
+            query.setParameter("realm", application.getRealm());
+            
+            applicationEntity = (ApplicationEntity)query.getSingleResult();
+        }
+        
+        Claim c = claimDAO.getClaim(claim.getClaimType().toString());
+        ClaimEntity claimEntity = em.find(ClaimEntity.class, c.getId());
+                
+        ApplicationClaimEntity appClaimEntity = new ApplicationClaimEntity();
+        appClaimEntity.setClaim(claimEntity);
+        appClaimEntity.setApplication(applicationEntity);
+        appClaimEntity.setOptional(claim.isOptional());
+        
+        applicationEntity.getRequestedClaims().add(appClaimEntity);
+    }
+    
+    @Override
+    public void removeClaimFromApplication(Application application, RequestClaim claim) {
+        ApplicationEntity applicationEntity = null;
+        if (application.getId() != 0) {
+            applicationEntity = em.find(ApplicationEntity.class, application.getId());
+        } else {
+            Query query = null;
+            query = em.createQuery("select a from Application a where a.realm=:realm");
+            query.setParameter("realm", application.getRealm());
+            
+            applicationEntity = (ApplicationEntity)query.getSingleResult();
+        }
+        
+        ApplicationClaimEntity foundEntity = null;
+        for (ApplicationClaimEntity acm : applicationEntity.getRequestedClaims()) {
+            if (claim.getClaimType().toString().equals(acm.getClaim().getClaimType())) {
+                foundEntity = acm;
+                break;
+            }
+        }
+        if (foundEntity == null) {
+            throw new EntityNotFoundException("ApplicationClaimEntity not found");
+        }
+        
+        applicationEntity.getRequestedClaims().remove(foundEntity);
+    }
+    
+    
+    static ApplicationEntity getApplicationEntity(String realm, EntityManager em) {
+        Query query = null;
+        query = em.createQuery("select a from Application a where a.realm=:realm");
+        query.setParameter("realm", realm);
+        
+        //@SuppressWarnings("rawtypes")
+        return (ApplicationEntity)query.getSingleResult();
+    }
+        
+    public static void domain2entity(Application application, ApplicationEntity entity) {
+        //The ID must not be updated if the entity has got an id already (update case)
+        if (application.getId() > 0) {
+            entity.setId(application.getId());
+        }
+        
+        entity.setEncryptionCertificate(application.getEncryptionCertificate());
+        entity.setLifeTime(application.getLifeTime());
+        entity.setProtocol(application.getProtocol());
+        entity.setRealm(application.getRealm());
+        entity.setRole(application.getRole());
+        entity.setServiceDescription(application.getServiceDescription());
+        entity.setServiceDisplayName(application.getServiceDisplayName());
+        entity.setTokenType(application.getTokenType());
+    }
+    
+    public static Application entity2domain(ApplicationEntity entity, List<String> expandList) {
+        Application application = new Application();
+        application.setId(entity.getId());
+        application.setEncryptionCertificate(entity.getEncryptionCertificate());
+        application.setLifeTime(entity.getLifeTime());
+        application.setProtocol(entity.getProtocol());
+        application.setRealm(entity.getRealm());
+        application.setRole(entity.getRole());
+        application.setServiceDescription(entity.getServiceDescription());
+        application.setServiceDisplayName(entity.getServiceDisplayName());
+        application.setTokenType(entity.getTokenType());
+        
+        if (expandList != null && (expandList.contains("all") || expandList.contains("claims"))) {
+            for (ApplicationClaimEntity item : entity.getRequestedClaims()) {
+                RequestClaim claim = entity2domain(item);
+                application.getRequestedClaims().add(claim);
+            }
+        }
+        return application;
+    }
+    
+    public static RequestClaim entity2domain(ApplicationClaimEntity entity) {
+        Claim claim = ClaimDAOJPAImpl.entity2domain(entity.getClaim());
+        RequestClaim reqClaim = new RequestClaim(claim);
+        reqClaim.setId(entity.getId());
+        reqClaim.setOptional(entity.isOptional());
+        
+        return reqClaim;
+    }
+    
+    public static void domain2entity(ApplicationEntity application,
+                                     RequestClaim reqClaim, ApplicationClaimEntity entity) {
+        //The ID must not be updated if the entity has got an id already (update case)
+        ClaimEntity claim = new ClaimEntity();
+        ClaimDAOJPAImpl.domain2entity(reqClaim, claim);
+        
+        entity.setApplication(application);
+        entity.setClaim(claim);
+        entity.setOptional(reqClaim.isOptional());
+    }
+
+}

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/ServiceConfig.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/ServiceConfig.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/ServiceConfig.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java Wed Jan 22 21:47:02 2014
@@ -16,31 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.model;
+package org.apache.cxf.fediz.service.idp.service.jpa;
 
-import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.bind.annotation.XmlRootElement;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
 
-//import javax.persistence.Column;
-//import javax.persistence.Entity;
-//import javax.persistence.Id;
-//import javax.persistence.Table;
-
-//@Entity
-//@Table(name = "SERVICE")
-@XmlRootElement(name = "Service", namespace = "http://org.apache.cxf.fediz")
-public class ServiceConfig implements Serializable {
-
-        
-    //@Id
-    //private Long id;
 
-            
-    //Could be imported from Metadata document or manually filled
+@Entity(name = "Application")
+public class ApplicationEntity {
+    
+    @Id
+    private int id;
     
-    //@Column(name = "REALM", nullable = true, length = FIELD_LENGTH)
     private String realm;  //wtrealm, whr
 
     //Could be read from Metadata, RoleDescriptor protocolSupportEnumeration=
@@ -53,7 +45,8 @@ public class ServiceConfig implements Se
     private String encryptionCertificate;
     
     // Could be read from Metadata, fed:ClaimTypesRequested
-    private List<RequestClaim> requestedClaims;
+    @OneToMany(mappedBy = "application", cascade = CascadeType.ALL, orphanRemoval = true)
+    private List<ApplicationClaimEntity> requestedClaims = new ArrayList<ApplicationClaimEntity>();
     
     //Could be read from Metadata, ServiceDisplayName
     //usage for list of application where user is logged in
@@ -67,13 +60,21 @@ public class ServiceConfig implements Se
     //fed:ApplicationServiceType, fed:SecurityTokenServiceType
     private String role;
     
-    
     // Not in Metadata, configured in IDP or passed in wreq parameter
     private String tokenType;
     
     // Not in Metadata, configured in IDP or passed in wreq parameter
     private String lifeTime;
 
+   
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }    
+    
     public String getRealm() {
         return realm;
     }
@@ -98,11 +99,11 @@ public class ServiceConfig implements Se
         this.encryptionCertificate = encryptionCertificate;
     }
 
-    public List<RequestClaim> getRequestedClaims() {
+    public List<ApplicationClaimEntity> getRequestedClaims() {
         return requestedClaims;
     }
 
-    public void setRequestedClaims(List<RequestClaim> requestedClaims) {
+    public void setRequestedClaims(List<ApplicationClaimEntity> requestedClaims) {
         this.requestedClaims = requestedClaims;
     }
 
@@ -145,6 +146,5 @@ public class ServiceConfig implements Se
     public void setLifeTime(String lifeTime) {
         this.lifeTime = lifeTime;
     }
-        
 
 }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimDAOJPAImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimDAOJPAImpl.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimDAOJPAImpl.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimDAOJPAImpl.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,156 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service.jpa;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;            
+
+import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.apache.cxf.fediz.service.idp.domain.Claim;
+import org.apache.cxf.fediz.service.idp.service.ClaimDAO;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+
+@Component
+@Transactional
+public class ClaimDAOJPAImpl implements ClaimDAO {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(ClaimDAOJPAImpl.class);
+
+    private EntityManager em;
+    
+    @PersistenceContext
+    public void setEntityManager(EntityManager entityManager) {
+        this.em = entityManager;
+    }
+    
+    @Override
+    public List<Claim> getClaims(int start, int size) {
+        List<Claim> list = new ArrayList<Claim>();
+        
+        Query query = null;
+        query = em.createQuery("select c from Claim c");
+        
+        //@SuppressWarnings("rawtypes")
+        List claimEntities = query
+            .setFirstResult(start)
+            .setMaxResults(size)
+            .getResultList();
+
+        for (Object obj : claimEntities) {
+            ClaimEntity entity = (ClaimEntity) obj;
+            list.add(entity2domain(entity));
+        }
+        
+        return list;
+    }
+    
+    @Override
+    public Claim addClaim(Claim claim) {
+        try {
+            ClaimEntity entity = new ClaimEntity();
+            domain2entity(claim, entity);
+            em.persist(entity);
+            
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Claim '" + claim.getClaimType() + "' added");
+            }
+            return entity2domain(entity);
+        } catch (EntityExistsException ex) {
+            LOG.warn("Claim with type '" + claim.getClaimType() + "' already exists");
+            //[TODO] Introduce exception layer (to decouple from spring/jpa config)
+            throw new RuntimeException("Claim with type '" + claim.getClaimType() + "' already exists");
+        }
+    }
+
+    @Override
+    public Claim getClaim(String claimType) {
+        return entity2domain(getClaimEntity(claimType, em));
+    }
+
+    @Override
+    public void updateClaim(String claimType, Claim claim) {
+        Query query = null;
+        query = em.createQuery("select c from Claim c where c.claimtype=:claimtype");
+        query.setParameter("claimtype", claimType);
+        
+        //@SuppressWarnings("rawtypes")
+        ClaimEntity claimEntity = (ClaimEntity)query.getSingleResult();
+        
+        domain2entity(claim, claimEntity);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Claim '" + claim.getClaimType() + "' added");
+        }
+        em.persist(claimEntity);
+    }
+
+    @Override
+    public void deleteClaim(String claimType) {
+        Query query = null;
+        query = em.createQuery("select c from Claim c where c.claimType=:claimtype");
+        query.setParameter("claimtype", claimType);
+        
+        //@SuppressWarnings("rawtypes")
+        Object claimObj = query.getSingleResult();
+        em.remove(claimObj);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Claim '" + claimType + "' deleted");
+        }
+    }
+    
+    static ClaimEntity getClaimEntity(String claimType, EntityManager em) {
+        Query query = null;
+        query = em.createQuery("select c from Claim c where c.claimType=:claimtype");
+        query.setParameter("claimtype", claimType);
+        
+        //@SuppressWarnings("rawtypes")
+        return (ClaimEntity)query.getSingleResult();
+    }
+    
+    public static void domain2entity(Claim claim, ClaimEntity entity) {
+        //The ID must not be updated if the entity has got an id already (update case)
+        if (claim.getId() > 0) {
+            entity.setId(claim.getId());
+        }
+        entity.setClaimType(claim.getClaimType().toString());
+        entity.setDisplayName(claim.getDisplayName());
+        entity.setDescription(claim.getDescription());
+    }
+    
+    public static Claim entity2domain(ClaimEntity entity) {
+        Claim claim = new Claim();
+        claim.setId(entity.getId());
+        claim.setClaimType(URI.create(entity.getClaimType()));
+        claim.setDisplayName(entity.getDisplayName());
+        claim.setDescription(entity.getDescription());
+        return claim;
+    }
+
+}

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/RequestClaim.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java Wed Jan 22 21:47:02 2014
@@ -16,28 +16,49 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.model;
+package org.apache.cxf.fediz.service.idp.service.jpa;
 
-import java.io.Serializable;
-import java.net.URI;
+import javax.persistence.Entity;
+import javax.persistence.Id;
 
-public class RequestClaim implements Serializable {
-    
-    private URI claimType;
-    
-    private boolean optional;
+@Entity(name = "Claim")
+public class ClaimEntity {
     
+    @Id
+    private int id;
+    private String claimType;
+    private String displayName;
+    private String description;
+        
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
     
-    public void setClaimType(URI claimType) {
+    public void setClaimType(String claimType) {
         this.claimType = claimType;
     }
-    public URI getClaimType() {
+    
+    public String getClaimType() {
         return claimType;
     }
-    public void setOptional(boolean optional) {
-        this.optional = optional;
+
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public void setDisplayName(String displayName) {
+        this.displayName = displayName;
     }
-    public boolean isOptional() {
-        return optional;
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
     }
 }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ConfigServiceJPA.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ConfigServiceJPA.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ConfigServiceJPA.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ConfigServiceJPA.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service.jpa;
+
+import java.util.Arrays;
+
+import org.apache.cxf.fediz.service.idp.domain.Idp;
+import org.apache.cxf.fediz.service.idp.rest.IdpService;
+import org.apache.cxf.fediz.service.idp.service.ConfigService;
+
+
+public class ConfigServiceJPA implements ConfigService {
+
+    IdpService idpService;
+
+    @Override
+    public Idp getIDP(String realm) {
+        if (realm == null || realm.length() == 0) {
+            return idpService.getIdps(0, 1, Arrays.asList("all"), null).getIdps().iterator().next();
+        } else {
+            return idpService.getIdp(realm, Arrays.asList("all"));
+        }
+    }
+
+    @Override
+    public void setIDP(Idp config) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void removeIDP(String realm) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public IdpService getIdpService() {
+        return idpService;
+    }
+
+    public void setIdpService(IdpService idpService) {
+        this.idpService = idpService;
+    }
+    
+
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBInitApplicationListener.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBInitApplicationListener.java?rev=1560525&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBInitApplicationListener.java (added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBInitApplicationListener.java Wed Jan 22 21:47:02 2014
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.fediz.service.idp.service.jpa;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DBInitApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DBInitApplicationListener.class);
+    
+    private EntityManager em;
+    
+    @Autowired
+    private List<DBLoader> dbloader;
+    
+    @PersistenceContext
+    public void setEntityManager(EntityManager entityManager) {
+        this.em = entityManager;
+    }
+        
+    @Override
+    public void onApplicationEvent(ContextRefreshedEvent arg0) {
+        if (!isDBEmpty()) {
+            LOG.info("Inital DB already loaded");
+            return;
+        }
+        
+        LOG.debug("Loading inital DB data...");
+        for (DBLoader loader : this.dbloader) {
+            loader.load();
+            LOG.info("Inital DB data loaded for " + loader.getName());
+        }
+    }
+    
+    protected boolean isDBEmpty() {
+        CriteriaBuilder cb = em.getCriteriaBuilder();
+        CriteriaQuery<Long> cq = cb.createQuery(Long.class);
+        cq.select(cb.count(cq.from(ClaimEntity.class)));
+
+        return em.createQuery(cq).getSingleResult() == 0;
+    }
+
+}

Copied: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoader.java (from r1560523, cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoader.java?p2=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoader.java&p1=cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java&r1=1560523&r2=1560525&rev=1560525&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java (original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoader.java Wed Jan 22 21:47:02 2014
@@ -16,18 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.fediz.service.idp.service;
 
-import org.apache.cxf.fediz.service.idp.model.IDPConfig;
-import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+package org.apache.cxf.fediz.service.idp.service.jpa;
 
-public interface ConfigService {
+public interface DBLoader {
 
-    ServiceConfig getServiceConfig(String realm);
+    void load();
+    
+    String getName();
 
-    IDPConfig getIDPConfig(String realm);
-
-    void setIDPConfig(IDPConfig config);
-
-    IDPConfig removeIDPConfig(String realm);
 }



Mime
View raw message