本文整理汇总了Java中org.springframework.security.oauth2.common.util.SerializationUtils类的典型用法代码示例。如果您正苦于以下问题:Java SerializationUtils类的具体用法?Java SerializationUtils怎么用?Java SerializationUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationUtils类属于org.springframework.security.oauth2.common.util包,在下文中一共展示了SerializationUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeSafely
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
/**
* Dirty hack to fix <a href="https://github.com/spring-projects/spring-security-oauth/issues/665">Spring Security Issue</a>
* If there is serialUid mismatch, replaces Uuid and tries de-serialize object again
* Introduces mismatchCallback function to handle successful recovery of Uuid mismatch
*
* @param data Data to de-serialize
* @param mismatchCallback Mismatch callback. Executed in case of successful recovery
* @param <T> Type of Object
* @return De-serialized object
*/
@SuppressWarnings("unchecked")
public static <T> T deserializeSafely(byte[] data, @Nullable Consumer<T> mismatchCallback) {
try {
return SerializationUtils.deserialize(data);
} catch (IllegalArgumentException e) {
boolean serialUidMismatch = java.io.InvalidClassException.class.equals(e.getCause().getClass());
if (!serialUidMismatch) {
throw e;
}
try {
ObjectInputStream is = new SerialUidReplacingInputStream(new ByteArrayInputStream(data));
T t = (T) is.readObject();
if (null != mismatchCallback) {
mismatchCallback.accept(t);
}
return t;
} catch (IOException | ClassNotFoundException e1) {
throw new IllegalArgumentException("Unable to serialize object", e1);
}
}
}
示例2: getAccessToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public OAuth2AccessToken getAccessToken(
OAuth2ProtectedResourceDetails resource,
Authentication authentication) {
String username = authentication.getPrincipal().toString();
String shimKey = authentication.getDetails().toString();
AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(
username, shimKey, new Sort(Sort.Direction.DESC, "dateCreated"));
if (accessParameters == null || accessParameters.getSerializedToken() == null) {
return null; //No token was found!
}
return SerializationUtils.deserialize(accessParameters.getSerializedToken());
}
示例3: saveAccessToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public void saveAccessToken(
OAuth2ProtectedResourceDetails resource,
Authentication authentication, OAuth2AccessToken accessToken) {
String username = authentication.getPrincipal().toString();
String shimKey = authentication.getDetails().toString();
AccessParameters accessParameters =
accessParametersRepo.findByUsernameAndShimKey(
username,
shimKey,
new Sort(Sort.Direction.DESC, "dateCreated"));
if (accessParameters == null) {
accessParameters = new AccessParameters();
accessParameters.setUsername(username);
accessParameters.setShimKey(shimKey);
}
accessParameters.setSerializedToken(SerializationUtils.serialize(accessToken));
accessParametersRepo.save(accessParameters);
}
示例4: shouldStoreAccessToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Test
public void shouldStoreAccessToken() {
//Given
final OAuth2AccessToken auth2AccessToken = OAuth2AccessTokenBuilder.oAuth2AccessTokenBuilder().build();
final byte[] token = SerializationUtils.serialize(auth2AccessToken);
//And
final OAuth2Authentication oAuth2Authentication = OAuth2AuthenticationBuilder.oAuth2AuthenticationBuilder().build();
//And
given(mongoOAuth2AccessTokenRepository.findByTokenId(any(String.class))).willReturn(MongoOAuth2AccessTokenBuilder.mongoOAuth2AccessTokenBuilder().token(token).build());
//When
tokenStore.storeAccessToken(auth2AccessToken, oAuth2Authentication);
//Then
verify(mongoOAuth2AccessTokenRepository).deleteByTokenId(any(String.class));
verify(mongoOAuth2AccessTokenRepository).save(any(MongoOAuth2AccessToken.class));
}
示例5: shouldStoreRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Test
public void shouldStoreRefreshToken() {
//Given
final OAuth2RefreshToken oAuth2RefreshToken = OAuth2RefreshTokenBuilder.oAuth2RefreshToken().build();
//And
final OAuth2Authentication oAuth2Authentication = OAuth2AuthenticationBuilder.oAuth2AuthenticationBuilder().build();
//And
final ArgumentCaptor<MongoOAuth2RefreshToken> argumentCaptor = ArgumentCaptor.forClass(MongoOAuth2RefreshToken.class);
//When
tokenStore.storeRefreshToken(oAuth2RefreshToken, oAuth2Authentication);
//Then
verify(mongoOAuth2RefreshTokenRepository).save(argumentCaptor.capture());
final MongoOAuth2RefreshToken refreshToken = argumentCaptor.getValue();
final byte[] expectedResult = SerializationUtils.serialize(oAuth2RefreshToken);
assertThat(refreshToken.getToken()).isEqualTo(expectedResult);
}
示例6: shouldReadRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Test
public void shouldReadRefreshToken() {
//Given
final String tokenValue = string().next();
final OAuth2RefreshToken oAuth2RefreshToken = OAuth2RefreshTokenBuilder.oAuth2RefreshToken().build();
final byte[] oAuth2RefreshTokenSer = SerializationUtils.serialize(oAuth2RefreshToken);
//And
given(mongoOAuth2RefreshTokenRepository.findByTokenId(any(String.class)))
.willReturn(MongoOAuth2RefreshTokenBuilder.mongoOAuth2RefreshTokenBuilder().token(oAuth2RefreshTokenSer).build());
//When
final OAuth2RefreshToken result = tokenStore.readRefreshToken(tokenValue);
//Then
assertThat(result.getValue()).isEqualTo(oAuth2RefreshToken.getValue());
}
示例7: shouldReadAuthenticationForRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Test
public void shouldReadAuthenticationForRefreshToken() {
//Given
final OAuth2RefreshToken oAuth2RefreshToken = OAuth2RefreshTokenBuilder.oAuth2RefreshToken().build();
//And
final OAuth2Authentication authentication = OAuth2AuthenticationBuilder.oAuth2AuthenticationBuilder().build();
final byte[] authenticationSer = SerializationUtils.serialize(authentication);
//And
given(mongoOAuth2RefreshTokenRepository.findByTokenId(any(String.class)))
.willReturn(MongoOAuth2RefreshTokenBuilder.mongoOAuth2RefreshTokenBuilder()
.authentication(authenticationSer)
.build());
//When
final OAuth2Authentication oAuth2Authentication = tokenStore.readAuthenticationForRefreshToken(oAuth2RefreshToken);
//Then
assertThat(oAuth2Authentication.getPrincipal()).isEqualTo(authentication.getPrincipal());
assertThat(oAuth2Authentication.getCredentials()).isEqualTo(authentication.getCredentials());
}
示例8: getAccessToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
public OAuth2AccessToken getAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication) {
OAuth2AccessToken accessToken = null;
try {
accessToken = jdbcTemplate.queryForObject(selectAccessTokenSql, new RowMapper<OAuth2AccessToken>() {
public OAuth2AccessToken mapRow(ResultSet rs, int rowNum) throws SQLException {
return SerializationUtils.deserialize(rs.getBytes(2));
}
}, keyGenerator.extractKey(resource, authentication));
}
catch (EmptyResultDataAccessException e) {
if (LOG.isInfoEnabled()) {
LOG.debug("Failed to find access token for authentication " + authentication);
}
}
return accessToken;
}
示例9: remove
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
public OAuth2Authentication remove(String code) {
OAuth2Authentication authentication;
try {
authentication = jdbcTemplate.queryForObject(selectAuthenticationSql,
new RowMapper<OAuth2Authentication>() {
public OAuth2Authentication mapRow(ResultSet rs, int rowNum)
throws SQLException {
return SerializationUtils.deserialize(rs.getBytes("authentication"));
}
}, code);
} catch (EmptyResultDataAccessException e) {
return null;
}
if (authentication != null) {
jdbcTemplate.update(deleteAuthenticationSql, code);
}
return authentication;
}
示例10: readAuthentication
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public OAuth2Authentication readAuthentication(String token) {
Authentication authentication = authenticationRepository.findOne(token);
if (authentication != null) {
ByteBuffer bufferedOAuth2Authentication = authentication.getoAuth2Authentication();
byte[] serializedOAuth2Authentication = new byte[bufferedOAuth2Authentication.remaining()];
bufferedOAuth2Authentication.get(serializedOAuth2Authentication);
OAuth2Authentication oAuth2Authentication = SerializationUtils.deserialize(serializedOAuth2Authentication);
return oAuth2Authentication;
} else {
return null;
}
}
示例11: storeRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
List<RegularStatement> statementList = new ArrayList<RegularStatement>();
byte[] serializedRefreshToken = SerializationUtils.serialize(refreshToken);
ByteBuffer bufferedRefreshToken = ByteBuffer.wrap(serializedRefreshToken);
byte[] serializedAuthentication = SerializationUtils.serialize(authentication);
ByteBuffer bufferedAuthentication = ByteBuffer.wrap(serializedAuthentication);
WriteOptions refreshWriteOptions = new WriteOptions();
if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken;
Date expiration = expiringRefreshToken.getExpiration();
if (expiration != null) {
int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue();
refreshWriteOptions.setTtl(seconds);
}
}
// Insert into RefreshToken table
Insert accessInsert = CassandraTemplate.createInsertQuery(RefreshToken.TABLE, new RefreshToken(refreshToken.getValue(), bufferedRefreshToken), refreshWriteOptions, cassandraTemplate.getConverter());
statementList.add(accessInsert);
// Insert into RefreshTokenAuthentication table
Insert authInsert = CassandraTemplate.createInsertQuery(RefreshTokenAuthentication.TABLE, new RefreshTokenAuthentication(refreshToken.getValue(), bufferedAuthentication), refreshWriteOptions, cassandraTemplate.getConverter());
statementList.add(authInsert);
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
示例12: readRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public OAuth2RefreshToken readRefreshToken(String tokenValue) {
RefreshToken refreshToken = refreshTokenRepository.findOne(tokenValue);
if (refreshToken != null) {
ByteBuffer bufferedRefreshToken = refreshToken.getoAuth2RefreshToken();
byte[] serializedRefreshToken = new byte[bufferedRefreshToken.remaining()];
bufferedRefreshToken.get(serializedRefreshToken);
OAuth2RefreshToken oAuth2RefreshToken = SerializationUtils.deserialize(serializedRefreshToken);
return oAuth2RefreshToken;
} else {
return null;
}
}
示例13: readAuthenticationForRefreshToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
RefreshTokenAuthentication refreshTokenAuthentication = refreshTokenAuthenticationRepository.findOne(token.getValue());
if (refreshTokenAuthentication != null) {
ByteBuffer bufferedOAuth2Authentication = refreshTokenAuthentication.getoAuth2Authentication();
byte[] serializedOAuth2Authentication = new byte[bufferedOAuth2Authentication.remaining()];
bufferedOAuth2Authentication.get(serializedOAuth2Authentication);
OAuth2Authentication oAuth2Authentication = SerializationUtils.deserialize(serializedOAuth2Authentication);
return oAuth2Authentication;
} else {
return null;
}
}
示例14: readAuthentication
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public OAuth2Authentication readAuthentication(String tokenId) {
final OAuth2AccessTokenEntity entity = oAuth2AccessTokenRepository.findByTokenId(tokenId);
return deserializeSafely(entity.getAuthentication(),
auth -> {
// if we are at the place, there was InvalidClassException,
// and we successfully recovered auth object
// let's save it back to DB then, since now it has correct version UUID
entity.setAuthentication(SerializationUtils.serialize(auth));
oAuth2AccessTokenRepository.save(entity);
});
}
示例15: storeAccessToken
import org.springframework.security.oauth2.common.util.SerializationUtils; //导入依赖的package包/类
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
OAuth2AccessTokenEntity tokenEntity = new OAuth2AccessTokenEntity();
tokenEntity.setTokenId(token.getValue());
tokenEntity.setToken(SerializationUtils.serialize(token));
tokenEntity.setAuthentication(SerializationUtils.serialize(authentication));
tokenEntity.setAuthenticationId(authenticationKeyGenerator.extractKey(authentication));
tokenEntity.setUserName(authentication.isClientOnly() ? null : authentication.getName());
tokenEntity.setRefreshToken(null == token.getRefreshToken() ? null : token.getRefreshToken().getValue());
tokenEntity.setClientId(authentication.getOAuth2Request().getClientId());
oAuth2AccessTokenRepository.save(tokenEntity);
}