Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

SOCIAL-355: Make Connection Serializable #121

Merged
merged 2 commits into from
Feb 14, 2014
Merged

SOCIAL-355: Make Connection Serializable #121

merged 2 commits into from
Feb 14, 2014

Conversation

ractive
Copy link
Contributor

@ractive ractive commented Feb 10, 2014

Connection is a field in SocialAuthenticationToken, which implements
Authentication which is Serializable. Therefore Connection must be
Serializable as well.

See https://jira.springsource.org/browse/SOCIAL-355

james added 2 commits February 10, 2014 10:41
Connection is a field in SocialAuthenticationToken, which implements
Authentication which is Serializable. Therefore Connection must be
Serializable as well.
@ractive
Copy link
Contributor Author

ractive commented Feb 10, 2014

I'm using this test to check if the OAuth2Connection is Serializable. I'm not sure where such a test could be to put it in the spring-social project(s), since it uses a concrete API implementation. I'm sure there are some Mocks that could be used instead...

package ch.local.auth.support;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.springframework.security.oauth2.common.util.SerializationUtils;
import org.springframework.social.connect.ConnectionData;
import org.springframework.social.connect.support.OAuth2Connection;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.connect.FacebookAdapter;
import org.springframework.social.facebook.connect.FacebookServiceProvider;

/**
 * Tests if the OAuth2Connection class is serializable.
 * 
 * @see https://jira.springsource.org/browse/SOCIAL-355
 */
public class OAuth2ConnectionTest {
    @Test
    public void oauth2ConnectionSerializable() throws Exception {
        OAuth2Connection<Facebook> connection =
                new OAuth2Connection<Facebook>(new ConnectionData("test", "test", "test", "test", "test", "test", "test", "test", 123L), new FacebookServiceProvider("test", "test", "test"), new FacebookAdapter());

        byte[] byteArray = SerializationUtils.serialize(connection);
        OAuth2Connection<Facebook> connectionFromArray = SerializationUtils.deserialize(byteArray);

        assertEquals(connection, connectionFromArray);
    }
}

habuma added a commit that referenced this pull request Feb 14, 2014
SOCIAL-355: Make Connection Serializable
@habuma habuma merged commit 0b2a6ef into spring-attic:master Feb 14, 2014
@damiancalabresi
Copy link

Now connection is serializable, but due to the transient keyword added in the commit:
0b2a6ef

The ServiceProvider of the connection is null when it's deserialized, so the connection is recovered but throws a NullPointerException if I want to use it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants