Skip to content

Commit

Permalink
orcid-web tests should be working
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Jan 20, 2023
1 parent 25bc82a commit 096c7ba
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 155 deletions.
108 changes: 106 additions & 2 deletions orcid-api-common/src/main/resources/orcid-oauth2-api-common-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,74 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">


<!-- Message converters -->
<bean id="orcidJsonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list value-type="org.springframework.http.MediaType">
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="json" />
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="orcid+json" />
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="vnd.orcid+json" />
</bean>
</list>
</property>
<property name="prettyPrint" value="true" />
</bean>

<bean id="orcidXmlMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list value-type="org.springframework.http.MediaType">
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="xml" />
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="orcid+xml" />
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg type="java.lang.String" value="application" />
<constructor-arg type="java.lang.String" value="vnd.orcid+xml" />
</bean>
</list>
</property>
</bean>

<!-- OAUTH2 common configuration -->
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler">
<property name="exceptionRenderer" ref="oauthExceptionRenderer" />
</bean>

<bean id="oauthExceptionRenderer"
class="org.springframework.security.oauth2.provider.error.DefaultOAuth2ExceptionRenderer">
<property name="messageConverters">
<list>
<ref bean="orcidJsonMessageConverter" />
<ref bean="orcidXmlMessageConverter" />
</list>
</property>
</bean>

<bean id="orcidClientCredentialsChecker" class="org.orcid.core.oauth.OrcidClientCredentialsChecker">
<constructor-arg ref="oAuth2RequestFactory" />
</bean>

<!-- An extension of RandomValueAuthorizationCodeServices to create and
remove authorisation codes -->
<bean id="orcidAuthorizationCodeService"
class="org.orcid.core.oauth.service.OrcidAuthorizationCodeServiceImpl" />

<!-- As we have a Jersey endpoint, we need to create an extension to the
Spring MVC, so we use a delegator -->
<bean id="orcidClientCredentialEndPointDelegator"
Expand All @@ -13,6 +80,43 @@
<property name="clientDetailsService" ref="clientDetailsManager" />
</bean>

<bean id="oAuth2RequestFactory"
class="org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory">
<constructor-arg ref="clientDetailsManager" />
</bean>

<bean id="orcidRefreshTokenChecker" class="org.orcid.core.oauth.OrcidRefreshTokenChecker" />

<!-- TODO: code for token granters should be moved from the orcid-core to the orcid-api-common package -->
<!-- A token granter for the client credentials -->
<bean id="clientCredentialsTokenGranter" class="org.orcid.core.oauth.OrcidClientCredentialsTokenGranter">
<constructor-arg ref="tokenServices" />
<constructor-arg ref="orcidClientCredentialsChecker" />
</bean>

<!-- The 'granter responsible for returning and removing the auth codes -->
<bean id="authorizationCodeTokenGranter" class="org.orcid.core.oauth.OrcidAuthorizationCodeTokenGranter">
<constructor-arg ref="orcidAuthorizationCodeService" />
<constructor-arg ref="tokenServices" />
<constructor-arg ref="clientDetailsManager" />
<constructor-arg ref="oAuth2RequestFactory" />
</bean>

<bean id="orcidImplicitTokenGranter" class="org.orcid.core.oauth.OrcidImplicitTokenGranter">
<constructor-arg ref="tokenServices" />
<constructor-arg ref="clientDetailsManager" />
<constructor-arg ref="oAuth2RequestFactory" />
</bean>

<bean id="refreshTokenTokenGranter" class="org.orcid.core.oauth.OrcidRefreshTokenTokenGranter">
<constructor-arg ref="orcidRefreshTokenChecker" />
<constructor-arg ref="tokenServices" />
</bean>

<bean id="ietfExchangeTokenGranter" class="org.orcid.core.oauth.IETFExchangeTokenGranter">
<constructor-arg ref="tokenServices" />
</bean>

<!-- Use the composite granter to enable granting of tokens for both client
credentials and auth codes -->
<bean id="tokenGranter"
Expand All @@ -26,5 +130,5 @@
<ref bean="orcidImplicitTokenGranter" />
</list>
</constructor-arg>
</bean>
</bean>
</beans>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.orcid.core.oauth;
package org.orcid.api.common.oauth;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -22,6 +22,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.core.constants.OrcidOauth2Constants;
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
import org.orcid.core.oauth.OrcidRefreshTokenTokenGranter;
import org.orcid.persistence.dao.OrcidOauth2TokenDetailDao;
import org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail;
import org.orcid.persistence.jpa.entities.ProfileEntity;
Expand All @@ -36,7 +38,7 @@
import org.springframework.test.context.ContextConfiguration;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-core-context.xml", "classpath:orcid-oauth2-common-config.xml" })
@ContextConfiguration(locations = { "classpath:test-orcid-api-common-context.xml" })
public class OrcidRefreshTokenTokenGranterTest extends DBUnitTest {

private static final String CLIENT_ID_1 = "APP-5555555555555555";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ignore-unresolvable="true" />

<import resource="classpath*:orcid-core-context.xml"/>
<import resource="classpath*:orcid-oauth2-common-config.xml"/>
<import resource="classpath*:orcid-oauth2-api-common-config.xml"/>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.6.xsd
http://www.springframework.org/schema/security/oauth2 https://raw.githubusercontent.com/spring-attic/spring-security-oauth/main/spring-security-oauth2/src/main/resources/org/springframework/security/oauth2/spring-security-oauth2-2.0.xsd">

<import resource="classpath*:orcid-oauth2-common-config.xml"/>
<import resource="classpath*:orcid-oauth2-api-common-config.xml"/>

<sec:http-firewall ref="httpFirewall"/>
Expand Down
110 changes: 0 additions & 110 deletions orcid-core/src/main/resources/orcid-oauth2-common-config.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
<context:property-placeholder location="\${org.orcid.config.file.api.common}" ignore-resource-not-found="true" ignore-unresolvable="true" />
<context:property-placeholder location="\${org.orcid.config.file.api.internal}" ignore-resource-not-found="true" ignore-unresolvable="true" />

<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<import resource="classpath*:orcid-core-context.xml"/>
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->
<!-- TODO: LOOK AT IMPORTS HERE!!!! -->

<context:component-scan base-package="org.orcid.api.t2, org.orcid.api.common, org.orcid.core.security"/>
<aop:aspectj-autoproxy />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.6.xsd
http://www.springframework.org/schema/security/oauth2 https://raw.githubusercontent.com/spring-attic/spring-security-oauth/main/spring-security-oauth2/src/main/resources/org/springframework/security/oauth2/spring-security-oauth2-2.0.xsd">

<import resource="classpath*:orcid-oauth2-common-config.xml"/>
<import resource="classpath*:orcid-oauth2-api-common-config.xml"/>

<sec:http pattern="/static/**" security="none" create-session="stateless" />
Expand Down
2 changes: 1 addition & 1 deletion orcid-test/src/main/java/org/orcid/test/DBUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DBUnitTest {

private static final String API_COMMON_CONTEXT = "classpath:test-orcid-api-common-context.xml";

private static final String UI_CONTEXT = "classpath:test-frontend-web-servlet.xml";
private static final String UI_CONTEXT = "classpath:test-frontend-db-context.xml";

private static final String[] tables = new String[] { "profile", "orcid_social", "profile_event", "work", "researcher_url",
"given_permission_to", "external_identifier", "email", "email_event", "biography", "record_name", "other_name", "profile_keyword", "profile_patent",
Expand Down
Loading

0 comments on commit 096c7ba

Please sign in to comment.