spring-attic / spring-social

Allows you to connect your applications with SaaS providers such as Facebook and Twitter.
http://projects.spring.io/spring-social
Apache License 2.0
619 stars 351 forks source link

SOCIAL-355: Make Connection Serializable #121

Closed ractive closed 10 years ago

ractive commented 10 years ago

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

ractive commented 10 years ago

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);
    }
}
damiancalabresi commented 9 years ago

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

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.