-
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: ZAAS /safIdt endpoint to generate SAF ID token for authenticate…
…d user (#3220) * New ZAAS safIdt endpoint to generate SAF ID tokens for authenticated user. Signed-off-by: Petr Weinfurt <[email protected]> * IT tests for safIdt endpoint. Signed-off-by: Petr Weinfurt <[email protected]> * Address code review comments. Signed-off-by: Petr Weinfurt <[email protected]> * Remove unused class Signed-off-by: Petr Weinfurt <[email protected]> * Fix tests Signed-off-by: Petr Weinfurt <[email protected]> * Fix IT tests Signed-off-by: Petr Weinfurt <[email protected]> * Fix unit tests Signed-off-by: Petr Weinfurt <[email protected]> * Add Controller Advice to handle exceptions. Signed-off-by: Petr Weinfurt <[email protected]> * Handle more exceptions. Signed-off-by: Petr Weinfurt <[email protected]> * Add content type and body to negative test. Signed-off-by: Petr Weinfurt <[email protected]> * Add content type and body to negative test. Signed-off-by: Petr Weinfurt <[email protected]> * Add content type and body to negative test. Signed-off-by: Petr Weinfurt <[email protected]> * Add negative tests with valid Okta token and no mapping. Signed-off-by: Petr Weinfurt <[email protected]> * Fix Rest assured RequestSpec preparation. Signed-off-by: Petr Weinfurt <[email protected]> * Checkout the main branch before Sonar scan to resolve issue 'Could not find ref 'v2.x.x' in refs/heads, refs/remotes/upstream or refs/remotes/origin.' Signed-off-by: Petr Weinfurt <[email protected]> * Fetch the main branch before Sonar scan to resolve issue 'Could not find ref 'v2.x.x' in refs/heads, refs/remotes/upstream or refs/remotes/origin.' Signed-off-by: Petr Weinfurt <[email protected]> * Replace deprecated sonar.login property Signed-off-by: Petr Weinfurt <[email protected]> * Fetch depth 0 Signed-off-by: Petr Weinfurt <[email protected]> * Handle TokenNotValid and TokenExpired exception with 401 response. Signed-off-by: Petr Weinfurt <[email protected]> --------- Signed-off-by: Petr Weinfurt <[email protected]> Signed-off-by: Pavel Jares <[email protected]>
- Loading branch information
Showing
11 changed files
with
615 additions
and
109 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
99 changes: 99 additions & 0 deletions
99
gateway-service/src/main/java/org/zowe/apiml/gateway/zaas/ZaasExceptionHandler.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,99 @@ | ||
/* | ||
* 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.zaas; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.zowe.apiml.gateway.security.service.saf.SafIdtAuthException; | ||
import org.zowe.apiml.gateway.security.service.saf.SafIdtException; | ||
import org.zowe.apiml.gateway.security.service.schema.source.AuthSchemeException; | ||
import org.zowe.apiml.gateway.security.ticket.ApplicationNameNotFoundException; | ||
import org.zowe.apiml.message.api.ApiMessageView; | ||
import org.zowe.apiml.message.core.MessageService; | ||
import org.zowe.apiml.passticket.IRRPassTicketGenerationException; | ||
import org.zowe.apiml.security.common.token.TokenExpireException; | ||
import org.zowe.apiml.security.common.token.TokenNotValidException; | ||
|
||
import javax.management.ServiceNotFoundException; | ||
|
||
@ControllerAdvice | ||
@RequiredArgsConstructor | ||
public class ZaasExceptionHandler { | ||
private final MessageService messageService; | ||
|
||
@ExceptionHandler(value = {IRRPassTicketGenerationException.class}) | ||
public ResponseEntity<ApiMessageView> handlePassTicketException(IRRPassTicketGenerationException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.security.ticket.generateFailed", | ||
ex.getErrorCode().getMessage()).mapToView(); | ||
return ResponseEntity | ||
.status(ex.getHttpStatus()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {SafIdtException.class, SafIdtAuthException.class}) | ||
public ResponseEntity<ApiMessageView> handleSafIdtExceptions(RuntimeException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.security.idt.failed", ex.getMessage()).mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {ApplicationNameNotFoundException.class}) | ||
public ResponseEntity<ApiMessageView> handleApplIdNotFoundException(ApplicationNameNotFoundException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.security.ticket.invalidApplicationName").mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {ServiceNotFoundException.class}) | ||
public ResponseEntity<ApiMessageView> handleServiceNotFoundException(ServiceNotFoundException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.zaas.zosmf.noZosmfTokenReceived", ex.getMessage()).mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.SERVICE_UNAVAILABLE) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {IllegalStateException.class}) | ||
public ResponseEntity<ApiMessageView> handleZoweJwtCreationErrors(IllegalStateException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.zaas.zoweJwt.noToken", ex.getMessage()).mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {TokenNotValidException.class, AuthSchemeException.class}) | ||
public ResponseEntity<ApiMessageView> handleTokenNotValidException(RuntimeException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.gateway.security.invalidToken").mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
|
||
@ExceptionHandler(value = {TokenExpireException.class}) | ||
public ResponseEntity<ApiMessageView> handleTokenExpiredException(TokenExpireException ex) { | ||
ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.gateway.security.expiredToken").mapToView(); | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(messageView); | ||
} | ||
} |
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.