5959import static org .elasticsearch .transport .RemoteClusterPortSettings .TRANSPORT_VERSION_ADVANCED_REMOTE_CLUSTER_SECURITY ;
6060import static org .elasticsearch .xcontent .ConstructingObjectParser .constructorArg ;
6161import static org .elasticsearch .xcontent .ConstructingObjectParser .optionalConstructorArg ;
62+ import static org .elasticsearch .xpack .core .security .authc .Authentication .AuthenticationType .TOKEN ;
6263import static org .elasticsearch .xpack .core .security .authc .Authentication .RealmRef .newAnonymousRealmRef ;
6364import static org .elasticsearch .xpack .core .security .authc .Authentication .RealmRef .newApiKeyRealmRef ;
6465import static org .elasticsearch .xpack .core .security .authc .Authentication .RealmRef .newCloudApiKeyRealmRef ;
8384import static org .elasticsearch .xpack .core .security .authc .AuthenticationField .FALLBACK_REALM_NAME ;
8485import static org .elasticsearch .xpack .core .security .authc .AuthenticationField .FALLBACK_REALM_TYPE ;
8586import static org .elasticsearch .xpack .core .security .authc .RealmDomain .REALM_DOMAIN_PARSER ;
87+ import static org .elasticsearch .xpack .core .security .authc .Subject .Type .USER ;
8688import static org .elasticsearch .xpack .core .security .authz .RoleDescriptor .Fields .REMOTE_CLUSTER ;
8789import static org .elasticsearch .xpack .core .security .authz .permission .RemoteClusterPermissions .ROLE_REMOTE_CLUSTER_PRIVS ;
8890
@@ -424,7 +426,7 @@ public Authentication token() {
424426 assert false == isAuthenticatedInternally ();
425427 assert false == isServiceAccount ();
426428 assert false == isCrossClusterAccess ();
427- final Authentication newTokenAuthentication = new Authentication (effectiveSubject , authenticatingSubject , AuthenticationType . TOKEN );
429+ final Authentication newTokenAuthentication = new Authentication (effectiveSubject , authenticatingSubject , TOKEN );
428430 return newTokenAuthentication ;
429431 }
430432
@@ -603,7 +605,7 @@ public boolean supportsRunAs(@Nullable AnonymousUser anonymousUser) {
603605 // Run-as is supported for authentication with realm, api_key or token.
604606 if (AuthenticationType .REALM == getAuthenticationType ()
605607 || AuthenticationType .API_KEY == getAuthenticationType ()
606- || AuthenticationType . TOKEN == getAuthenticationType ()) {
608+ || TOKEN == getAuthenticationType ()) {
607609 return true ;
608610 }
609611
@@ -717,7 +719,7 @@ public boolean canAccessResourcesOf(Authentication resourceCreatorAuthentication
717719 assert EnumSet .of (
718720 Authentication .AuthenticationType .REALM ,
719721 Authentication .AuthenticationType .API_KEY ,
720- Authentication . AuthenticationType . TOKEN ,
722+ TOKEN ,
721723 Authentication .AuthenticationType .ANONYMOUS ,
722724 Authentication .AuthenticationType .INTERNAL
723725 ).containsAll (EnumSet .of (getAuthenticationType (), resourceCreatorAuthentication .getAuthenticationType ()))
@@ -823,6 +825,9 @@ public void toXContentFragment(XContentBuilder builder) throws IOException {
823825 apiKeyField .put ("managed_by" , CredentialManagedBy .CLOUD .getDisplayName ());
824826 builder .field ("api_key" , Collections .unmodifiableMap (apiKeyField ));
825827 }
828+ if (metadata .containsKey ("managed_by" )) {
829+ builder .field ("managed_by" , metadata .get ("managed_by" ));
830+ }
826831 }
827832
828833 public static Authentication getAuthenticationFromCrossClusterAccessMetadata (Authentication authentication ) {
@@ -982,7 +987,7 @@ private void checkConsistencyForApiKeyAuthenticationType() {
982987 }
983988
984989 private void checkConsistencyForRealmAuthenticationType () {
985- if (Subject . Type . USER != authenticatingSubject .getType ()) {
990+ if (USER != authenticatingSubject .getType ()) {
986991 throw new IllegalArgumentException ("Realm authentication must have subject type of user" );
987992 }
988993 if (isRunAs ()) {
@@ -1025,7 +1030,7 @@ private static void checkRunAsConsistency(Subject effectiveSubject, Subject auth
10251030 )
10261031 );
10271032 }
1028- if (Subject . Type . USER != effectiveSubject .getType ()) {
1033+ if (USER != effectiveSubject .getType ()) {
10291034 throw new IllegalArgumentException (Strings .format ("Run-as subject type cannot be [%s]" , effectiveSubject .getType ()));
10301035 }
10311036 if (false == effectiveSubject .getMetadata ().isEmpty ()) {
@@ -1357,7 +1362,7 @@ public static Authentication newServiceAccountAuthentication(User serviceAccount
13571362 final Authentication .RealmRef authenticatedBy = newServiceAccountRealmRef (nodeName );
13581363 Authentication authentication = new Authentication (
13591364 new Subject (serviceAccountUser , authenticatedBy , TransportVersion .current (), metadata ),
1360- AuthenticationType . TOKEN
1365+ TOKEN
13611366 );
13621367 return authentication ;
13631368 }
@@ -1384,7 +1389,7 @@ public static Authentication newCloudAccessTokenAuthentication(
13841389 final User user = authResult .getValue ();
13851390 return new Authentication (
13861391 new Subject (user , realmRef , TransportVersion .current (), authResult .getMetadata ()),
1387- AuthenticationType . TOKEN
1392+ TOKEN
13881393 );
13891394 }
13901395
0 commit comments