-
Notifications
You must be signed in to change notification settings - Fork 270
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
feat: servlet classes that use the jakarta namespace #1115
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
94 changes: 94 additions & 0 deletions
94
...ions/appengine/auth/oauth2/jakarta/AbstractAppEngineAuthorizationCodeCallbackServlet.java
This file contains 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,94 @@ | ||
/* | ||
* Copyright (c) 2024 Google Inc. | ||
* | ||
* Licensed 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 com.google.api.client.extensions.appengine.auth.oauth2.jakarta; | ||
|
||
import com.google.api.client.extensions.servlet.auth.oauth2.jakarta.AbstractAuthorizationCodeCallbackServlet; | ||
import com.google.appengine.api.users.UserServiceFactory; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Simple extension of {@link AbstractAuthorizationCodeCallbackServlet} that uses the currently | ||
* logged-in Google Account user, as directed in <a | ||
* href="https://cloud.google.com/appengine/docs/standard/java/config/webxml#security-auth">Security | ||
* and Authentication</a>. This uses the {@code jakarta.servlet} namespace. | ||
* | ||
* <p>Note that if there is no currently logged-in user, {@link #getUserId(HttpServletRequest)} will | ||
* throw a {@link NullPointerException}. Example to require login for all pages: | ||
* | ||
* <pre> | ||
* <security-constraint> | ||
* <web-resource-collection> | ||
* <web-resource-name>any</web-resource-name> | ||
* <url-pattern>/*</url-pattern> | ||
* </web-resource-collection> | ||
* <auth-constraint> | ||
* <role-name>*</role-name> | ||
* </auth-constraint> | ||
* </security-constraint> | ||
* </pre> | ||
* | ||
* <p>Sample usage: | ||
* | ||
* <pre> | ||
* public class ServletCallbackSample extends AbstractAppEngineAuthorizationCodeCallbackServlet { | ||
* | ||
* @Override | ||
* protected void onSuccess(HttpServletRequest req, HttpServletResponse resp, Credential credential) | ||
* throws ServletException, IOException { | ||
* resp.sendRedirect("/"); | ||
* } | ||
* | ||
* @Override | ||
* protected void onError( | ||
* HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeResponseUrl errorResponse) | ||
* throws ServletException, IOException { | ||
* // handle error | ||
* } | ||
* | ||
* @Override | ||
* protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException { | ||
* GenericUrl url = new GenericUrl(req.getRequestURL().toString()); | ||
* url.setRawPath("/oauth2callback"); | ||
* return url.build(); | ||
* } | ||
* | ||
* @Override | ||
* protected AuthorizationCodeFlow initializeFlow() throws IOException { | ||
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(), | ||
* new UrlFetchTransport(), | ||
* new GsonFactory(), | ||
* new GenericUrl("https://server.example.com/token"), | ||
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"), | ||
* "s6BhdRkqt3", | ||
* "https://server.example.com/authorize").setCredentialStore(new AppEngineCredentialStore()) | ||
* .build(); | ||
* } | ||
* </pre> | ||
* | ||
* @since 1.36.0 | ||
*/ | ||
public abstract class AbstractAppEngineAuthorizationCodeCallbackServlet | ||
extends AbstractAuthorizationCodeCallbackServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected String getUserId(HttpServletRequest req) throws ServletException, IOException { | ||
// Use GAE Standard's users service to fetch the current user of the application. | ||
return UserServiceFactory.getUserService().getCurrentUser().getUserId(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...t/extensions/appengine/auth/oauth2/jakarta/AbstractAppEngineAuthorizationCodeServlet.java
This file contains 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,88 @@ | ||
/* | ||
* Copyright (c) 2024 Google Inc. | ||
* | ||
* Licensed 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 com.google.api.client.extensions.appengine.auth.oauth2.jakarta; | ||
|
||
import com.google.api.client.extensions.servlet.auth.oauth2.jakarta.AbstractAuthorizationCodeServlet; | ||
import com.google.appengine.api.users.UserServiceFactory; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Simple extension of {@link AbstractAuthorizationCodeServlet} that uses the currently logged-in | ||
* Google Account user, as directed in <a | ||
* href="https://cloud.google.com/appengine/docs/standard/java/config/webxml#security-auth">Security | ||
* and Authentication</a>. This uses the {@code jakarta.servlet} namespace. | ||
* | ||
* <p>Note that if there is no currently logged-in user, {@link #getUserId(HttpServletRequest)} will | ||
* throw a {@link NullPointerException}. Example to require login for all pages: | ||
* | ||
* <pre> | ||
* <security-constraint> | ||
* <web-resource-collection> | ||
* <web-resource-name>any</web-resource-name> | ||
* <url-pattern>/*</url-pattern> | ||
* </web-resource-collection> | ||
* <auth-constraint> | ||
* <role-name>*</role-name> | ||
* </auth-constraint> | ||
* </security-constraint> | ||
* </pre> | ||
* | ||
* <p>Sample usage: | ||
* | ||
* <pre> | ||
* public class ServletSample extends AbstractAppEngineAuthorizationCodeServlet { | ||
* | ||
* @Override | ||
* protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
* throws IOException { | ||
* // do stuff | ||
* } | ||
* | ||
* @Override | ||
* protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException { | ||
* GenericUrl url = new GenericUrl(req.getRequestURL().toString()); | ||
* url.setRawPath("/oauth2callback"); | ||
* return url.build(); | ||
* } | ||
* | ||
* @Override | ||
* protected AuthorizationCodeFlow initializeFlow() throws IOException { | ||
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(), | ||
* new UrlFetchTransport(), | ||
* new GsonFactory(), | ||
* new GenericUrl("https://server.example.com/token"), | ||
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"), | ||
* "s6BhdRkqt3", | ||
* "https://server.example.com/authorize").setCredentialStore(new AppEngineCredentialStore()) | ||
* .build(); | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* @since 1.36.0 | ||
*/ | ||
public abstract class AbstractAppEngineAuthorizationCodeServlet | ||
extends AbstractAuthorizationCodeServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected String getUserId(HttpServletRequest req) throws ServletException, IOException { | ||
// Use GAE Standard's users service to fetch the current user of the application. | ||
return UserServiceFactory.getUserService().getCurrentUser().getUserId(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ain/java/com/google/api/client/extensions/appengine/auth/oauth2/jakarta/package-info.java
This file contains 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,21 @@ | ||
/* | ||
* Copyright (c) 2024 Google Inc. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
/** | ||
* OAuth 2.0 utilities that help simplify the authorization flow on Google App Engine. This package | ||
* uses the {@code jakarta.servlet} namespace. | ||
* | ||
* @since 1.36.0 | ||
*/ | ||
package com.google.api.client.extensions.appengine.auth.oauth2.jakarta; |
This file contains 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.
1.36.0 is it the real new version that will be pushed? Otherwise, change it (and other files)
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.
Also curious if you need to configure Kokoro cfg files to enable SBOM generation (here and in all Cloud APIs area?)
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.
The latest is 1.35.0. This 1.36.0 is the real value to be released.
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.
Checking SBOM generation.
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.
Confirmed Kokoro configs are set up (log). Search for
sbom.spdx.json
.