Repository: cxf-fediz Updated Branches: refs/heads/master 56fc99ebe -> c8c08047e
[FEDIZ-122,FEDIZ-122] - Updating to Spring 4 + replacing bval Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/c8c08047 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/c8c08047 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/c8c08047 Branch: refs/heads/master Commit: c8c08047e163783db3633fb9bb41f613c9079e08 Parents: 56fc99e Author: Colm O hEigeartaigh <[email protected]> Authored: Wed May 20 13:55:30 2015 +0100 Committer: Colm O hEigeartaigh <[email protected]> Committed: Wed May 20 13:55:30 2015 +0100 ---------------------------------------------------------------------- pom.xml | 6 +- services/idp/pom.xml | 15 ++-- .../idp/service/jpa/ApplicationEntity.java | 2 +- .../ApplicationIdpProtocolSupportValidator.java | 58 ++++++++++++ .../jpa/ApplicationProtocolSupported.java | 47 ++++++++++ .../service/jpa/ProtocolSupportValidator.java | 92 -------------------- .../idp/service/jpa/ProtocolSupported.java | 51 ----------- .../idp/service/jpa/TrustedIdpEntity.java | 2 +- .../jpa/TrustedIdpProtocolSupportValidator.java | 58 ++++++++++++ .../jpa/TrustedIdpProtocolSupported.java | 47 ++++++++++ 10 files changed, 225 insertions(+), 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index fb89574..e8a4d7f 100644 --- a/pom.xml +++ b/pom.xml @@ -43,26 +43,26 @@ <cxf.build-utils.version>3.1.0</cxf.build-utils.version> <easymock.version>3.3</easymock.version> <ehcache.version>2.9.0</ehcache.version> + <hibernate.version>5.1.1.Final</hibernate.version> <httpclient.version>4.3.5</httpclient.version> <hsqldb.version>1.8.0.10</hsqldb.version> <htmlunit.version>2.15</htmlunit.version> <javassist.version>3.16.1-GA</javassist.version> + <javax.el.version>2.2</javax.el.version> <javax.validation.version>1.1.0.Final</javax.validation.version> <jericho.version>3.3</jericho.version> <jetty.version>8.1.12.v20130726</jetty.version> - <!--<jetty.version>7.6.8.v20121106</jetty.version>--> <junit.version>4.12</junit.version> <log4j.version>1.2.17</log4j.version> <ognl.version>3.0.8</ognl.version> <openjpa.version>2.3.0</openjpa.version> <servlet.version>2.5</servlet.version> <slf4j.version>1.7.9</slf4j.version> - <spring.version>3.2.6.RELEASE</spring.version> + <spring.version>4.1.6.RELEASE</spring.version> <spring.security.version>3.1.4.RELEASE</spring.security.version> <tomcat.version>7.0.54</tomcat.version> <wss4j.version>2.1.0</wss4j.version> <xalan.version>2.7.2</xalan.version> - <bval.version>0.5</bval.version> <tomcat.url>http://localhost:8080/manager/text</tomcat.url> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/pom.xml ---------------------------------------------------------------------- diff --git a/services/idp/pom.xml b/services/idp/pom.xml index 4285461..b32335c 100644 --- a/services/idp/pom.xml +++ b/services/idp/pom.xml @@ -227,15 +227,20 @@ <version>${javax.validation.version}</version> </dependency> <dependency> - <groupId>org.apache.bval</groupId> - <artifactId>bval-jsr303</artifactId> - <version>${bval.version}</version> - </dependency> - <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <version>${hibernate.version}</version> + </dependency> + <dependency> + <groupId>javax.el</groupId> + <artifactId>el-api</artifactId> + <version>${javax.el.version}</version> + </dependency> </dependencies> <build> <resources> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java index f78e08d..379dee8 100644 --- a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationEntity.java @@ -45,7 +45,7 @@ public class ApplicationEntity { // "http://docs.oa14sis-open.org/wsfed/federation/200706" // Metadata could provide more than one but one must be chosen @NotNull - @ProtocolSupported + @ApplicationProtocolSupported private String protocol; // Public key only http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationIdpProtocolSupportValidator.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationIdpProtocolSupportValidator.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationIdpProtocolSupportValidator.java new file mode 100644 index 0000000..edeafe5 --- /dev/null +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationIdpProtocolSupportValidator.java @@ -0,0 +1,58 @@ +/** + * 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.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import org.apache.cxf.fediz.service.idp.protocols.ProtocolController; +import org.apache.cxf.fediz.service.idp.spi.ApplicationProtocolHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +/** + * Validate that the protocol is a valid Application protocol + */ +@Component +public class ApplicationIdpProtocolSupportValidator + implements ConstraintValidator<ApplicationProtocolSupported, String> { + + @Autowired + @Qualifier("applicationProtocolControllerImpl") + private ProtocolController<ApplicationProtocolHandler> applicationProtocolHandlers; + + @Override + public boolean isValid(String object, ConstraintValidatorContext constraintContext) { + + List<String> protocols = applicationProtocolHandlers.getProtocols(); + if (protocols.contains(object)) { + return true; + } + + return false; + } + + @Override + public void initialize(ApplicationProtocolSupported constraintAnnotation) { + } + +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationProtocolSupported.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationProtocolSupported.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationProtocolSupported.java new file mode 100644 index 0000000..6dc69a5 --- /dev/null +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ApplicationProtocolSupported.java @@ -0,0 +1,47 @@ +/** + * 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.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import javax.validation.Constraint; +import javax.validation.Payload; + +@Target({ METHOD, FIELD, ANNOTATION_TYPE }) +@Retention(RUNTIME) +@Constraint(validatedBy = ApplicationIdpProtocolSupportValidator.class) +@Documented +public @interface ApplicationProtocolSupported { + + String message() default "{Protocol not supported}"; + + Class<?>[] groups() default { }; + + Class<? extends Payload>[] payload() default { }; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupportValidator.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupportValidator.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupportValidator.java deleted file mode 100644 index ef35ec5..0000000 --- a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupportValidator.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * 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.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -import org.apache.bval.jsr303.ConstraintValidatorContextImpl; -import org.apache.cxf.fediz.service.idp.protocols.ProtocolController; -import org.apache.cxf.fediz.service.idp.spi.ApplicationProtocolHandler; -import org.apache.cxf.fediz.service.idp.spi.TrustedIdpProtocolHandler; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -@Component -public class ProtocolSupportValidator implements ConstraintValidator<ProtocolSupported, String> { - - private static final Logger LOG = LoggerFactory.getLogger(ProtocolSupportValidator.class); - - @Autowired - // Qualifier workaround. See http://www.jayway.com/2013/11/03/spring-and-autowiring-of-generic-types/ - @Qualifier("trustedIdpProtocolControllerImpl") - private ProtocolController<TrustedIdpProtocolHandler> trustedIdpProtocolHandlers; - - @Autowired - @Qualifier("applicationProtocolControllerImpl") - private ProtocolController<ApplicationProtocolHandler> applicationProtocolHandlers; - - - /* - public ProtocolSupportValidator() { - try { - throw new Exception("test"); - } catch (Exception ex) { - LOG.error("", ex); - } - } - */ - - @Override - public boolean isValid(String object, ConstraintValidatorContext constraintContext) { - - - ConstraintValidatorContextImpl x = (ConstraintValidatorContextImpl)constraintContext; - Class<?> owner = x.getValidationContext().getCurrentOwner(); - - List<String> protocols = null; - if (owner.equals(TrustedIdpEntity.class)) { - protocols = trustedIdpProtocolHandlers.getProtocols(); - } else if (owner.equals(ApplicationEntity.class)) { - protocols = applicationProtocolHandlers.getProtocols(); - } else { - LOG.warn("Invalid owner {}. Ignoring validation.", owner.getCanonicalName()); - return true; - } - - for (String protocol : protocols) { - if (protocol.equals(object)) { - return true; - } - } - return false; - } - - @Override - public void initialize(ProtocolSupported constraintAnnotation) { - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupported.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupported.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupported.java deleted file mode 100644 index 29dc312..0000000 --- a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/ProtocolSupported.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import javax.validation.Constraint; -import javax.validation.Payload; - - - -@Target({ METHOD, FIELD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Constraint(validatedBy = ProtocolSupportValidator.class) -@Documented -public @interface ProtocolSupported { - - String message() default "{Protocol not supported}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java index 848bbfb..0054b7e 100644 --- a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpEntity.java @@ -67,7 +67,7 @@ public class TrustedIdpEntity { //Could be read from Metadata, RoleDescriptor protocolSupportEnumeration= // "http://docs.oasis-open.org/wsfed/federation/200706" // Metadata could provide more than one but one must be chosen - @ProtocolSupported + @TrustedIdpProtocolSupported private String protocol; //FederateIdentity, FederateClaims http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupportValidator.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupportValidator.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupportValidator.java new file mode 100644 index 0000000..98d4cd2 --- /dev/null +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupportValidator.java @@ -0,0 +1,58 @@ +/** + * 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.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import org.apache.cxf.fediz.service.idp.protocols.ProtocolController; +import org.apache.cxf.fediz.service.idp.spi.TrustedIdpProtocolHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +/** + * Validate that the protocol is a valid IdP protocol + */ +@Component +public class TrustedIdpProtocolSupportValidator implements ConstraintValidator<TrustedIdpProtocolSupported, String> { + + @Autowired + // Qualifier workaround. See http://www.jayway.com/2013/11/03/spring-and-autowiring-of-generic-types/ + @Qualifier("trustedIdpProtocolControllerImpl") + private ProtocolController<TrustedIdpProtocolHandler> trustedIdpProtocolHandlers; + + @Override + public boolean isValid(String object, ConstraintValidatorContext constraintContext) { + + List<String> protocols = trustedIdpProtocolHandlers.getProtocols(); + if (protocols.contains(object)) { + return true; + } + + return false; + } + + @Override + public void initialize(TrustedIdpProtocolSupported constraintAnnotation) { + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/c8c08047/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupported.java ---------------------------------------------------------------------- diff --git a/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupported.java b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupported.java new file mode 100644 index 0000000..9c32af3 --- /dev/null +++ b/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/TrustedIdpProtocolSupported.java @@ -0,0 +1,47 @@ +/** + * 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.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import javax.validation.Constraint; +import javax.validation.Payload; + +@Target({ METHOD, FIELD, ANNOTATION_TYPE }) +@Retention(RUNTIME) +@Constraint(validatedBy = TrustedIdpProtocolSupportValidator.class) +@Documented +public @interface TrustedIdpProtocolSupported { + + String message() default "{Protocol not supported}"; + + Class<?>[] groups() default { }; + + Class<? extends Payload>[] payload() default { }; + +} \ No newline at end of file
