cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1545234 - in /cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp: model/ rest/ service/
Date Mon, 25 Nov 2013 11:40:23 GMT
Author: sergeyb
Date: Mon Nov 25 11:40:22 2013
New Revision: 1545234

URL: http://svn.apache.org/r1545234
Log:
Some more prototyping of Fediz IDP Service REST interface

Added:
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
  (with props)
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java
  (with props)
Modified:
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/IDPConfig.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServices.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigService.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/ConfigServiceSpring.java

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/IDPConfig.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/IDPConfig.java?rev=1545234&r1=1545233&r2=1545234&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/IDPConfig.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/model/IDPConfig.java
Mon Nov 25 11:40:22 2013
@@ -22,90 +22,87 @@ import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
-//import javax.persistence.Column;
-//import javax.persistence.Entity;
-//import javax.persistence.Id;
-//import javax.persistence.Table;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-//@Entity
-//@Table(name = "IDP")
 import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement(name = "IDP", namespace = "http://org.apache.cxf.fediz")
 public class IDPConfig implements Serializable {
-        
-    //@Id
-    //private Long id;
-
-    //@Column(name = "REALM", nullable = false, length = FIELD_LENGTH)
-    //Unique
-    //fed:TargetScope
-    private String realm;  //wtrealm, whr
 
-    //Unique
-    //https://<host>:<port>/fediz-idp/<IDP uri>/
+    // @Id
+    // private Long id;
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -5570301342547139039L;
+
+    // @Column(name = "REALM", nullable = false, length = FIELD_LENGTH)
+    // Unique
+    // fed:TargetScope
+    private String realm; // wtrealm, whr
+
+    // Unique
+    // https://<host>:<port>/fediz-idp/<IDP uri>/
     private String uri;
-    
-    //Home Realm Discovery Service
-    //Spring EL
+
+    // Home Realm Discovery Service
+    // Spring EL
     private String hrds;
-    
-    //@Column(name = "INACTIVE", nullable = true, length = FIELD_LENGTH)
-    //if HRDS can't determine the home realm, should
-    //the list of trusted IDPs be shown to make a choice
+
+    // @Column(name = "INACTIVE", nullable = true, length = FIELD_LENGTH)
+    // if HRDS can't determine the home realm, should
+    // the list of trusted IDPs be shown to make a choice
     private boolean provideIDPList;
-    
-    //If HRDS can't discover a home realm and displaying IDP list is not enabled
-    //it falls back to current IDP if an authentication domain is configured
+
+    // If HRDS can't discover a home realm and displaying IDP list is not
+    // enabled
+    // it falls back to current IDP if an authentication domain is configured
     private boolean useCurrentIDP;
-    
-    //Store certificate in DB or filesystem, provide options?
-    //md:KeyDescriptor, use="signing"
+
+    // Store certificate in DB or filesystem, provide options?
+    // md:KeyDescriptor, use="signing"
     private String certificate;
-    
-    //Password to read the private key to sign metadata document
+
+    // Password to read the private key to sign metadata document
     private String certificatePassword;
-    
-    //fed:SecurityTokenSerivceEndpoint
+
+    // fed:SecurityTokenSerivceEndpoint
     private String stsUrl;
-    
-    //fed:PassiveRequestorEndpoint
-    //published hostname, port must be configured
+
+    // fed:PassiveRequestorEndpoint
+    // published hostname, port must be configured
     private String idpUrl;
-    
-    //RoleDescriptor protocolSupportEnumeration=
+
+    // RoleDescriptor protocolSupportEnumeration=
     // "http://docs.oasis-open.org/wsfed/federation/200706"
     // "http://docs.oasis-open.org/ws-sx/ws-trust/200512"
     // Could be more in the future
     private List<String> supportedProtocols;
-    
-    //list of RPs and RP-IDPs from whom we accept SignInResponse
-    //which includes RP IDPs
-    //key: wtrealm
+
+    // list of RPs and RP-IDPs from whom we accept SignInResponse
+    // which includes RP IDPs
+    // key: wtrealm
     private Map<String, ServiceConfig> services;
-    
-    //list of trusted IDP from whom we accept SignInResponse
-    //key: whr
+
+    // list of trusted IDP from whom we accept SignInResponse
+    // key: whr
     private Map<String, TrustedIDPConfig> trustedIDPs;
-    
-    //which URI to redirect for authentication
-    //fediz-idp/<IDP uri>/login/auth/<auth URI>
-    //wauth to auth URI mapping
+
+    // which URI to redirect for authentication
+    // fediz-idp/<IDP uri>/login/auth/<auth URI>
+    // wauth to auth URI mapping
     private Map<String, String> authenticationURIs;
-    
-    //required to create Federation Metadata document
-    //fed:TokenTypesOffered
+
+    // required to create Federation Metadata document
+    // fed:TokenTypesOffered
     private List<String> tokenTypesOffered;
-    
-    //fed:ClaimTypesOffered
+
+    // fed:ClaimTypesOffered
     private List<String> claimTypesOffered;
-    
-    //ServiceDisplayName
+
+    // ServiceDisplayName
     private String serviceDisplayName;
-    
-    //ServiceDescription
+
+    // ServiceDescription
     private String serviceDescription;
 
     public String getRealm() {
@@ -155,7 +152,7 @@ public class IDPConfig implements Serial
     public void setCertificate(String certificate) {
         this.certificate = certificate;
     }
-    
+
     public String getCertificatePassword() {
         return certificatePassword;
     }
@@ -188,8 +185,6 @@ public class IDPConfig implements Serial
         this.supportedProtocols = supportedProtocols;
     }
 
-    @GET
-    @Path("services")
     public Map<String, ServiceConfig> getServices() {
         return services;
     }
@@ -198,8 +193,6 @@ public class IDPConfig implements Serial
         this.services = services;
     }
 
-    @GET
-    @Path("trusted-idp")
     public Map<String, TrustedIDPConfig> getTrustedIDPs() {
         return trustedIDPs;
     }

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java?rev=1545234&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
Mon Nov 25 11:40:22 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
+
+@XmlRootElement
+public class IDPServiceConfigs {
+
+    private Map<String, ServiceConfig> services;
+
+    public IDPServiceConfigs() {
+    }
+
+    public IDPServiceConfigs(Map<String, ServiceConfig> services) {
+        this.services = services;
+    }
+
+    public Map<String, ServiceConfig> getServices() {
+        return services;
+    }
+
+    public void setServices(Map<String, ServiceConfig> services) {
+        this.services = services;
+    }
+
+    @GET
+    @Path("wtrealm")
+    public ServiceConfig getServiceConfig(@PathParam("wtrealm") String wtrealm) {
+        ServiceConfig config = services.get(wtrealm);
+        if (config == null) {
+            throw new NotFoundException();
+        }
+        return config;
+    }
+
+}
\ No newline at end of file

Propchange: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServiceConfigs.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServices.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServices.java?rev=1545234&r1=1545233&r2=1545234&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServices.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPServices.java
Mon Nov 25 11:40:22 2013
@@ -19,8 +19,10 @@
 
 package org.apache.cxf.fediz.service.idp.rest;
 
+import javax.ws.rs.BadRequestException;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
@@ -30,68 +32,74 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.fediz.service.idp.model.IDPConfig;
 import org.apache.cxf.fediz.service.idp.service.ConfigService;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Path("/idp")
-@Produces("text/xml")
+@Produces({ "text/xml", "application/xml", "application/json", "text/html" })
 public class IDPServices {
-    
-    private static final Logger LOG = LoggerFactory.getLogger(IDPServices.class);
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(IDPServices.class);
 
     private ConfigService configService;
-    
+
     public IDPServices() {
     }
-    
-    
+
     @GET
-    @Path("/{id}/")
-    public IDPConfig getIDP(@PathParam("id") String id) {
-        LOG.info("get IDP config: " + id);
-        
-        return configService.getIDPConfig(id);
+    @Path("/{realm}/")
+    public IDPConfig getIDP(@PathParam("realm") String realm) {
+        LOG.info("get IDP config for realm: " + realm);
+
+        IDPConfig currentConfig = configService.getIDPConfig(realm);
+        if (currentConfig == null) {
+            throw new NotFoundException();
+        }
+        return currentConfig;
     }
 
     @PUT
-    @Path("/idp/")
+    @Path("/")
     public Response updateIDP(IDPConfig idp) {
-        LOG.info("update IDP config: " + idp.getRealm());
-        
-        IDPConfig idpConfig = configService.getIDPConfig(idp.getRealm());
+        LOG.info("update IDP config for realm: " + idp.getRealm());
+
+        IDPConfig currentConfig = getIDP(idp.getRealm());
+
         Response r;
-        if (idpConfig != null) {
-            //configService.put(idp.getRealm(), idp);
+        if (!currentConfig.equals(idp)) {
+            configService.setIDPConfig(idp);
             r = Response.ok().build();
         } else {
             r = Response.notModified().build();
         }
-
         return r;
     }
 
     @POST
     @Path("/")
     public Response addIDP(IDPConfig idp) {
-        LOG.info("add IDP config: " + idp.getRealm());
-        
-        //configService.put(idp.getRealm(), idp);
+        LOG.info("add IDP config for realm: " + idp.getRealm());
 
+        if (configService.getIDPConfig(idp.getRealm()) != null) {
+            LOG.info("IDP config with realm: " + idp.getRealm()
+                    + " already exists");
+            throw new BadRequestException();
+        }
+        configService.setIDPConfig(idp);
         return Response.ok(idp).build();
     }
 
     @DELETE
-    @Path("/{id}/")
-    public Response deleteIDP(@PathParam("id") String id) {
-        LOG.info("delete IDP config: " + id);
-        
-        IDPConfig config = configService.getIDPConfig(id);
-        
+    @Path("/{realm}/")
+    public Response deleteIDP(@PathParam("realm") String realm) {
+        LOG.info("delete IDP config for realm: " + realm);
+
+        IDPConfig config = configService.removeIDPConfig(realm);
+
         Response r;
         if (config != null) {
             r = Response.ok().build();
-            //configService.remove(config);
         } else {
             r = Response.notModified().build();
         }
@@ -99,7 +107,18 @@ public class IDPServices {
         return r;
     }
 
-    
+    @GET
+    @Path("{realm}/services")
+    public IDPServiceConfigs getServices(@PathParam("realm") String realm) {
+        return new IDPServiceConfigs(getIDP(realm).getServices());
+    }
+
+    @GET
+    @Path("{realm}/trusted-idps")
+    public IDPTrustedIdps getTrustedIdps(@PathParam("realm") String realm) {
+        return new IDPTrustedIdps(getIDP(realm).getTrustedIDPs());
+    }
+
     public ConfigService getConfigService() {
         return configService;
     }

Added: 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/IDPTrustedIdps.java?rev=1545234&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java
Mon Nov 25 11:40:22 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.cxf.fediz.service.idp.model.TrustedIDPConfig;
+
+@XmlRootElement
+public class IDPTrustedIdps {
+
+    private Map<String, TrustedIDPConfig> trustedIDPs;
+
+    public IDPTrustedIdps() {
+    }
+
+    public IDPTrustedIdps(Map<String, TrustedIDPConfig> trustedIDPs) {
+        this.trustedIDPs = trustedIDPs;
+    }
+
+    public Map<String, TrustedIDPConfig> getTrustedIDPs() {
+        return trustedIDPs;
+    }
+
+    public void setTrustedIDPs(Map<String, TrustedIDPConfig> trustedIDPs) {
+        this.trustedIDPs = trustedIDPs;
+    }
+
+    @GET
+    @Path("wtrealm")
+    public TrustedIDPConfig getTrustedIDPConfig(@PathParam("whr") String whr) {
+        TrustedIDPConfig config = trustedIDPs.get(whr);
+        if (config == null) {
+            throw new NotFoundException();
+        }
+        return config;
+    }
+
+}
\ No newline at end of file

Propchange: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/IDPTrustedIdps.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=1545234&r1=1545233&r2=1545234&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
Mon Nov 25 11:40:22 2013
@@ -22,8 +22,12 @@ import org.apache.cxf.fediz.service.idp.
 import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
 
 public interface ConfigService {
-    
+
     ServiceConfig getServiceConfig(String realm);
-    
+
     IDPConfig getIDPConfig(String realm);
+
+    void setIDPConfig(IDPConfig config);
+
+    IDPConfig removeIDPConfig(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=1545234&r1=1545233&r2=1545234&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
Mon Nov 25 11:40:22 2013
@@ -18,52 +18,57 @@
  */
 package org.apache.cxf.fediz.service.idp.service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cxf.fediz.service.idp.model.IDPConfig;
 import org.apache.cxf.fediz.service.idp.model.ServiceConfig;
 
 public class ConfigServiceSpring implements ConfigService {
 
-    private List<ServiceConfig> serviceConfigs;
-    private List<IDPConfig> idpConfigs;
+    private Map<String, ServiceConfig> serviceConfigs = new HashMap<String, ServiceConfig>();
+    private Map<String, IDPConfig> idpConfigs = new HashMap<String, IDPConfig>();
 
-    
-    
     @Override
     public ServiceConfig getServiceConfig(String realm) {
-        for (ServiceConfig cfg : serviceConfigs) {
-            if (realm.equals(cfg.getRealm())) {
-                return cfg;
-            }
-        }
-        return null;
+        return serviceConfigs.get(realm);
     }
 
     @Override
     public IDPConfig getIDPConfig(String realm) {
-        for (IDPConfig cfg : idpConfigs) {
-            if (realm.equals(cfg.getRealm())) {
-                return cfg;
-            }
-        }
-        return null;
+        return idpConfigs.get(realm);
     }
-    
+
     public List<ServiceConfig> getServiceConfigs() {
-        return serviceConfigs;
+        return new ArrayList<ServiceConfig>(serviceConfigs.values());
     }
 
-    public void setServiceConfigs(List<ServiceConfig> serviceConfigs) {
-        this.serviceConfigs = serviceConfigs;
+    public void setServiceConfigs(List<ServiceConfig> serviceList) {
+        for (ServiceConfig s : serviceList) {
+            serviceConfigs.put(s.getRealm(), s);
+        }
     }
 
     public List<IDPConfig> getIdpConfigs() {
-        return idpConfigs;
+        return new ArrayList<IDPConfig>(idpConfigs.values());
     }
 
-    public void setIdpConfigs(List<IDPConfig> idpConfigs) {
-        this.idpConfigs = idpConfigs;
+    public void setIdpConfigs(List<IDPConfig> idpList) {
+        for (IDPConfig i : idpList) {
+            idpConfigs.put(i.getRealm(), i);
+        }
+    }
+
+    @Override
+    public void setIDPConfig(IDPConfig config) {
+        idpConfigs.put(config.getRealm(), config);
+    }
+
+    @Override
+    public IDPConfig removeIDPConfig(String realm) {
+        return idpConfigs.remove(realm);
     }
 
 }



Mime
View raw message