Repository: cxf Updated Branches: refs/heads/3.1.x-fixes c43c29880 -> 88cde3652
http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/pom.xml ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/pom.xml b/rt/rs/security/sso/oidc/pom.xml index 0fd2844..c09336b 100644 --- a/rt/rs/security/sso/oidc/pom.xml +++ b/rt/rs/security/sso/oidc/pom.xml @@ -17,152 +17,248 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-rt-rs-security-sso-oidc</artifactId> - <packaging>bundle</packaging> - <name>Apache CXF Runtime OpenId Connect</name> - <description>Apache CXF Runtime OpenId Connect</description> - <url>http://cxf.apache.org</url> - <parent> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-parent</artifactId> - <version>3.1.8-SNAPSHOT</version> - <relativePath>../../../../../parent/pom.xml</relativePath> - </parent> - <properties> - <hibernate.em.version>4.1.0.Final</hibernate.em.version> - <hsqldb.version>1.8.0.10</hsqldb.version> - </properties> - <dependencies> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-security-oauth2</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-security-jose-jaxrs</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - <version>${cxf.geronimo.jpa.version}</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <!--test dependencies--> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>${hsqldb.version}</version> - <scope>test</scope> - </dependency> - <!-- - <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - <version>${cxf.openjpa.version}</version> - <scope>provided</scope> - </dependency> - --> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <version>${hibernate.em.version}</version> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.bsc.maven</groupId> - <artifactId>maven-processor-plugin</artifactId> - <version>3.1.0</version> - <executions> - <execution> - <id>process</id> - <goals> - <goal>process</goal> - </goals> - <phase>generate-sources</phase> - <configuration> - <compilerArguments>-Aopenjpa.source=7 -Aopenjpa.metamodel=true</compilerArguments> - <processors> - <processor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</processor> - </processors> - <outputDirectory>target/generated-sources/metamodel</outputDirectory> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - <version>${cxf.openjpa.version}</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.10</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>target/generated-sources/metamodel</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - <!-- - <plugin> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa-maven-plugin</artifactId> - <version>${cxf.openjpa.version}</version> - <configuration> - <includes> - org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.class, - org/apache/cxf/rs/security/oauth2/common/Client.class, - org/apache/cxf/rs/security/oauth2/common/UserSubject.class, - org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrant, - org/apache/cxf/rs/security/oauth2/grants/code/ServerAuthorizationCodeGrant.class, - org/apache/cxf/rs/security/oauth2/tokens/bearer/BearerAccessToken.class, - org/apache/cxf/rs/security/oauth2/common/ServerAccessToken.class, - org/apache/cxf/rs/security/oauth2/common/AccessToken.class, - org/apache/cxf/rs/security/oauth2/tokens/refresh/RefreshToken.class, - org/apache/cxf/rs/security/oauth2/common/OAuthPermission.class - </includes> - </configuration> - <executions> - <execution> - <id>enhancer</id> - <phase>process-test-classes</phase> - <goals> - <goal>test-enhance</goal> - </goals> - </execution> - </executions> - </plugin> - --> - </plugins> - </build> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-rt-rs-security-sso-oidc</artifactId> + <packaging>bundle</packaging> + <name>Apache CXF Runtime OpenId Connect</name> + <description>Apache CXF Runtime OpenId Connect</description> + <url>http://cxf.apache.org</url> + <parent> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-parent</artifactId> + <version>3.1.8-SNAPSHOT</version> + <relativePath>../../../../../parent/pom.xml</relativePath> + </parent> + <properties> + <hibernate.em.version>4.1.0.Final</hibernate.em.version> + <hsqldb.version>1.8.0.10</hsqldb.version> + </properties> + <dependencies> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-security-oauth2</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-security-jose-jaxrs</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jpa_2.0_spec</artifactId> + <version>${cxf.geronimo.jpa.version}</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <!--test dependencies--> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>${hsqldb.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + <version>${cxf.openjpa.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>${hibernate.em.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-ehcache</artifactId> + <version>${hibernate.em.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${cxf.spring.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${cxf.spring.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${cxf.spring.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${cxf.spring.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + <version>${cxf.spring.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>1.8.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>${cxf.slf4j.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.bsc.maven</groupId> + <artifactId>maven-processor-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>process</id> + <goals> + <goal>process</goal> + </goals> + <phase>generate-sources</phase> + <configuration> + <compilerArguments>-Aopenjpa.source=7 -Aopenjpa.metamodel=true</compilerArguments> + <processors> + <processor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</processor> + </processors> + <outputDirectory>target/generated-sources/metamodel</outputDirectory> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + <version>${cxf.openjpa.version}</version> + </dependency> + </dependencies> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.10</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>target/generated-sources/metamodel</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <!-- + <plugin> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa-maven-plugin</artifactId> + <version>${cxf.openjpa.version}</version> + <configuration> + <includes> + org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.class, + org/apache/cxf/rs/security/oauth2/common/Client.class, + org/apache/cxf/rs/security/oauth2/common/UserSubject.class, + org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrant, + org/apache/cxf/rs/security/oauth2/grants/code/ServerAuthorizationCodeGrant.class, + org/apache/cxf/rs/security/oauth2/tokens/bearer/BearerAccessToken.class, + org/apache/cxf/rs/security/oauth2/common/ServerAccessToken.class, + org/apache/cxf/rs/security/oauth2/common/AccessToken.class, + org/apache/cxf/rs/security/oauth2/tokens/refresh/RefreshToken.class, + org/apache/cxf/rs/security/oauth2/common/OAuthPermission.class + </includes> + </configuration> + <executions> + <execution> + <id>enhancer</id> + <phase>process-test-classes</phase> + <goals> + <goal>test-enhance</goal> + </goals> + </execution> + </executions> + </plugin> + --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>3.0.1</version> + <executions> + <execution> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <!-- this configures the surefire plugin to run your tests with the javaagent enabled --> + <!-- (openJPA loadtime weaving) --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-javaagent:${project.basedir}/target/openjpa-${cxf.openjpa.version}.jar</argLine> + <workingDirectory>${project.basedir}/target</workingDirectory> + </configuration> + </plugin> + <!-- this tells maven to copy the openjpa agent jar into your target/ directory --> + <!-- where surefire can see it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy</id> + <phase>process-resources</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + <version>${cxf.openjpa.version}</version> + <outputDirectory>${project.build.directory}</outputDirectory> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java index cea5319..c0c4b97 100644 --- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java @@ -18,7 +18,10 @@ */ package org.apache.cxf.rs.security.oidc.idp; +import javax.persistence.Basic; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Lob; import org.apache.cxf.rs.security.oauth2.common.UserSubject; import org.apache.cxf.rs.security.oidc.common.IdToken; @@ -26,34 +29,41 @@ import org.apache.cxf.rs.security.oidc.common.UserInfo; @Entity public class OidcUserSubject extends UserSubject { - + private static final long serialVersionUID = 8806727177012442229L; + private IdToken idToken; + private UserInfo userInfo; - + public OidcUserSubject() { - + } - + public OidcUserSubject(String login) { super(login); } - - public OidcUserSubject(String login, String id) { + + public OidcUserSubject(String login, String id) { super(login, id); } - + public OidcUserSubject(UserSubject sub) { super(sub); } - + + @Lob + @Basic(fetch = FetchType.EAGER) public IdToken getIdToken() { return idToken; } + public void setIdToken(IdToken idToken) { this.idToken = idToken; } + @Lob + @Basic(fetch = FetchType.EAGER) public UserInfo getUserInfo() { return userInfo; } http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTOpenJPATest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTOpenJPATest.java b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTOpenJPATest.java new file mode 100644 index 0000000..50d0ddd --- /dev/null +++ b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTOpenJPATest.java @@ -0,0 +1,55 @@ +/** + * 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.rs.security.oidc.idp; + +import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("JPAOidcUserSubjectCMTTest.xml") +@DirtiesContext +@ActiveProfiles("openJPA") +public class JPAOidcUserSubjectCMTOpenJPATest extends JPAOidcUserSubjectTest { + + @Autowired + private JPAOAuthDataProvider oauthProvider; + + @Override + protected JPAOAuthDataProvider getProvider() { + return this.oauthProvider; + } + + @Before + @Override + public void setUp() { + initializeProvider(oauthProvider); + } + + @After + @Override + public void tearDown() { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.java b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.java new file mode 100644 index 0000000..00495e1 --- /dev/null +++ b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.java @@ -0,0 +1,55 @@ +/** + * 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.rs.security.oidc.idp; + +import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("JPAOidcUserSubjectCMTTest.xml") +@DirtiesContext +@ActiveProfiles("hibernate") +public class JPAOidcUserSubjectCMTTest extends JPAOidcUserSubjectTest { + + @Autowired + private JPAOAuthDataProvider oauthProvider; + + @Override + protected JPAOAuthDataProvider getProvider() { + return this.oauthProvider; + } + + @Before + @Override + public void setUp() { + initializeProvider(oauthProvider); + } + + @After + @Override + public void tearDown() { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectOpenJPATest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectOpenJPATest.java b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectOpenJPATest.java new file mode 100644 index 0000000..4c7031c --- /dev/null +++ b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectOpenJPATest.java @@ -0,0 +1,27 @@ +/** + * 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.rs.security.oidc.idp; + +public class JPAOidcUserSubjectOpenJPATest extends JPAOidcUserSubjectTest { + + @Override + protected String getPersistenceUnitName() { + return "testUnitOpenJPA"; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectTest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectTest.java b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectTest.java index 4b18902..b6280d4 100644 --- a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectTest.java +++ b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectTest.java @@ -18,11 +18,7 @@ */ package org.apache.cxf.rs.security.oidc.idp; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.Collections; - -import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; @@ -31,7 +27,6 @@ import org.apache.cxf.rs.security.oauth2.common.Client; import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken; import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProvider; import org.apache.cxf.rs.security.oidc.common.IdToken; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -39,30 +34,33 @@ import org.junit.Test; public class JPAOidcUserSubjectTest extends Assert { private EntityManagerFactory emFactory; - private Connection connection; private JPAOAuthDataProvider provider; + @Before public void setUp() throws Exception { try { - Class.forName("org.hsqldb.jdbcDriver"); - connection = DriverManager.getConnection("jdbc:hsqldb:mem:oauth-jpa", "sa", ""); - } catch (Exception ex) { - ex.printStackTrace(); - fail("Exception during HSQL database init."); - } - try { - emFactory = Persistence.createEntityManagerFactory("testUnitHibernate"); - EntityManager em = emFactory.createEntityManager(); + emFactory = Persistence.createEntityManagerFactory(getPersistenceUnitName()); provider = new JPAOAuthDataProvider(); - provider.setEntityManager(em); - provider.setSupportedScopes(Collections.singletonMap("a", "A Scope")); - provider.setSupportedScopes(Collections.singletonMap("refreshToken", "RefreshToken")); + provider.setEntityManagerFactory(emFactory); + initializeProvider(provider); } catch (Exception ex) { ex.printStackTrace(); fail("Exception during JPA EntityManager creation."); } } + protected JPAOAuthDataProvider getProvider() { + return provider; + } + + protected void initializeProvider(JPAOAuthDataProvider oauthDataProvider) { + oauthDataProvider.setSupportedScopes(Collections.singletonMap("a", "A Scope")); + oauthDataProvider.setSupportedScopes(Collections.singletonMap("refreshToken", "RefreshToken")); + } + + protected String getPersistenceUnitName() { + return "testUnitHibernate"; + } @Test public void testAccessTokenWithOidcUserSubject() { @@ -79,8 +77,8 @@ public class JPAOidcUserSubjectTest extends Assert { oidcSubject.setIdToken(idToken); atr.setSubject(oidcSubject); - ServerAccessToken at = provider.createAccessToken(atr); - ServerAccessToken at2 = provider.getAccessToken(at.getTokenKey()); + ServerAccessToken at = getProvider().createAccessToken(atr); + ServerAccessToken at2 = getProvider().getAccessToken(at.getTokenKey()); assertEquals(at.getTokenKey(), at2.getTokenKey()); OidcUserSubject oidcSubject2 = (OidcUserSubject)at2.getSubject(); @@ -93,8 +91,8 @@ public class JPAOidcUserSubjectTest extends Assert { oidcSubject3.setIdToken(idToken2); atr.setSubject(oidcSubject3); - ServerAccessToken at3 = provider.createAccessToken(atr); - ServerAccessToken at4 = provider.getAccessToken(at3.getTokenKey()); + ServerAccessToken at3 = getProvider().createAccessToken(atr); + ServerAccessToken at4 = getProvider().getAccessToken(at3.getTokenKey()); OidcUserSubject oidcSubject4 = (OidcUserSubject)at4.getSubject(); assertEquals(c.getClientId(), oidcSubject4.getIdToken().getAudience()); } @@ -105,28 +103,26 @@ public class JPAOidcUserSubjectTest extends Assert { c.setRedirectUris(Collections.singletonList("http://client/redirect")); c.setClientId(clientId); c.setResourceOwnerSubject(new OidcUserSubject(userLogin)); - provider.setClient(c); + getProvider().setClient(c); return c; } @After public void tearDown() throws Exception { try { - if (provider != null) { - provider.close(); - } - if (emFactory != null) { - emFactory.close(); + if (getProvider() != null) { + getProvider().close(); } } catch (Throwable ex) { ex.printStackTrace(); } finally { try { - connection.createStatement().execute("SHUTDOWN"); + if (getProvider() != null) { + getProvider().close(); + } } catch (Throwable ex) { ex.printStackTrace(); } } } - } http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/resources/META-INF/persistence.xml b/rt/rs/security/sso/oidc/src/test/resources/META-INF/persistence.xml index 0966633..afb1a12 100644 --- a/rt/rs/security/sso/oidc/src/test/resources/META-INF/persistence.xml +++ b/rt/rs/security/sso/oidc/src/test/resources/META-INF/persistence.xml @@ -2,51 +2,56 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> - <persistence-unit name="testUnitHibernate" transaction-type="RESOURCE_LOCAL"> - <provider>org.hibernate.ejb.HibernatePersistence</provider> - <class>org.apache.cxf.rs.security.oidc.idp.OidcUserSubject</class> - <class>org.apache.cxf.rs.security.oauth2.common.Client</class> - <class>org.apache.cxf.rs.security.oauth2.common.UserSubject</class> - <class>org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant</class> - <class>org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant</class> - <class>org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.ServerAccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.AccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.OAuthPermission</class> - <class>org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken</class> - <exclude-unlisted-classes>true</exclude-unlisted-classes> - <properties> - <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:oauth-jpa"/> - <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> - <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> - <property name="hibernate.hbm2ddl.auto" value="create-drop"/> - <property name="hibernate.connection.username" value="sa"/> - <property name="hibernate.connection.password" value=""/> - <property name="javax.persistence.validation.mode" value="none"/> - </properties> - </persistence-unit> - <!-- - <persistence-unit name="testUnitOpenJPA" transaction-type="RESOURCE_LOCAL"> - <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> - <class>org.apache.cxf.rs.security.oidc.idp.OidcUserSubject</class> - <class>org.apache.cxf.rs.security.oauth2.common.Client</class> - <class>org.apache.cxf.rs.security.oauth2.common.UserSubject</class> - <class>org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant</class> - <class>org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant</class> - <class>org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.ServerAccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.AccessToken</class> - <class>org.apache.cxf.rs.security.oauth2.common.OAuthPermission</class> - <class>org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken</class> - <exclude-unlisted-classes>true</exclude-unlisted-classes> - <properties> - <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:oauth-jpa"/> - <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/> - <property name="openjpa.jdbc.DBDictionary" value="hsql" /> - <property name="openjpa.ConnectionUserName" value="sa"/> - <property name="openjpa.ConnectionPassword" value=""/> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/> - </properties> + <persistence-unit name="testUnitHibernate" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>org.apache.cxf.rs.security.oidc.idp.OidcUserSubject</class> + <class>org.apache.cxf.rs.security.oauth2.common.Client</class> + <class>org.apache.cxf.rs.security.oauth2.common.UserSubject</class> + <class>org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant</class> + <class>org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant</class> + <class>org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.ServerAccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.AccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.OAuthPermission</class> + <class>org.apache.cxf.rs.security.oauth2.common.Permission</class> + <class>org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken</class> + <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> + <properties> + <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:oauth-jpa"/> + <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> + <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="hibernate.connection.username" value="sa"/> + <property name="hibernate.connection.password" value=""/> + <property name="javax.persistence.validation.mode" value="none"/> + <property name="hibernate.cache.region.factory_class" + value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/> + <property name="hibernate.max_fetch_depth" value="3"/> + </properties> </persistence-unit> - --> + + <persistence-unit name="testUnitOpenJPA" transaction-type="RESOURCE_LOCAL"> + <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> + <class>org.apache.cxf.rs.security.oidc.idp.OidcUserSubject</class> + <class>org.apache.cxf.rs.security.oauth2.common.Client</class> + <class>org.apache.cxf.rs.security.oauth2.common.UserSubject</class> + <class>org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant</class> + <class>org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant</class> + <class>org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.ServerAccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.AccessToken</class> + <class>org.apache.cxf.rs.security.oauth2.common.OAuthPermission</class> + <class>org.apache.cxf.rs.security.oauth2.common.Permission</class> + <class>org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken</class> + <exclude-unlisted-classes>true</exclude-unlisted-classes> + <properties> + <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:oauth-jpa"/> + <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/> + <property name="openjpa.jdbc.DBDictionary" value="hsql" /> + <property name="openjpa.ConnectionUserName" value="sa"/> + <property name="openjpa.ConnectionPassword" value=""/> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/> + </properties> + </persistence-unit> + </persistence> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/88cde365/rt/rs/security/sso/oidc/src/test/resources/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.xml ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/test/resources/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.xml b/rt/rs/security/sso/oidc/src/test/resources/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.xml new file mode 100644 index 0000000..c80434a --- /dev/null +++ b/rt/rs/security/sso/oidc/src/test/resources/org/apache/cxf/rs/security/oidc/idp/JPAOidcUserSubjectCMTTest.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:aop="http://www.springframework.org/schema/aop" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/aop + http://www.springframework.org/schema/aop/spring-aop.xsd + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util.xsd"> + + + <bean id="oauthProvider" + class="org.apache.cxf.rs.security.oauth2.grants.code.JPACMTCodeDataProvider" + init-method="init" destroy-method="close"> + </bean> + + + <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> + <property name="entityManagerFactory" ref="entityManagerFactory"/> + </bean> + + <tx:annotation-driven transaction-manager="transactionManager"/> + + <aop:config proxy-target-class="true"> + <aop:pointcut id="oauthProviderOperation" + expression="bean(oauthProvider)"/> + <aop:advisor advice-ref="txAdvice" pointcut-ref="oauthProviderOperation"/> + </aop:config> + <tx:advice id="txAdvice" transaction-manager="transactionManager"> + <tx:attributes> + <tx:method name="*"/> + </tx:attributes> + </tx:advice> + + <beans profile="hibernate"> + <bean id="entityManagerFactory" + class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> + <!-- + <property name="dataSource" ref="dataSource"/> + --> + <!--<property name="jpaVendorAdapter">--> + <!--<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">--> + <!--<property name="showSql" value="true"/>--> + <!--<property name="generateDdl" value="true"/>--> + <!--</bean>--> + <!--</property>--> + <property name="persistenceUnitName" value="testUnitHibernate"/> + <property name="jpaPropertyMap"> + <map> + <entry key="hibernate.jdbc.fetch_size" value="400"/> + <entry key="hibernate.jdbc.batch_size" value="100"/> + <!--<entry key="hibernate.cache.use_second_level_cache" value="true"/>--> + <!--<entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>--> + </map> + </property> + </bean> + </beans> + + <beans profile="openJPA"> + <bean id="entityManagerFactory" + class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> + <!-- + <property name="dataSource" ref="dataSource"/> + --> + <!--<property name="jpaVendorAdapter">--> + <!--<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">--> + <!--<property name="showSql" value="true"/>--> + <!--<property name="generateDdl" value="true"/>--> + <!--</bean>--> + <!--</property>--> + <property name="persistenceUnitName" value="testUnitOpenJPA"/> + <!-- + <property name="loadTimeWeaver"> + <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/> + </property> + --> + <!--<property name="jpaPropertyMap">--> + <!--<map>--> + <!--<entry key="openjpa.Log" value="slf4j"/>--> + <!--<entry key="openjpa.Log" value="SQL=TRACE"/>--> + <!--<entry key="openjpa.ConnectionFactoryProperties"--> + <!--value="PrintParameters=true, PrettyPrint=true, PrettyPrintLineLength=80"/>--> + <!--<entry key="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>--> + <!--</map>--> + </bean> + </beans> +</beans> \ No newline at end of file
