-
Notifications
You must be signed in to change notification settings - Fork 64
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: Support OIDC token to authenticate in API Catalog #3925
Open
pj892031
wants to merge
15
commits into
v3.x.x
Choose a base branch
from
reboot/oidc-catalog
base: v3.x.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
648f107
draft
pj892031 826b881
minor changes
pj892031 9b00de8
set authentication scheme on API Catalog
pj892031 07eb49a
test system environment
pj892031 f2172cb
Merge branch 'v3.x.x' into reboot/oidc-catalog
pj892031 d3d3fc7
fix unit tests
pj892031 a927241
Merge branch 'v3.x.x' into reboot/oidc-catalog
pj892031 239e733
fix npm tests
pj892031 192a6b3
code review
pj892031 e316119
unit tests to validate callers
pj892031 a84b4ef
Merge branch 'v3.x.x' into reboot/oidc-catalog
pj892031 0ce4ea3
ignore sonar issue
pj892031 0c9686d
cache of providers
pj892031 1a94dbe
fix response code
pj892031 c2b0266
Merge branch 'v3.x.x' into reboot/oidc-catalog
pj892031 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
35 changes: 35 additions & 0 deletions
35
api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/security/OidcUtils.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,35 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.apicatalog.security; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
@UtilityClass | ||
public class OidcUtils { | ||
|
||
private String PREFIX = "ZWE_components_gateway_spring_security_oauth2_client_"; | ||
|
||
public List<String> getOidcProvider() { | ||
return System.getenv().keySet().stream() | ||
.filter(key -> StringUtils.startsWith(key, PREFIX)) | ||
.map(key -> key.substring(PREFIX.length())) | ||
.map(key -> key.split("_")) | ||
.filter(parts -> parts.length > 2) | ||
.map(parts -> parts[1]) | ||
.distinct() | ||
.sorted() | ||
.toList(); | ||
} | ||
|
||
} |
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
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 |
---|---|---|
|
@@ -172,6 +172,7 @@ eureka: | |
|
||
authentication: | ||
sso: true | ||
scheme: zoweJwt | ||
client: | ||
healthcheck: | ||
enabled: true | ||
|
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
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ import WarningIcon from '@material-ui/icons/Warning'; | |
import Spinner from '../Spinner/Spinner'; | ||
import './Login.css'; | ||
import Footer from '../Footer/Footer'; | ||
import getBaseUrl from "../../helpers/urls"; | ||
|
||
function Login(props) { | ||
const [username, setUsername] = useState(''); | ||
|
@@ -42,6 +43,9 @@ function Login(props) { | |
const [warning, setWarning] = useState(false); | ||
const [submitted, setSubmitted] = useState(false); | ||
|
||
const [oidcProvidersLoadingStarted, setOidcProviderLoadingStarted] = useState(false); | ||
const [oidcProviders, setOidcProviders] = useState([]); | ||
|
||
const { returnToLogin, login, authentication, isFetching, validateInput } = props; | ||
const enterNewPassMsg = 'Enter a new password for account'; | ||
const invalidPassMsg = 'The specified username or password is invalid.'; | ||
|
@@ -122,6 +126,21 @@ function Login(props) { | |
setSubmitted(true); | ||
} | ||
|
||
function loadOidcProviders() { | ||
if (!oidcProvidersLoadingStarted) { | ||
setOidcProviderLoadingStarted(true); | ||
fetch(`${getBaseUrl()}/oidc/provider`).then(resp => | ||
resp.json().then(json => { | ||
console.log('json') | ||
setOidcProviders(json) | ||
return json | ||
}) | ||
).catch(() => setOidcProviderLoadingStarted(false)) | ||
} | ||
} | ||
|
||
loadOidcProviders(); | ||
|
||
let errorData = { messageText: null, expired: false, invalidNewPassword: true, invalidCredentials: false }; | ||
if ( | ||
authentication !== undefined && | ||
|
@@ -299,6 +318,17 @@ function Login(props) { | |
)} | ||
</FormControl> | ||
<div className="login-btns" id="loginButton"> | ||
{ | ||
oidcProviders.map(oidcProvider => | ||
<Button | ||
variant="contained" | ||
style={{ marginRight: '10px' }} | ||
onClick={() => window.location = `/gateway/oauth2/authorization/${oidcProvider}?returnUrl=${encodeURIComponent(window.location.href.split('#')[0])}`} | ||
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. "window.location" breaks unit tests 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. fixed, it was a different reason |
||
> | ||
Login with {oidcProvider} | ||
</Button>) | ||
} | ||
|
||
<Button | ||
variant="contained" | ||
color="primary" | ||
|
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
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
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
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
37 changes: 37 additions & 0 deletions
37
...curity-common/src/main/java/org/zowe/apiml/security/common/content/OidcContentFilter.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,37 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.security.common.content; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.zowe.apiml.security.common.error.ResourceAccessExceptionHandler; | ||
import org.zowe.apiml.security.common.handler.FailedAuthenticationHandler; | ||
import org.zowe.apiml.security.common.token.TokenAuthentication; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.zowe.apiml.constants.ApimlConstants.HEADER_OIDC_TOKEN; | ||
import static org.zowe.apiml.security.common.token.TokenAuthentication.Type.OIDC; | ||
|
||
public class OidcContentFilter extends AbstractSecureContentFilter { | ||
|
||
public OidcContentFilter(AuthenticationManager authenticationManager, FailedAuthenticationHandler authenticationFailureHandler, ResourceAccessExceptionHandler resourceAccessExceptionHandler) { | ||
super(authenticationManager, authenticationFailureHandler, resourceAccessExceptionHandler, new String[0]); | ||
} | ||
|
||
@Override | ||
protected Optional<AbstractAuthenticationToken> extractContent(HttpServletRequest request) { | ||
return Optional.ofNullable(request.getHeader(HEADER_OIDC_TOKEN)) | ||
.map(token -> new TokenAuthentication(token, OIDC)); | ||
} | ||
|
||
} |
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.
maybe store the value for subsequent calls
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.
done in the controller