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

Upgrade Spring boot to 2.0.2.RELEASE and spring security to 2.3.3.RELEASE #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ build/
nbbuild/
dist/
nbdist/
.nb-gradle/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline please.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be automatically fixed for you when you do a git pull.

.nb-gradle/

.DS_Store
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
coverallsVersion = '2.8.1'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.kt3k.gradle.plugin:coveralls-gradle-plugin:${coverallsVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'maven'

version = '0.0.1-SNAPSHOT'
group = 'mertz.security'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group = 'com.github.mert-z'
This will be automatically fixed for you when you do a git pull.


sourceCompatibility = 1.8

repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-release'
}
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile('org.springframework.security.oauth:spring-security-oauth2')
compile('org.springframework.data:spring-data-cassandra:2.0.10.RELEASE')
compile('org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE')
compile('com.fasterxml.jackson.core:jackson-databind:2.9.0')
compile('com.fasterxml.jackson.core:jackson-annotations:2.9.0')
compile('com.fasterxml.jackson.core:jackson-core:2.9.0')

testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('org.springframework.boot:spring-boot-starter-test:2.0.2.RELEASE')
testCompile('org.springframework.security:spring-security-test:5.0.8.RELEASE')
testCompile('org.cassandraunit:cassandra-unit-spring:3.1.3.2')
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'spring-oauth2-cassandra-token-store'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline please

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public AuthenticationKeyGenerator getAuthenticationKeyGenerator() {
return new DefaultAuthenticationKeyGenerator();
}

@Bean
public ObjectMapper getObjectMapper() {
return new ObjectMapper();
}

public static OAuth2AccessToken deserializeOAuth2AccessToken(String jsonOAuth2AccessToken) {
try {
return OAUTH2ACCESSTOKEN_OBJECT_READER.readValue(jsonOAuth2AccessToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = AccessToken.TABLE)
public class AccessToken {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import java.nio.ByteBuffer;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
import java.nio.ByteBuffer;

@Table(value = Authentication.TABLE)
public class Authentication {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = AuthenticationToAccessToken.TABLE)
public class AuthenticationToAccessToken {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = ClientIdToAccessToken.TABLE)
public class ClientIdToAccessToken {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import java.nio.ByteBuffer;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
import java.nio.ByteBuffer;

@Table(value = RefreshToken.TABLE)
public class RefreshToken {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import java.nio.ByteBuffer;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
import java.nio.ByteBuffer;

@Table(value = RefreshTokenAuthentication.TABLE)
public class RefreshTokenAuthentication {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = RefreshTokenToAccessToken.TABLE)
public class RefreshTokenToAccessToken {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mertz.security.oauth2.provider.token.store.cassandra.model;

import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;

import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = UsernameToAccessToken.TABLE)
public class UsernameToAccessToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
import java.util.Date;
import java.util.UUID;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
Expand All @@ -26,20 +22,10 @@
import org.springframework.security.oauth2.provider.RequestTokenFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.TokenStoreBaseTests;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
@ActiveProfiles(profiles = "externalcassandra")
public class CassandraTokenStoreTests extends TokenStoreBaseTests {

@Autowired
private CassandraOperations cassandraOperations;

@Autowired
private CassandraMappingContext cassandraMappingContext;
public abstract class CassandraTokenStoreTests extends TokenStoreBaseTests {

@Autowired
private TokenStore cassandraTokenStore;
Expand All @@ -49,11 +35,6 @@ public TokenStore getTokenStore() {
return cassandraTokenStore;
}

@Before
public void setUp() throws Exception {
cassandraMappingContext.getTableEntities().forEach(entity -> cassandraOperations.truncate(entity.getTableName()));
}

@Configuration
@ComponentScan(basePackages = "mertz.security.oauth2.provider.token.store.cassandra")
public static class SpringConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -18,5 +20,4 @@
@CassandraDataSet(keyspace = "${spring.data.cassandra.keyspace-name}")
@ActiveProfiles(profiles = "embeddedcassandra", inheritProfiles = false)
public class EmbeddedCassandraTokenStoreTests extends CassandraTokenStoreTests {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;

@Configuration
Expand All @@ -28,7 +28,7 @@ protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {

@Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
return SchemaAction.RECREATE;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be problematic for a rolling upgrade. Shouldn't we keep the existing tokens in the DB since we are not altering DB schema?

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testRetrieveAccessToken() {
assertEquals(expectedOAuth2AccessToken, actualOAuth2AccessToken);
assertEquals(authentication.getUserAuthentication(), getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()).getUserAuthentication());
// The authorizationRequest does not match because it is unapproved, but the token was granted to an approved request
assertFalse(storedOAuth2Request.equals(getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()).getOAuth2Request()));
assertNotEquals(storedOAuth2Request, getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()).getOAuth2Request());
actualOAuth2AccessToken = getTokenStore().getAccessToken(authentication);
assertEquals(expectedOAuth2AccessToken, actualOAuth2AccessToken);
getTokenStore().removeAccessToken(expectedOAuth2AccessToken);
Expand Down Expand Up @@ -196,12 +196,13 @@ public void testRemoveRefreshToken() {

@Test
public void testRemovedTokenCannotBeFoundByUsername() {
String clientId = "id"+UUID.randomUUID();
OAuth2AccessToken token = new DefaultOAuth2AccessToken("testToken");
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
"id", false), new TestAuthentication("test2", false));
clientId, false), new TestAuthentication("test2", false));
getTokenStore().storeAccessToken(token, expectedAuthentication);
getTokenStore().removeAccessToken(token);
Collection<OAuth2AccessToken> tokens = getTokenStore().findTokensByClientIdAndUserName("id", "test2");
Collection<OAuth2AccessToken> tokens = getTokenStore().findTokensByClientIdAndUserName(clientId, "test2");
assertFalse(tokens.contains(token));
assertTrue(tokens.isEmpty());
}
Expand Down