-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance x509 authentication scheme to support client certificat…
…es (part 2) (#2260) * feat: Enhance x509 authentication scheme to support client certificates (part 1) move the logic which gets authentication source from request to scheme * feat: Enhance x509 authentication scheme to support client certificates (part 2) - validate extended key usage for X509 certificate in getAuthSourceFromRequest() method; - use AuthSourceService in X509Scheme. Signed-off-by: Yelyzaveta Chebanova <[email protected]> * merge with master branch Signed-off-by: Yelyzaveta Chebanova <[email protected]> * feat: Enhance x509 authentication scheme to support client certificates (part 2) -remove unnecessary usage of Serializable Signed-off-by: Yelyzaveta Chebanova <[email protected]> * feat: Enhance x509 authentication scheme to support client certificates (part 2) - cleanup Signed-off-by: Yelyzaveta Chebanova <[email protected]>
- Loading branch information
1 parent
d5d6f93
commit d888a11
Showing
13 changed files
with
532 additions
and
190 deletions.
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
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
55 changes: 55 additions & 0 deletions
55
...n/java/org/zowe/apiml/gateway/security/service/schema/source/X509CNAuthSourceService.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,55 @@ | ||
/* | ||
* 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.gateway.security.service.schema.source; | ||
|
||
import com.netflix.zuul.context.RequestContext; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Optional; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.zowe.apiml.gateway.security.login.x509.X509CommonNameUserMapper; | ||
import org.zowe.apiml.gateway.security.service.AuthenticationService; | ||
import org.zowe.apiml.gateway.security.service.TokenCreationService; | ||
|
||
/** | ||
* Custom implementation of AuthSourceService interface which uses client certificate as an authentication source. | ||
* This implementation uses instance of {@link X509CommonNameUserMapper} for validation and parsing of the client certificate. | ||
*/ | ||
@Slf4j | ||
public class X509CNAuthSourceService extends X509AuthSourceService { | ||
public X509CNAuthSourceService(X509CommonNameUserMapper mapper, TokenCreationService tokenService, AuthenticationService authenticationService) { | ||
super(mapper, tokenService, authenticationService); | ||
} | ||
|
||
/** | ||
* Gets client certificate from request. | ||
* <p> | ||
* First try to get certificate from custom attribute "client.auth.X509Certificate". | ||
* If certificate not found - try to get it from standard attribute "javax.servlet.request.X509Certificate". | ||
* In case of multiple certificates only the first one will be used. | ||
* <p> | ||
* @return Optional<AuthSource> with client certificate of Optional.empty() | ||
*/ | ||
@Override | ||
public Optional<AuthSource> getAuthSourceFromRequest() { | ||
final RequestContext context = RequestContext.getCurrentContext(); | ||
|
||
// get certificate from custom attribute "client.auth.X509Certificate" | ||
X509Certificate clientCert = super.getCertificateFromRequest(context.getRequest(), "client.auth.X509Certificate"); | ||
if (clientCert == null) { | ||
// get certificate from standard attribute "javax.servlet.request.X509Certificate" | ||
clientCert = super.getCertificateFromRequest(context.getRequest(), "javax.servlet.request.X509Certificate"); | ||
} | ||
if (!isValid(clientCert)) { | ||
clientCert = null; | ||
} | ||
return clientCert == null ? Optional.empty() : Optional.of(new X509AuthSource(clientCert)); | ||
} | ||
|
||
} |
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.