-
Notifications
You must be signed in to change notification settings - Fork 25.2k
OpenID Connect Realm base functionality #37009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
5af56b9
c4154f6
8149339
8d54c7c
cc68f5a
72a2dd4
69fb95c
12dd9c0
6a4cac6
aeacfc5
845dc36
687c109
06c26dc
4bde32f
08be032
8ead2e5
dcf46fa
cb35d6e
8d9dcf6
e97097e
da98413
03d2db5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.Action; | ||
|
||
/** | ||
* Action for initiating an authentication process using OpenID Connect | ||
*/ | ||
public final class OpenIdConnectAuthenticateAction extends Action<OpenIdConnectAuthenticateResponse> { | ||
|
||
public static final OpenIdConnectAuthenticateAction INSTANCE = new OpenIdConnectAuthenticateAction(); | ||
public static final String NAME = "cluster:admin/xpack/security/oidc/authenticate"; | ||
|
||
protected OpenIdConnectAuthenticateAction() { | ||
super(NAME); | ||
} | ||
|
||
public OpenIdConnectAuthenticateResponse newResponse() { | ||
return new OpenIdConnectAuthenticateResponse(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Represents a request for authentication using OpenID Connect | ||
*/ | ||
public class OpenIdConnectAuthenticateRequest extends ActionRequest { | ||
|
||
/** | ||
* The URI were the OP redirected the browser after the authentication attempt. This is passed as is from the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/were/where |
||
* facilitator entity (i.e. Kibana) | ||
*/ | ||
private String redirectUri; | ||
|
||
/** | ||
* The state value that either we or the facilitator generated for this specific flow and that was stored at the user's session with | ||
* the facilitator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These java docs ("the faciliator generated") are no longer true. |
||
*/ | ||
private String state; | ||
|
||
/** | ||
* The nonce value that the facilitator generated for this specific flow and that was stored at the user's session with | ||
* the facilitator | ||
*/ | ||
private String nonce; | ||
|
||
public OpenIdConnectAuthenticateRequest() { | ||
} | ||
|
||
public String getRedirectUri() { | ||
return redirectUri; | ||
} | ||
|
||
public void setRedirectUri(String redirectUri) { | ||
this.redirectUri = redirectUri; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public void setState(String state) { | ||
this.state = state; | ||
} | ||
|
||
public String getNonce() { | ||
return nonce; | ||
} | ||
|
||
public void setNonce(String nonce) { | ||
this.nonce = nonce; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(redirectUri); | ||
out.writeString(state); | ||
out.writeOptionalString(nonce); | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
jkakavas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super.readFrom(in); | ||
redirectUri = in.readString(); | ||
state = in.readString(); | ||
nonce = in.readOptionalString(); | ||
} | ||
|
||
public String toString() { | ||
return "{redirectUri=" + redirectUri + ", state=" + state + ", nonce=" + nonce + "}"; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.ActionRequestBuilder; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
|
||
/** | ||
* Request builder for populating a {@link OpenIdConnectAuthenticateRequest} | ||
*/ | ||
public class OpenIdConnectAuthenticateRequestBuilder | ||
extends ActionRequestBuilder<OpenIdConnectAuthenticateRequest, OpenIdConnectAuthenticateResponse> { | ||
|
||
public OpenIdConnectAuthenticateRequestBuilder(ElasticsearchClient client) { | ||
super(client, OpenIdConnectAuthenticateAction.INSTANCE, new OpenIdConnectAuthenticateRequest()); | ||
} | ||
|
||
public OpenIdConnectAuthenticateRequestBuilder redirectUri(String redirectUri) { | ||
request.setRedirectUri(redirectUri); | ||
return this; | ||
} | ||
|
||
public OpenIdConnectAuthenticateRequestBuilder state(String state) { | ||
request.setState(state); | ||
return this; | ||
} | ||
|
||
public OpenIdConnectAuthenticateRequestBuilder nonce(String nonce) { | ||
request.setNonce(nonce); | ||
return this; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
||
import java.io.IOException; | ||
|
||
public class OpenIdConnectAuthenticateResponse extends ActionResponse { | ||
private String principal; | ||
private String accessTokenString; | ||
private String refreshTokenString; | ||
private TimeValue expiresIn; | ||
|
||
public OpenIdConnectAuthenticateResponse(String principal, String accessTokenString, String refreshTokenString, TimeValue expiresIn) { | ||
this.principal = principal; | ||
this.accessTokenString = accessTokenString; | ||
this.refreshTokenString = refreshTokenString; | ||
this.expiresIn = expiresIn; | ||
} | ||
|
||
public OpenIdConnectAuthenticateResponse() { | ||
} | ||
|
||
public String getPrincipal() { | ||
return principal; | ||
} | ||
|
||
public String getAccessTokenString() { | ||
return accessTokenString; | ||
} | ||
|
||
public String getRefreshTokenString() { | ||
return refreshTokenString; | ||
} | ||
|
||
public TimeValue getExpiresIn() { | ||
return expiresIn; | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to see us start using |
||
super.readFrom(in); | ||
principal = in.readString(); | ||
accessTokenString = in.readString(); | ||
refreshTokenString = in.readString(); | ||
expiresIn = in.readTimeValue(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(principal); | ||
out.writeString(accessTokenString); | ||
out.writeString(refreshTokenString); | ||
out.writeTimeValue(expiresIn); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.Action; | ||
|
||
public class OpenIdConnectPrepareAuthenticationAction extends Action<OpenIdConnectPrepareAuthenticationResponse> { | ||
|
||
public static final OpenIdConnectPrepareAuthenticationAction INSTANCE = new OpenIdConnectPrepareAuthenticationAction(); | ||
public static final String NAME = "cluster:admin/xpack/security/oidc/prepare"; | ||
|
||
protected OpenIdConnectPrepareAuthenticationAction() { | ||
super(NAME); | ||
} | ||
|
||
public OpenIdConnectPrepareAuthenticationResponse newResponse() { | ||
return new OpenIdConnectPrepareAuthenticationResponse(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
/** | ||
* Represents a request to prepare an OAuth 2.0 authentication request | ||
jkakavas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public class OpenIdConnectPrepareAuthenticationRequest extends ActionRequest { | ||
|
||
private String realmName; | ||
private String state; | ||
private String nonce; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's easier to reason if we generate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went back and forth on this for some time. Agreed, there is no strong argument against allowing Kibana (or any other facilitator ) to determine the nonce and state. I will address this |
||
|
||
public String getRealmName() { | ||
return realmName; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public String getNonce() { | ||
return nonce; | ||
} | ||
|
||
public void setRealmName(String realmName) { | ||
this.realmName = realmName; | ||
} | ||
|
||
public void setState(String state) { | ||
this.state = state; | ||
} | ||
|
||
public void setNonce(String nonce) { | ||
this.nonce = nonce; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (Strings.hasText(realmName) == false) { | ||
validationException = addValidationError("realm name must be provided", null); | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(realmName); | ||
out.writeOptionalString(state); | ||
out.writeOptionalString(nonce); | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
jkakavas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super.readFrom(in); | ||
realmName = in.readString(); | ||
state = in.readOptionalString(); | ||
nonce = in.readOptionalString(); | ||
} | ||
|
||
public String toString() { | ||
return "{realmName=" + realmName + ", state=" + state + ", nonce=" + nonce + "}"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.oidc; | ||
|
||
import org.elasticsearch.action.ActionRequestBuilder; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
|
||
/** | ||
* Request builder for populating a {@link OpenIdConnectPrepareAuthenticationRequest} | ||
*/ | ||
public class OpenIdConnectPrepareAuthenticationRequestBuilder | ||
extends ActionRequestBuilder<OpenIdConnectPrepareAuthenticationRequest, OpenIdConnectPrepareAuthenticationResponse> { | ||
|
||
public OpenIdConnectPrepareAuthenticationRequestBuilder(ElasticsearchClient client) { | ||
super(client, OpenIdConnectPrepareAuthenticationAction.INSTANCE, new OpenIdConnectPrepareAuthenticationRequest()); | ||
} | ||
|
||
public OpenIdConnectPrepareAuthenticationRequestBuilder realmName(String name) { | ||
request.setRealmName(name); | ||
return this; | ||
} | ||
|
||
public OpenIdConnectPrepareAuthenticationRequestBuilder state(String state) { | ||
request.setState(state); | ||
return this; | ||
} | ||
|
||
public OpenIdConnectPrepareAuthenticationRequestBuilder nonce(String nonce) { | ||
request.setNonce(nonce); | ||
return this; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.