cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1573654 - in /cxf/fediz/trunk: ./ services/idp/ services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/ services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ services/idp/src/main/resources/ services/idp/src/ma...
Date Mon, 03 Mar 2014 18:26:12 GMT
Author: owulff
Date: Mon Mar  3 18:26:11 2014
New Revision: 1573654

URL: http://svn.apache.org/r1573654
Log:
JPA bean validation added

Modified:
    cxf/fediz/trunk/pom.xml
    cxf/fediz/trunk/services/idp/pom.xml
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpEntity.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java
    cxf/fediz/trunk/services/idp/src/main/resources/META-INF/spring-persistence.xml
    cxf/fediz/trunk/services/idp/src/main/resources/persistenceContext.xml
    cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPATest.java
    cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpDAOJPATest.java
    cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpDAOJPATest.java

Modified: cxf/fediz/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/pom.xml?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/pom.xml (original)
+++ cxf/fediz/trunk/pom.xml Mon Mar  3 18:26:11 2014
@@ -49,6 +49,7 @@
         <spring.security.version>3.1.4.RELEASE</spring.security.version>
         <tomcat.version>7.0.42</tomcat.version>
         <wss4j.version>2.0.0-SNAPSHOT</wss4j.version>
+        <bval.version>0.5</bval.version>
 
         <tomcat.url>http://localhost:8080/manager/text</tomcat.url>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Modified: cxf/fediz/trunk/services/idp/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/pom.xml?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/pom.xml (original)
+++ cxf/fediz/trunk/services/idp/pom.xml Mon Mar  3 18:26:11 2014
@@ -177,17 +177,44 @@
             <artifactId>cglib-nodep</artifactId>
             <version>2.1_3</version>
         </dependency>
+        <!-- 
         <dependency>
             <groupId>org.apache.openjpa</groupId>
             <artifactId>openjpa-all</artifactId>
             <version>2.2.2</version>
         </dependency>
+        -->
+        <dependency>
+            <groupId>commons-dbcp</groupId> 
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.openjpa</groupId>
+            <artifactId>openjpa-jdbc</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.openjpa</groupId>
+            <artifactId>openjpa-persistence-jdbc</artifactId>
+            <version>2.2.2</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-rs-client</artifactId>
             <version>${cxf.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+            <version>1.0.0.GA</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.bval</groupId>
+            <artifactId>bval-jsr303</artifactId>
+            <version>${bval.version}</version>
+        </dependency>
     </dependencies>
     <build>
         <resources>

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
Mon Mar  3 18:26:11 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.fediz.service.idp.rest;
 
+import javax.validation.ConstraintViolationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -44,13 +45,20 @@ public class RestServiceExceptionMapper 
 
     @Override
     public Response toResponse(final Exception ex) {
-        LOG.error("Exception thrown by REST method: " + ex.getMessage(), ex);
+        LOG.warn("Exception occured processing REST request: " + ex.getMessage(), ex);
 
         if (ex instanceof AccessDeniedException) {
             return Response.status(Response.Status.UNAUTHORIZED).
                     header(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM_UNAUTHORIZED).
                     build();
         }
+        if (ex instanceof ConstraintViolationException) {
+            ConstraintViolationException cve = (ConstraintViolationException)ex;
+            if (LOG.isDebugEnabled()) {
+                LOG.debug(ex.getMessage() + "\n" + cve.getConstraintViolations().toString());
+            }
+            return buildResponse(Response.Status.BAD_REQUEST, ex);
+        }
         if (ex instanceof DataIntegrityViolationException) {
             return buildResponse(Response.Status.CONFLICT, ex);
         }

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.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?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java
Mon Mar  3 18:26:11 2014
@@ -25,6 +25,8 @@ import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.OneToMany;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
 
 import org.apache.openjpa.persistence.jdbc.Index;
 
@@ -36,11 +38,13 @@ public class ApplicationEntity {
     private int id;
     
     @Index
+    @NotNull
     private String realm;  //wtrealm, whr
 
     //Could be read from Metadata, RoleDescriptor protocolSupportEnumeration=
-    // "http://docs.oasis-open.org/wsfed/federation/200706"
+    // "http://docs.oa14sis-open.org/wsfed/federation/200706"
     // Metadata could provide more than one but one must be chosen
+    @NotNull
     private String protocol;
  
     // Public key only
@@ -53,6 +57,7 @@ public class ApplicationEntity {
     
     //Could be read from Metadata, ServiceDisplayName
     //usage for list of application where user is logged in
+    @NotNull
     private String serviceDisplayName;
     
     //Could be read from Metadata, ServiceDescription
@@ -64,9 +69,11 @@ public class ApplicationEntity {
     private String role;
     
     // Not in Metadata, configured in IDP or passed in wreq parameter
+    @NotNull
     private String tokenType;
     
     // Not in Metadata, configured in IDP or passed in wreq parameter
+    @Min(value = 1)
     private int lifeTime;
     
     // WS-Policy Namespace in SignIn Response

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.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?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ClaimEntity.java
Mon Mar  3 18:26:11 2014
@@ -20,6 +20,7 @@ package org.apache.cxf.fediz.service.idp
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
+import javax.validation.constraints.NotNull;
 
 import org.apache.openjpa.persistence.jdbc.Index;
 
@@ -30,6 +31,7 @@ public class ClaimEntity {
     private int id;
     
     @Index
+    @NotNull
     private String claimType;
     
     private String displayName;

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpEntity.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpEntity.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpEntity.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpEntity.java
Mon Mar  3 18:26:11 2014
@@ -34,6 +34,7 @@ import javax.persistence.Id;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToMany;
 import javax.persistence.MapKeyColumn;
+import javax.validation.constraints.NotNull;
 
 import org.apache.openjpa.persistence.jdbc.Index;
 
@@ -46,6 +47,7 @@ public class IdpEntity {
     // Unique
     // fed:TargetScope
     @Index
+    @NotNull
     private String realm; // wtrealm, whr
 
     // Unique
@@ -73,10 +75,12 @@ public class IdpEntity {
     private String certificatePassword;
 
     // fed:SecurityTokenSerivceEndpoint
+    @NotNull
     private URL stsUrl;
 
     // fedl:PassiveRequestorEndpoint
     // published hostname, port must be configured
+    @NotNull
     private URL idpUrl;
     
     private boolean rpSingleSignOutConfirmation;
@@ -125,6 +129,7 @@ public class IdpEntity {
     private List<ClaimEntity> claimTypesOffered = new ArrayList<ClaimEntity>();
 
     // ServiceDisplayName
+    @NotNull
     private String serviceDisplayName;
 
     // ServiceDescription

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java
Mon Mar  3 18:26:11 2014
@@ -22,6 +22,7 @@ import javax.persistence.Entity;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
 import javax.persistence.Id;
+import javax.validation.constraints.NotNull;
 
 import org.apache.cxf.fediz.service.idp.domain.FederationType;
 import org.apache.cxf.fediz.service.idp.domain.TrustType;
@@ -36,6 +37,7 @@ public class TrustedIdpEntity {
 
     //@Column(name = "REALM", nullable = true, length = FIELD_LENGTH)
     @Index
+    @NotNull
     private String realm;  //wtrealm, whr
 
     // Should tokens be cached from trusted IDPs
@@ -43,6 +45,7 @@ public class TrustedIdpEntity {
     private boolean cacheTokens;
     
     //Could be read from Metadata, PassiveRequestorEndpoint
+    @NotNull
     private String url;
     
     //Could be read from Metadata, md:KeyDescriptor, use="signing"
@@ -63,6 +66,7 @@ public class TrustedIdpEntity {
     private FederationType federationType;
     
     //optional (to provide a list of IDPs)
+    @NotNull
     private String name;
     
     //optional (to provide a list of IDPs)

Modified: cxf/fediz/trunk/services/idp/src/main/resources/META-INF/spring-persistence.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/resources/META-INF/spring-persistence.xml?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/resources/META-INF/spring-persistence.xml (original)
+++ cxf/fediz/trunk/services/idp/src/main/resources/META-INF/spring-persistence.xml Mon Mar
 3 18:26:11 2014
@@ -25,6 +25,6 @@
 
     <persistence-unit name="fedizPersistenceUnit">
         <mapping-file>META-INF/orm.xml</mapping-file>
-        <validation-mode>NONE</validation-mode>
+        <validation-mode>AUTO</validation-mode>
     </persistence-unit>
 </persistence>
\ No newline at end of file

Modified: cxf/fediz/trunk/services/idp/src/main/resources/persistenceContext.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/resources/persistenceContext.xml?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/resources/persistenceContext.xml (original)
+++ cxf/fediz/trunk/services/idp/src/main/resources/persistenceContext.xml Mon Mar  3 18:26:11
2014
@@ -96,5 +96,12 @@
 
     <bean id="dbListener"
         class="org.apache.cxf.fediz.service.idp.service.jpa.DBInitApplicationListener" />
+        
+    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
+    <!-- 
+        <property name="providerClass"
+                  value="org.apache.bval.jsr303.ApacheValidationProvider" />
+                  -->
+    </bean>
 
 </beans>
\ No newline at end of file

Modified: cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPATest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPATest.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPATest.java
(original)
+++ cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationDAOJPATest.java
Mon Mar  3 18:26:11 2014
@@ -213,8 +213,8 @@ public class ApplicationDAOJPATest {
     @Test(expected = EmptyResultDataAccessException.class)
     public void testRemoveExistingApplication() {
         String realm = "urn:org:apache:cxf:fediz:app:testdelete";
-        Application application = new Application();
-        application.setRealm(realm);
+        Application application = createApplication(realm);
+        
         applicationDAO.addApplication(application);
         
         applicationDAO.deleteApplication(realm);

Modified: cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpDAOJPATest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpDAOJPATest.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpDAOJPATest.java
(original)
+++ cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/IdpDAOJPATest.java
Mon Mar  3 18:26:11 2014
@@ -220,10 +220,8 @@ public class IdpDAOJPATest {
     
     
     @Test(expected = DataIntegrityViolationException.class)
-    public void testTryAddExistingIdp() {
-        Idp idp = new Idp();
-        idp.setRealm("urn:org:apache:cxf:fediz:idp:realm-A");
-        
+    public void testTryAddExistingIdp() throws MalformedURLException {
+        Idp idp = createIdp("urn:org:apache:cxf:fediz:idp:realm-A");
         idpDAO.addIdp(idp);
     }
     
@@ -235,9 +233,8 @@ public class IdpDAOJPATest {
     
     
     @Test(expected = EmptyResultDataAccessException.class)
-    public void testRemoveExistingIdp() {
-        Idp idp = new Idp();
-        idp.setRealm("urn:org:apache:cxf:fediz:idp:testdelete");
+    public void testRemoveExistingIdp() throws MalformedURLException {
+        Idp idp = createIdp("urn:org:apache:cxf:fediz:idp:testdelete");
         
         idpDAO.addIdp(idp);
         

Modified: cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpDAOJPATest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpDAOJPATest.java?rev=1573654&r1=1573653&r2=1573654&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpDAOJPATest.java
(original)
+++ cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpDAOJPATest.java
Mon Mar  3 18:26:11 2014
@@ -160,8 +160,7 @@ public class TrustedIdpDAOJPATest {
     
     @Test(expected = DataIntegrityViolationException.class)
     public void testTryAddExistingTrustedIdp() {
-        TrustedIdp trustedIdp = new TrustedIdp();
-        trustedIdp.setRealm("urn:org:apache:cxf:fediz:idp:realm-B");
+        TrustedIdp trustedIdp = createTrustedIdp("urn:org:apache:cxf:fediz:idp:realm-B");
         trustedIdpDAO.addTrustedIDP(trustedIdp);
     }
     
@@ -175,8 +174,7 @@ public class TrustedIdpDAOJPATest {
     @Test(expected = EmptyResultDataAccessException.class)
     public void testRemoveExistingTrustedIdp() {
         String realm = "urn:org:apache:cxf:fediz:trusted-idp:testdelete";
-        TrustedIdp trustedIdp = new TrustedIdp();
-        trustedIdp.setRealm(realm);
+        TrustedIdp trustedIdp = createTrustedIdp(realm);
         
         trustedIdpDAO.addTrustedIDP(trustedIdp);
         



Mime
View raw message