Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scopes and authorities to the authorization code table #7079

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3279481
Deactivated records should get 409 on GET requests
amontenegro Feb 27, 2024
b3660c2
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Feb 28, 2024
2cc66ab
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 1, 2024
f2dc713
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 4, 2024
b4f8223
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 7, 2024
b0026c3
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 12, 2024
53e7616
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 19, 2024
bf82372
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Mar 25, 2024
23b6afb
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 4, 2024
182c67d
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 4, 2024
c52ef13
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 8, 2024
d4f779b
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 8, 2024
27b0033
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 17, 2024
585b896
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Apr 18, 2024
9c9dfef
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro May 8, 2024
42ac636
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro May 28, 2024
3f0d771
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jun 10, 2024
e65ec79
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jun 20, 2024
e69191a
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jun 24, 2024
cff8029
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 3, 2024
ddf3e67
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 4, 2024
a091bb3
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 5, 2024
97024f0
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 15, 2024
3201e7e
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 18, 2024
c85de91
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 22, 2024
3132245
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Jul 30, 2024
3672cfd
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 6, 2024
6ef71b1
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 12, 2024
3ccccec
Sequence should start at 100000
amontenegro Aug 12, 2024
50b85a9
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 12, 2024
3338fbb
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 13, 2024
ebd6d1c
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 16, 2024
13e0a6f
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 19, 2024
ca4085d
Merge branch 'main' of https://github.com/ORCID/ORCID-Source
amontenegro Aug 30, 2024
a4e5704
Lets store the scopes and authrities directly into the auth code table
amontenegro Aug 30, 2024
1dba8a8
Add authorization_uri to the authorization code table
amontenegro Aug 30, 2024
56d0161
Change name
amontenegro Aug 30, 2024
de445a1
Add a field to store the short auth code
amontenegro Aug 30, 2024
ec09931
Storing the spring security request id, still not sure why we need it…
amontenegro Aug 31, 2024
72d4221
Shorter id names
amontenegro Aug 31, 2024
bad7061
Adding auth code expiration time
amontenegro Aug 31, 2024
538e0ba
Add the authorization state attribute field
amontenegro Sep 2, 2024
b616230
We dont need to store the short auth code in a different field
amontenegro Sep 5, 2024
f19e778
Adding spring session redis
amontenegro Sep 13, 2024
afd8239
This should be rolled back
amontenegro Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion orcid-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,18 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.4.3</version>
<version>3.7.1</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
</dependency>


</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
Expand Down Expand Up @@ -31,7 +35,7 @@ public class RedisClient {
private final String redisPassword;
private final int cacheExpiryInSecs;
private final int clientTimeoutInMillis;
private JedisPool pool;
public JedisPool pool;
private SetParams defaultSetParams;

@Resource
Expand Down Expand Up @@ -67,7 +71,7 @@ public RedisClient(String redisHost, int redisPort, String password, int cacheEx
@PostConstruct
private void init() {
try {
JedisClientConfig config = DefaultJedisClientConfig.builder().connectionTimeoutMillis(this.clientTimeoutInMillis).timeoutMillis(this.clientTimeoutInMillis)
JedisClientConfig config = DefaultJedisClientConfig.builder().connectionTimeoutMillis(this.clientTimeoutInMillis)
.socketTimeoutMillis(this.clientTimeoutInMillis).password(this.redisPassword).ssl(true).build();
pool = new JedisPool(new HostAndPort(this.redisHost, this.redisPort), config);
defaultSetParams = new SetParams().ex(this.cacheExpiryInSecs);
Expand Down Expand Up @@ -141,4 +145,33 @@ public boolean remove(String key) {
}
return true;
}

public static void main(String [] args) {
RedisClient client = new RedisClient("reg-qa-redis-001.reg-qa-redis.3zksuc.use2.cache.amazonaws.com", 6379, "aVerySimpleToken");
client.init();
System.out.println("Connected");
Jedis r = client.pool.getResource();

Set<String> keys = r.keys("spring:session:sessions:*");

for(String key : keys) {
System.out.println("----------------------------------------------");
System.out.println(key);
String keyType = r.type(key);
System.out.println(keyType);
if("hash".equals(keyType)) {
Map<String, String> myMap = r.hgetAll(key);
for(String tkey : myMap.keySet()) {
System.out.println(tkey + ": " + myMap.get(tkey));
}
}
if("string".equals(keyType)) {
System.out.println(key + ": " + r.get("key"));
}
System.out.println("----------------------------------------------");
}



}
}
1 change: 1 addition & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,5 @@
<include file="/db/updates/create_profile_email_domain_table.xml" />
<include file="/db/updates/create_dw_notification.xml" />
<include file="/db/updates/create_dw_profile_email_domain.xml" />
<include file="/db/updates/oauth2_authoriziation_code_detail_improvements.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet author="Angel Montenegro" id="ADD-SCOPES">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="scopes"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="scopes" type="VARCHAR(255)" />
</addColumn>
</changeSet>

<changeSet author="Angel Montenegro" id="ADD-AUTHORITIES">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="authorities"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="authorities" type="VARCHAR(255)" />
</addColumn>
</changeSet>

<changeSet author="Angel Montenegro" id="ADD-AUTHORIZATION-STATE-ATTRIBUTE">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="authorization_state_attribute"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="authorization_state_attribute" type="VARCHAR(500)" />
</addColumn>
</changeSet>

<changeSet author="Angel Montenegro" id="ADD-AUTHORIZATION-URI">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="authorization_request_uri"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="authorization_request_uri" type="VARCHAR(2500)" />
</addColumn>
</changeSet>

<changeSet author="Angel Montenegro" id="ADD-SPRING-AUHT-CODE-REQ-ID">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="spring_authorization_code_request_id"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="spring_authorization_code_request_id" type="VARCHAR(255)" />
</addColumn>
</changeSet>

<changeSet author="Angel Montenegro" id="ADD-SPRING-AUHT-CODE-EXPIRES-AT">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="oauth2_authoriziation_code_detail" columnName="authorization_code_expires_at"/>
</not>
</preConditions>
<addColumn tableName="oauth2_authoriziation_code_detail">
<column name="authorization_code_expires_at" type="TIMESTAMP WITH TIME ZONE" />
</addColumn>
</changeSet>

</databaseChangeLog>
12 changes: 12 additions & 0 deletions orcid-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.6.4</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-agroal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.orcid.frontend.spring.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.security.jackson2.SecurityJackson2Modules;

@Configuration
public class OrcidBeanClassLoaderAware implements BeanClassLoaderAware {
private ClassLoader loader;

@Bean
public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
return new GenericJackson2JsonRedisSerializer(objectMapper());
}

/**
* Customized {@link ObjectMapper} to add mix-in for class that doesn't have default
* constructors
* @return the {@link ObjectMapper} to use
*/
private ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(SecurityJackson2Modules.getModules(this.loader));
return mapper;
}

@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.loader = classLoader;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.orcid.frontend.spring.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.JedisClientConfig;

import java.time.Duration;

@Configuration
@EnableRedisHttpSession
public class SessionCacheConfig extends AbstractHttpSessionApplicationInitializer {

@Value("${org.orcid.core.utils.cache.redis.host}")
private String host;
@Value("${org.orcid.core.utils.cache.redis.port}")
private int port;
@Value("${org.orcid.core.utils.cache.redis.password}")
private String password;
@Value("${org.orcid.core.utils.cache.redis.connection_timeout_millis:10000}")
private int connectionTimeoutMillis;


@Bean
public JedisConnectionFactory connectionFactory() {
Duration timeoutDuration = Duration.ofMillis(connectionTimeoutMillis);

RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(password);

JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfigurationBuilder = JedisClientConfiguration.builder();
jedisClientConfigurationBuilder.useSsl().and().connectTimeout(timeoutDuration).build();

return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfigurationBuilder.build());
}

@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.orcid.frontend.spring.session;

import org.springframework.data.redis.core.RedisOperations;
import org.springframework.session.data.redis.RedisSessionRepository;

public class OrcidRedisSessionRepository extends RedisSessionRepository {

public OrcidRedisSessionRepository(RedisOperations<String, Object> sessionRedisOperations) {
super(sessionRedisOperations);
}

}
Loading
Loading