Remove deprecated Authentication#getAuthenticatedBy#91104
Remove deprecated Authentication#getAuthenticatedBy#91104ywangd merged 2 commits intoelastic:mainfrom
Conversation
This PR removes the deprecated Authentication#getAuthenticatedBy method and replaces its usages with #getAuthenticatingSubject#getRealm Relates: elastic#88494
| } else if (clientAuthentication.getAuthenticatingSubject() | ||
| .getRealm() | ||
| .getName() | ||
| .equals(refreshToken.getAssociatedRealm()) == false) { |
There was a problem hiding this comment.
This logic is inconsistent, i.e. it first checks effective user but then checks authenticating realm. But it is an existing bug (the token was created by capturing effective user + authenticating realm). So this is kept as is. Also it does not really matter much in practice because we now capture full authentication object for new tokens and these logics are not really used much.
| public SamlAuthenticateResponse(Authentication authentication, String tokenString, String refreshToken, TimeValue expiresIn) { | ||
| this.principal = authentication.getEffectiveSubject().getUser().principal(); | ||
| this.realm = authentication.getAuthenticatedBy().getName(); | ||
| this.realm = authentication.getEffectiveSubject().getRealm().getName(); |
There was a problem hiding this comment.
This technically should be effectiveSubject. So I changed it be so. In practice, it does not matter because SAML realm authentication cannot have run-as. I add such assertion in other places (closer to where authentication is created).
| final String token = request.getToken(); | ||
| tokenService.getAuthenticationAndMetadata(token, ActionListener.wrap(tuple -> { | ||
| final Authentication authentication = tuple.v1(); | ||
| assert false == authentication.isRunAs() : "oidc realm authentication cannot have run-as"; |
There was a problem hiding this comment.
Similarly, oidc realm authentication cannot have run-as either.
| final Realm realm = this.realms.realm(authentication.getAuthenticatedBy().getName()); | ||
| final Realm realm = this.realms.realm(authentication.getEffectiveSubject().getRealm().getName()); |
There was a problem hiding this comment.
This and the other two places in this file are the same stroy as the saml realm authentication.
| return; | ||
| } | ||
| assert authentication != null : "authentication should never be null at this point"; | ||
| assert false == authentication.isRunAs() : "saml realm authentication cannot have run-as"; |
There was a problem hiding this comment.
Assertion for saml realm not having run-as.
| final Authentication.RealmRef ref = authentication.getAuthenticatedBy(); | ||
| final Authentication.RealmRef ref = authentication.getEffectiveSubject().getRealm(); | ||
| if (ref == null || Strings.isNullOrEmpty(ref.getName())) { | ||
| throw SamlUtils.samlException("Authentication {} has no authenticating realm", authentication); | ||
| throw SamlUtils.samlException("Authentication {} has no effective realm", authentication); |
| token.getDelegateeAuthentication().getAuthenticatedBy().getName() | ||
| // TODO: this should be the realm of effective subject | ||
| token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName() |
There was a problem hiding this comment.
This is a bug. I'll have a separate PR just for it so it is not blended in a pure refactoring.
There was a problem hiding this comment.
Good catch! Happy to review that one, too.
|
Pinging @elastic/es-security (Team:Security) |
| token.getDelegateeAuthentication().getAuthenticatedBy().getName() | ||
| // TODO: this should be the realm of effective subject | ||
| token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName() |
There was a problem hiding this comment.
Good catch! Happy to review that one, too.
This PR removes the deprecated Authentication#getAuthenticatedBy method and replaces its usages with #getAuthenticatingSubject#getRealm
Relates: #88494