-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Passticket endpoint for ZAAS component (#3125)
* Add empty ZAAS controller Signed-off-by: Petr Weinfurt <[email protected]> * The /zaas/ticket endpoint Signed-off-by: Petr Weinfurt <[email protected]> * Testing security configuration for x509 and basic auth. Signed-off-by: Petr Weinfurt <[email protected]> * OIDC authentication filter Signed-off-by: Petr Weinfurt <[email protected]> * OIDC authentication filter tests Signed-off-by: Petr Weinfurt <[email protected]> * Move the security filter into a new configuration class Signed-off-by: at670475 <[email protected]> * fix bean Signed-off-by: at670475 <[email protected]> * Support JWT as source (only with client cert) + test Signed-off-by: sj895092 <[email protected]> * Fix JWT authentication filter. Add integration tests. Signed-off-by: Petr Weinfurt <[email protected]> * ZaasController unit tests. Signed-off-by: Petr Weinfurt <[email protected]> * TEST - disable some integration tests. Signed-off-by: Petr Weinfurt <[email protected]> * Remove condition for OIDC Auth source service. Signed-off-by: Petr Weinfurt <[email protected]> * Fix checkstyle Signed-off-by: Petr Weinfurt <[email protected]> * Fix broken test Signed-off-by: Petr Weinfurt <[email protected]> * Remove dependency on Zuul RequestContext. Add simple filter to extract authentication source from request. Signed-off-by: Petr Weinfurt <[email protected]> * add extract auth source filter Signed-off-by: achmelo <[email protected]> * Working zaas controller with request attribute Signed-off-by: Petr Weinfurt <[email protected]> * add filters directly Signed-off-by: achmelo <[email protected]> * Fix gateway unit tests Signed-off-by: Petr Weinfurt <[email protected]> * Exception handling Signed-off-by: Petr Weinfurt <[email protected]> * Fix integration tests Signed-off-by: Petr Weinfurt <[email protected]> * Cleanup. Add some more unit tests. Signed-off-by: Petr Weinfurt <[email protected]> * Test ZaasController with mockMvc. Signed-off-by: Petr Weinfurt <[email protected]> --------- Signed-off-by: Petr Weinfurt <[email protected]> Signed-off-by: at670475 <[email protected]> Signed-off-by: sj895092 <[email protected]> Signed-off-by: achmelo <[email protected]> Co-authored-by: Andrea Tabone <[email protected]> Co-authored-by: sj895092 <[email protected]> Co-authored-by: achmelo <[email protected]>
- Loading branch information
1 parent
aef60d4
commit b9e9958
Showing
30 changed files
with
767 additions
and
137 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
gateway-service/src/main/java/org/zowe/apiml/gateway/controllers/ZaasController.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,72 @@ | ||
/* | ||
* 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.controllers; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.zowe.apiml.gateway.security.service.schema.source.AuthSource; | ||
import org.zowe.apiml.message.api.ApiMessageView; | ||
import org.zowe.apiml.message.core.MessageService; | ||
import org.zowe.apiml.passticket.IRRPassTicketGenerationException; | ||
import org.zowe.apiml.passticket.PassTicketService; | ||
import org.zowe.apiml.ticket.TicketRequest; | ||
import org.zowe.apiml.ticket.TicketResponse; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping(ZaasController.CONTROLLER_PATH) | ||
@Slf4j | ||
public class ZaasController { | ||
public static final String CONTROLLER_PATH = "gateway/zaas"; | ||
|
||
private final PassTicketService passTicketService; | ||
private final MessageService messageService; | ||
|
||
@PostMapping(path = "ticket", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(summary = "Provides PassTicket for authenticated user.") | ||
@ResponseBody | ||
public ResponseEntity<Object> getPassTicket(@RequestBody TicketRequest ticketRequest, @RequestAttribute("zaas.auth.source") AuthSource.Parsed authSource) { | ||
|
||
if (StringUtils.isEmpty(authSource.getUserId())) { | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.build(); | ||
} | ||
|
||
final String applicationName = ticketRequest.getApplicationName(); | ||
if (StringUtils.isBlank(applicationName)) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.security.ticket.invalidApplicationName").mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(messageView); | ||
} | ||
|
||
String ticket = null; | ||
try { | ||
ticket = passTicketService.generate(authSource.getUserId(), applicationName); | ||
} catch (IRRPassTicketGenerationException e) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.security.ticket.generateFailed", | ||
e.getErrorCode().getMessage()).mapToView(); | ||
return ResponseEntity | ||
.status(e.getHttpStatus()) | ||
.body(messageView); | ||
} | ||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.body(new TicketResponse(null, authSource.getUserId(), applicationName, ticket)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...way-service/src/main/java/org/zowe/apiml/gateway/filters/pre/ExtractAuthSourceFilter.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,53 @@ | ||
/* | ||
* 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.filters.pre; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.authentication.InsufficientAuthenticationException; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
import org.zowe.apiml.gateway.security.service.schema.source.AuthSource; | ||
import org.zowe.apiml.gateway.security.service.schema.source.AuthSourceService; | ||
import org.zowe.apiml.security.common.error.AuthExceptionHandler; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ExtractAuthSourceFilter extends OncePerRequestFilter { | ||
static final String AUTH_SOURCE_ATTR = "zaas.auth.source"; | ||
|
||
private final AuthSourceService authSourceService; | ||
private final AuthExceptionHandler authExceptionHandler; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
try { | ||
Optional<AuthSource> authSource = authSourceService.getAuthSourceFromRequest(request); | ||
if (authSource.isPresent()) { | ||
AuthSource.Parsed parsed = authSourceService.parse(authSource.get()); | ||
request.setAttribute(AUTH_SOURCE_ATTR, parsed); | ||
filterChain.doFilter(request, response); | ||
} else { | ||
throw new InsufficientAuthenticationException("No authentication source found in the request."); | ||
} | ||
} | ||
catch (RuntimeException ex) { | ||
authExceptionHandler.handleException(request, response, ex); | ||
} | ||
|
||
} | ||
} |
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
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
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
Oops, something went wrong.