4545import org .elasticsearch .cluster .ClusterStateUpdateTask ;
4646import org .elasticsearch .cluster .ack .AckedRequest ;
4747import org .elasticsearch .cluster .service .ClusterService ;
48- import org .elasticsearch .core .Nullable ;
4948import org .elasticsearch .common .Priority ;
5049import org .elasticsearch .common .Strings ;
5150import org .elasticsearch .common .UUIDs ;
5251import org .elasticsearch .common .bytes .BytesReference ;
5352import org .elasticsearch .common .cache .Cache ;
5453import org .elasticsearch .common .cache .CacheBuilder ;
55- import org .elasticsearch .core .Tuple ;
5654import org .elasticsearch .common .hash .MessageDigests ;
5755import org .elasticsearch .common .io .stream .BytesStreamOutput ;
5856import org .elasticsearch .common .io .stream .InputStreamStreamInput ;
6361import org .elasticsearch .common .settings .Setting ;
6462import org .elasticsearch .common .settings .Setting .Property ;
6563import org .elasticsearch .common .settings .Settings ;
66- import org .elasticsearch .core .TimeValue ;
6764import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
6865import org .elasticsearch .common .util .concurrent .ThreadContext ;
6966import org .elasticsearch .common .util .iterable .Iterables ;
7067import org .elasticsearch .common .xcontent .XContentBuilder ;
7168import org .elasticsearch .common .xcontent .XContentFactory ;
7269import org .elasticsearch .common .xcontent .XContentType ;
70+ import org .elasticsearch .core .Nullable ;
71+ import org .elasticsearch .core .TimeValue ;
72+ import org .elasticsearch .core .Tuple ;
7373import org .elasticsearch .core .internal .io .Streams ;
7474import org .elasticsearch .index .IndexNotFoundException ;
7575import org .elasticsearch .index .engine .VersionConflictEngineException ;
9797import org .elasticsearch .xpack .security .support .FeatureNotEnabledException .Feature ;
9898import org .elasticsearch .xpack .security .support .SecurityIndexManager ;
9999
100- import javax .crypto .Cipher ;
101- import javax .crypto .CipherInputStream ;
102- import javax .crypto .CipherOutputStream ;
103- import javax .crypto .NoSuchPaddingException ;
104- import javax .crypto .SecretKey ;
105- import javax .crypto .SecretKeyFactory ;
106- import javax .crypto .spec .GCMParameterSpec ;
107- import javax .crypto .spec .PBEKeySpec ;
108- import javax .crypto .spec .SecretKeySpec ;
109100import java .io .ByteArrayInputStream ;
110101import java .io .ByteArrayOutputStream ;
111102import java .io .Closeable ;
144135import java .util .function .Predicate ;
145136import java .util .function .Supplier ;
146137import java .util .stream .Collectors ;
138+ import javax .crypto .Cipher ;
139+ import javax .crypto .CipherInputStream ;
140+ import javax .crypto .CipherOutputStream ;
141+ import javax .crypto .NoSuchPaddingException ;
142+ import javax .crypto .SecretKey ;
143+ import javax .crypto .SecretKeyFactory ;
144+ import javax .crypto .spec .GCMParameterSpec ;
145+ import javax .crypto .spec .PBEKeySpec ;
146+ import javax .crypto .spec .SecretKeySpec ;
147147
148148import static java .util .Collections .emptyList ;
149149import static java .util .Collections .singletonList ;
@@ -449,6 +449,7 @@ private void getUserTokenFromId(String userTokenId, Version tokenVersion, Action
449449 () -> executeAsyncWithOrigin (client .threadPool ().getThreadContext (), SECURITY_ORIGIN , getRequest ,
450450 ActionListener .<GetResponse >wrap (response -> {
451451 if (response .isExists ()) {
452+ @ SuppressWarnings ("unchecked" )
452453 Map <String , Object > accessTokenSource =
453454 (Map <String , Object >) response .getSource ().get ("access_token" );
454455 if (accessTokenSource == null ) {
@@ -458,6 +459,7 @@ private void getUserTokenFromId(String userTokenId, Version tokenVersion, Action
458459 onFailure .accept (new IllegalStateException (
459460 "token document is missing the user_token field" ));
460461 } else {
462+ @ SuppressWarnings ("unchecked" )
461463 Map <String , Object > userTokenSource =
462464 (Map <String , Object >) accessTokenSource .get ("user_token" );
463465 listener .onResponse (UserToken .fromSourceMap (userTokenSource ));
@@ -691,7 +693,7 @@ public void invalidateActiveTokensForRealmAndUser(@Nullable String realmName, @N
691693 }
692694 }, listener ::onFailure ));
693695 } else {
694- Predicate filter = null ;
696+ Predicate < Map < String , Object >> filter = null ;
695697 if (Strings .hasText (username )) {
696698 filter = isOfUser (username );
697699 }
@@ -1295,6 +1297,7 @@ private static Optional<ElasticsearchSecurityException> checkClientCanRefresh(Re
12951297 }
12961298
12971299 private static Map <String , Object > getRefreshTokenSourceMap (Map <String , Object > source ) {
1300+ @ SuppressWarnings ("unchecked" )
12981301 final Map <String , Object > refreshTokenSource = (Map <String , Object >) source .get ("refresh_token" );
12991302 if (refreshTokenSource == null || refreshTokenSource .isEmpty ()) {
13001303 throw new IllegalStateException ("token document is missing the refresh_token object" );
@@ -1303,10 +1306,12 @@ private static Map<String, Object> getRefreshTokenSourceMap(Map<String, Object>
13031306 }
13041307
13051308 private static Map <String , Object > getUserTokenSourceMap (Map <String , Object > source ) {
1309+ @ SuppressWarnings ("unchecked" )
13061310 final Map <String , Object > accessTokenSource = (Map <String , Object >) source .get ("access_token" );
13071311 if (accessTokenSource == null || accessTokenSource .isEmpty ()) {
13081312 throw new IllegalStateException ("token document is missing the access_token object" );
13091313 }
1314+ @ SuppressWarnings ("unchecked" )
13101315 final Map <String , Object > userTokenSource = (Map <String , Object >) accessTokenSource .get ("user_token" );
13111316 if (userTokenSource == null || userTokenSource .isEmpty ()) {
13121317 throw new IllegalStateException ("token document is missing the user token info" );
@@ -1556,7 +1561,9 @@ private Tuple<UserToken, String> filterAndParseHit(SearchHit hit, @Nullable Pred
15561561 */
15571562 private Tuple <UserToken , String > parseTokensFromDocument (Map <String , Object > source , @ Nullable Predicate <Map <String , Object >> filter )
15581563 throws IllegalStateException , DateTimeException {
1564+ @ SuppressWarnings ("unchecked" )
15591565 final String hashedRefreshToken = (String ) ((Map <String , Object >) source .get ("refresh_token" )).get ("token" );
1566+ @ SuppressWarnings ("unchecked" )
15601567 final Map <String , Object > userTokenSource = (Map <String , Object >)
15611568 ((Map <String , Object >) source .get ("access_token" )).get ("user_token" );
15621569 if (null != filter && filter .test (userTokenSource ) == false ) {
@@ -1634,6 +1641,7 @@ private void checkIfTokenIsValid(UserToken userToken, ActionListener<UserToken>
16341641 ActionListener .<GetResponse >wrap (response -> {
16351642 if (response .isExists ()) {
16361643 Map <String , Object > source = response .getSource ();
1644+ @ SuppressWarnings ("unchecked" )
16371645 Map <String , Object > accessTokenSource = (Map <String , Object >) source .get ("access_token" );
16381646 if (accessTokenSource == null ) {
16391647 onFailure .accept (new IllegalStateException ("token document is missing access_token field" ));
@@ -2002,6 +2010,7 @@ public void onFailure(Exception e) {
20022010 * Creates a new key unless present that is newer than the current active key and returns the corresponding metadata. Note:
20032011 * this method doesn't modify the metadata used in this token service. See {@link #refreshMetadata(TokenMetadata)}
20042012 */
2013+ @ SuppressWarnings ("unchecked" )
20052014 synchronized TokenMetadata generateSpareKey () {
20062015 KeyAndCache maxKey = keyCache .cache .values ().stream ().max (Comparator .comparingLong (v -> v .keyAndTimestamp .getTimestamp ())).get ();
20072016 KeyAndCache currentKey = keyCache .activeKeyCache ;
@@ -2406,6 +2415,7 @@ static RefreshTokenStatus fromSourceMap(Map<String, Object> refreshTokenSource)
24062415 if (invalidated == null ) {
24072416 throw new IllegalStateException ("token document is missing the \" invalidated\" field" );
24082417 }
2418+ @ SuppressWarnings ("unchecked" )
24092419 final Map <String , Object > clientInfo = (Map <String , Object >) refreshTokenSource .get ("client" );
24102420 if (clientInfo == null ) {
24112421 throw new IllegalStateException ("token document is missing the \" client\" field" );
0 commit comments