|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | +package org.elasticsearch.xpack.core.security.action.oidc; |
| 7 | + |
| 8 | +import org.elasticsearch.action.ActionRequest; |
| 9 | +import org.elasticsearch.action.ActionRequestValidationException; |
| 10 | +import org.elasticsearch.common.Strings; |
| 11 | +import org.elasticsearch.common.io.stream.StreamInput; |
| 12 | +import org.elasticsearch.common.io.stream.StreamOutput; |
| 13 | + |
| 14 | +import java.io.IOException; |
| 15 | + |
| 16 | +import static org.elasticsearch.action.ValidateActions.addValidationError; |
| 17 | + |
| 18 | +/** |
| 19 | + * Represents a request for authentication using OpenID Connect |
| 20 | + */ |
| 21 | +public class OpenIdConnectAuthenticateRequest extends ActionRequest { |
| 22 | + |
| 23 | + /** |
| 24 | + * The URI where the OP redirected the browser after the authentication attempt. This is passed as is from the |
| 25 | + * facilitator entity (i.e. Kibana) |
| 26 | + */ |
| 27 | + private String redirectUri; |
| 28 | + |
| 29 | + /** |
| 30 | + * The state value that we generated or the facilitator provided for this specific flow and that should be stored at the user's session |
| 31 | + * with the facilitator |
| 32 | + */ |
| 33 | + private String state; |
| 34 | + |
| 35 | + /** |
| 36 | + * The nonce value that we generated or the facilitator provided for this specific flow and that should be stored at the user's session |
| 37 | + * with the facilitator |
| 38 | + */ |
| 39 | + private String nonce; |
| 40 | + |
| 41 | + public OpenIdConnectAuthenticateRequest() { |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + public OpenIdConnectAuthenticateRequest(StreamInput in) throws IOException { |
| 46 | + super.readFrom(in); |
| 47 | + redirectUri = in.readString(); |
| 48 | + state = in.readString(); |
| 49 | + nonce = in.readString(); |
| 50 | + } |
| 51 | + |
| 52 | + public String getRedirectUri() { |
| 53 | + return redirectUri; |
| 54 | + } |
| 55 | + |
| 56 | + public void setRedirectUri(String redirectUri) { |
| 57 | + this.redirectUri = redirectUri; |
| 58 | + } |
| 59 | + |
| 60 | + public String getState() { |
| 61 | + return state; |
| 62 | + } |
| 63 | + |
| 64 | + public void setState(String state) { |
| 65 | + this.state = state; |
| 66 | + } |
| 67 | + |
| 68 | + public String getNonce() { |
| 69 | + return nonce; |
| 70 | + } |
| 71 | + |
| 72 | + public void setNonce(String nonce) { |
| 73 | + this.nonce = nonce; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public ActionRequestValidationException validate() { |
| 78 | + ActionRequestValidationException validationException = null; |
| 79 | + if (Strings.isNullOrEmpty(state)) { |
| 80 | + validationException = addValidationError("state parameter is missing", validationException); |
| 81 | + } |
| 82 | + if (Strings.isNullOrEmpty(nonce)) { |
| 83 | + validationException = addValidationError("nonce parameter is missing", validationException); |
| 84 | + } |
| 85 | + if (Strings.isNullOrEmpty(redirectUri)) { |
| 86 | + validationException = addValidationError("redirect_uri parameter is missing", validationException); |
| 87 | + } |
| 88 | + return validationException; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void writeTo(StreamOutput out) throws IOException { |
| 93 | + super.writeTo(out); |
| 94 | + out.writeString(redirectUri); |
| 95 | + out.writeString(state); |
| 96 | + out.writeString(nonce); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public void readFrom(StreamInput in) { |
| 101 | + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); |
| 102 | + } |
| 103 | + |
| 104 | + public String toString() { |
| 105 | + return "{redirectUri=" + redirectUri + ", state=" + state + ", nonce=" + nonce + "}"; |
| 106 | + } |
| 107 | +} |
| 108 | + |
0 commit comments