-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28670 Add support for custom REST HTTP endpoint extensions #13131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8b0f8f
IGNITE-28670 Add support for custom REST HTTP endpoint extensions
NSAmelchev 23b0674
fixed codestyle
NSAmelchev 1d34882
review fixes
NSAmelchev b386e66
review fixes
NSAmelchev e61e88e
review fixes
NSAmelchev e5f9775
Merge remote-tracking branch 'refs/remotes/apache/master' into ignite…
NSAmelchev aafd61f
fixed dependency
NSAmelchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...org/apache/ignite/internal/processors/rest/protocols/http/jetty/AuthenticationFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.ignite.internal.processors.rest.protocols.http.jetty; | ||
|
|
||
| import java.io.IOException; | ||
| import jakarta.servlet.Filter; | ||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.ServletRequest; | ||
| import jakarta.servlet.ServletResponse; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import org.apache.ignite.internal.GridKernalContext; | ||
| import org.apache.ignite.internal.processors.rest.GridRestProcessor; | ||
| import org.apache.ignite.internal.processors.security.SecurityContext; | ||
| import org.apache.ignite.internal.thread.context.Scope; | ||
| import org.apache.ignite.internal.util.typedef.internal.U; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import static org.apache.ignite.internal.processors.rest.protocols.http.jetty.GridJettyRestHandler.sessionToken; | ||
|
|
||
| /** | ||
| * Servlet filter that authenticates REST requests via session token. | ||
| */ | ||
| public class AuthenticationFilter implements Filter { | ||
| /** */ | ||
| private final GridKernalContext ctx; | ||
|
|
||
| /** */ | ||
| public AuthenticationFilter(GridKernalContext ctx) { | ||
| this.ctx = ctx; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void doFilter( | ||
| ServletRequest req, | ||
| ServletResponse res, | ||
| FilterChain chain | ||
| ) throws IOException, ServletException { | ||
| SecurityContext secCtx = resolveSession((HttpServletRequest)req); | ||
|
|
||
| if (secCtx == null) { | ||
| ((HttpServletResponse)res).sendError(HttpServletResponse.SC_UNAUTHORIZED, | ||
| "Missing or invalid authentication token (maybe expired session)"); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| try (Scope ignored = ctx.security().withContext(secCtx)) { | ||
| chain.doFilter(req, res); | ||
| } | ||
| } | ||
|
|
||
| /** @return Security context for given session token, or {@code null} if none found. */ | ||
| @Nullable private SecurityContext resolveSession(HttpServletRequest req) { | ||
| byte[] token = sessionToken(req.getParameter("sessionToken")); | ||
|
|
||
| if (token == null) | ||
| return null; | ||
|
|
||
| return ((GridRestProcessor)ctx.rest()).securityContext(U.bytesToUuid(token, 0)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteRestExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.ignite.internal.processors.rest.protocols.http.jetty; | ||
|
|
||
| import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
|
||
| /** | ||
| * Extension point for registering custom HTTP REST endpoints in the Jetty REST protocol. | ||
| * <p> | ||
| * Each extension is configured within an isolated {@link ServletContextHandler} instance | ||
| * managed by the Ignite REST subsystem. | ||
| * Extensions are discovered using Java {@link java.util.ServiceLoader}. | ||
| * <p> | ||
| * Implementations are responsible for: | ||
| * <ul> | ||
| * <li>Configuring the servlet context path via | ||
| * {@link ServletContextHandler#setContextPath(String)}.</li> | ||
| * <li>Registering servlets, filters, and related HTTP components.</li> | ||
| * </ul> | ||
| * <p> | ||
| * Context paths must be unique across all registered extensions. | ||
| * <p> | ||
| * Authentication and other common infrastructure are configured by Ignite. | ||
| */ | ||
| public interface IgniteRestExtension { | ||
| /** | ||
| * Configures the REST extension. | ||
| * | ||
| * @param ctx Servlet context handler dedicated to this extension. | ||
| * @throws Exception If configuration failed. | ||
| */ | ||
| void configure(ServletContextHandler ctx) throws Exception; | ||
|
Check warning on line 47 in modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteRestExtension.java
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have similar (same?) logic implemented in
GridJettyRestHandler#createRequest- let's make method to call in both cases.