Closed ractive closed 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);
}
}
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.
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