List of usage examples for org.springframework.security.oauth2.common OAuth2RefreshToken getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.avego.oauth.migration.OauthDataMigrator.java
/** * This creates a new refresh token with the token id replaced with the given new token id, * it maintains the token expiry assuming the token implements ExpiringOAuth2RefreshToken * @param origToken The original token to create a new equivalent of with the token value replaced * @param newTokenId The new token value * @return The equivalent new refresh token with the value replaced with the new token * @throws IllegalArgumentException//from w ww. ja va 2 s . c om * @throws InstantiationException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ @SuppressWarnings("unchecked") private OAuth2RefreshToken replaceOAuth2RefreshTokenValue(OAuth2RefreshToken origToken, String newTokenId) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { OAuth2RefreshToken refreshToken = origToken; if (origToken != null) { // see if it has a set value method Method setValueMethod = MethodUtils.getAccessibleMethod(refreshToken.getClass(), "setValue", String.class); if (setValueMethod != null) { Object res = setValueMethod.invoke(refreshToken, newTokenId); if (res != null && res instanceof OAuth2RefreshToken) { refreshToken = (OAuth2RefreshToken) res; } } else { Constructor<OAuth2RefreshToken> constructor = null; // look for constructors that we can use if (refreshToken instanceof ExpiringOAuth2RefreshToken) { java.util.Date expiry = ((ExpiringOAuth2RefreshToken) refreshToken).getExpiration(); constructor = (Constructor<OAuth2RefreshToken>) ConstructorUtils .getAccessibleConstructor(refreshToken.getClass(), java.util.Date.class, String.class); if (constructor == null) { constructor = (Constructor<OAuth2RefreshToken>) ConstructorUtils.getAccessibleConstructor( refreshToken.getClass(), String.class, java.util.Date.class); if (constructor != null) { refreshToken = constructor.newInstance(newTokenId, expiry); } } else { refreshToken = constructor.newInstance(expiry, newTokenId); } } else { constructor = (Constructor<OAuth2RefreshToken>) ConstructorUtils .getAccessibleConstructor(refreshToken.getClass(), String.class); if (constructor != null) { refreshToken = constructor.newInstance(newTokenId); } } if (constructor == null) { throw new IllegalStateException( "Could not replace the refresh token value as the refresh token class: " + refreshToken.getClass() + " did not have a setValue method and did not have a matching constructor"); } } } return refreshToken; }