Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
7a79102
API for delegating credentials to generate a z/OS PassTicket based on…
Goutham024 Oct 27, 2025
d8d382f
Added the unit test for sts controller
Goutham024 Oct 28, 2025
6ece886
Merge branch 'v3.x.x' into passticket-delegations
Goutham024 Oct 28, 2025
92c9cbb
API for delegating credentials to generate a z/OS PassTicket based on…
Goutham024 Oct 27, 2025
bf1bb1d
Added the unit test for sts controller
Goutham024 Oct 28, 2025
3e16c67
fix: modulith mode does not distribute logout (#4191)
pablocarle Jul 2, 2025
2181db8
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.21'.
zowe-robot Jul 4, 2025
35d7241
[Gradle Release plugin] Create new version: 'v3.2.22-SNAPSHOT'.
zowe-robot Jul 4, 2025
783b74f
[skip ci] Update version
zowe-robot Jul 4, 2025
13aa556
chore: Update all non-major dependencies (v3.x.x) (#4134)
zowe-robot Jul 7, 2025
6543602
chore: Update all non-major dependencies (v3.x.x) (#4199)
zowe-robot Jul 8, 2025
71c78b5
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.22'.
zowe-robot Jul 11, 2025
6f438a8
[Gradle Release plugin] Create new version: 'v3.2.23-SNAPSHOT'.
zowe-robot Jul 11, 2025
99e60f3
[skip ci] Update version
zowe-robot Jul 11, 2025
363a724
chore: Update all non-major dependencies (v3.x.x) (#4200)
zowe-robot Jul 14, 2025
9a71046
chore: Enable Modulith HA tests (#4194)
pablocarle Jul 15, 2025
2add61e
chore: swagger-ui-react 5.22.0 upgrade (#4214)
richard-salac Jul 15, 2025
e084bfe
chore: Update all non-major dependencies (v3.x.x) (#4213)
zowe-robot Jul 15, 2025
b803668
fix: API ML startup message in modulith mode (#4216)
pablocarle Jul 15, 2025
54a57d1
fix: Fix SAF auth check in non-modulith (#4212)
taban03 Jul 16, 2025
5a7a011
refactor: Include Caching service in the Modulith (#4190)
taban03 Jul 17, 2025
f62f638
fix: unresponsive eureka (#4223)
achmelo Jul 17, 2025
f7f8c75
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.23'.
zowe-robot Jul 18, 2025
f930bfd
[Gradle Release plugin] Create new version: 'v3.2.24-SNAPSHOT'.
zowe-robot Jul 18, 2025
8673d52
[skip ci] Update version
zowe-robot Jul 18, 2025
a3429cc
fix: update start.sh settings for caching service (#4226)
pablocarle Jul 18, 2025
b733de9
feat: support independent response time route setting (#3981)
pablocarle Jul 18, 2025
d4c77c9
chore: Update all non-major dependencies (v3.x.x) (#4218)
zowe-robot Jul 18, 2025
57c6841
fix: Secure x-forwarded-* headers from untrusted proxies (#4171)
richard-salac Jul 18, 2025
a33fb30
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.24'.
zowe-robot Jul 25, 2025
83b2686
[Gradle Release plugin] Create new version: 'v3.2.25-SNAPSHOT'.
zowe-robot Jul 25, 2025
6fa849c
[skip ci] Update version
zowe-robot Jul 25, 2025
eaad4b9
fix: Use Gateway's address space suffix in modulith (#4237)
pablocarle Jul 25, 2025
f48ceca
refactor: Including catalog as a part of Modulith module apiml (#4189)
pavel-jares-bcm Jul 25, 2025
3143af6
fix: collect fixes to run modulith in z/OS (#4227)
pablocarle Jul 25, 2025
3ca279a
fix: ZAAS startup with `apiml.security.oidc.validationType` = `endpoi…
arxioly Jul 28, 2025
c93e2fe
fix: api catalog startup message (#4240)
pablocarle Jul 29, 2025
1afe38b
refactor: Call refresh of static services endpoint via API to reduce …
pavel-jares-bcm Jul 29, 2025
51d6578
chore: Upgrade Nimbus Jose JWT to 10.0.2 (#4245)
pavel-jares-bcm Jul 29, 2025
84e703c
chore: Update all non-major dependencies (v3.x.x) (#4229)
zowe-robot Jul 29, 2025
c7fdf64
refactor: Replacement of Apache HTTP client by WebClient in API Catal…
pavel-jares-bcm Jul 31, 2025
00e663e
fix: multi-tenancy deployment in single-service(modulith) mode (#4249)
achmelo Jul 31, 2025
7d9c1ca
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.25'.
zowe-robot Aug 1, 2025
f7374e1
[Gradle Release plugin] Create new version: 'v3.2.26-SNAPSHOT'.
zowe-robot Aug 1, 2025
83bceae
[skip ci] Update version
zowe-robot Aug 1, 2025
5dcff44
chore: add modulith on z/os integration test tasks (#4253)
pablocarle Aug 4, 2025
db84b2f
fix: update max request header size (#4257)
pablocarle Aug 5, 2025
bad8221
chore: Update all non-major dependencies (v3.x.x) (#4248)
zowe-robot Aug 5, 2025
15d679a
fix: prefer legacy component properties in modulith mode (#4258)
pablocarle Aug 6, 2025
70c5795
Update CHANGELOG.md (#4233)
balhar-jakub Aug 6, 2025
91d0d80
fix: Caching Service failing to start when not all ports avaliable on…
arxioly Aug 6, 2025
899840b
feat: adding PATCH in the list of CORS allowed methods (#4254)
nxhafa Aug 6, 2025
bc78b33
fix: configure methods from zowe, catch exception (#4261)
achmelo Aug 7, 2025
e5f57f8
[Gradle Release plugin] [skip ci] Before tag commit 'v3.2.26'.
zowe-robot Aug 7, 2025
da5f015
[Gradle Release plugin] Create new version: 'v3.3.0-SNAPSHOT'.
zowe-robot Aug 7, 2025
32853ed
[skip ci] Update version
zowe-robot Aug 7, 2025
d4d1710
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.0'.
zowe-robot Aug 7, 2025
6aae669
[Gradle Release plugin] Create new version: 'v3.3.1-SNAPSHOT'.
zowe-robot Aug 7, 2025
462c4b4
[skip ci] Update version
zowe-robot Aug 7, 2025
94a0ebd
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.1'.
zowe-robot Aug 8, 2025
b26f5ad
[Gradle Release plugin] Create new version: 'v3.3.2-SNAPSHOT'.
zowe-robot Aug 8, 2025
0cee8e4
[skip ci] Update version
zowe-robot Aug 8, 2025
4f0655c
chore: Update all non-major dependencies (v3.x.x) (#4259)
zowe-robot Aug 8, 2025
4f935e0
chore: Update all non-major dependencies (v3.x.x) (#4264)
zowe-robot Aug 12, 2025
c1569f7
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.2'.
zowe-robot Aug 15, 2025
48e7721
[Gradle Release plugin] Create new version: 'v3.3.3-SNAPSHOT'.
zowe-robot Aug 15, 2025
f460006
[skip ci] Update version
zowe-robot Aug 15, 2025
a844ad3
Disable retry for configured services (#4265)
richard-salac Aug 15, 2025
abb7dd4
fix: Fix URLs for onboarding when AT-TLS is enabled (#4169)
pavel-jares-bcm Aug 15, 2025
b17896f
fix: AT-TLS mode without reading keystore (#4271)
pablocarle Aug 19, 2025
4566591
chore: Update all non-major dependencies (v3.x.x) (#4270)
zowe-robot Aug 20, 2025
8abe039
chore: remove twisted (#4280)
achmelo Aug 20, 2025
a5bce62
fix: WebClient used in API Catalog does not follow redirects (#4278)
pablocarle Aug 21, 2025
d44da77
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.3'.
zowe-robot Aug 22, 2025
fb116ca
[Gradle Release plugin] Create new version: 'v3.3.4-SNAPSHOT'.
zowe-robot Aug 22, 2025
1936e1e
[skip ci] Update version
zowe-robot Aug 22, 2025
e72c300
fix: websocket frame size configuration (#4277)
richard-salac Aug 22, 2025
c381a8d
chore: updates to attlsClient profile in Gateway (#4279)
nxhafa Aug 22, 2025
388b8b3
chore: Update all non-major dependencies (v3.x.x) (#4281)
zowe-robot Aug 22, 2025
18efa13
fix: attls filter in modulith mode and Ltpa2 token (#4285)
achmelo Aug 22, 2025
11c36ec
chore: Update all non-major dependencies (v3.x.x) (#4291)
zowe-robot Aug 25, 2025
33dc7c2
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.4'.
zowe-robot Aug 25, 2025
a5d656e
[Gradle Release plugin] Create new version: 'v3.3.5-SNAPSHOT'.
zowe-robot Aug 25, 2025
c247611
[skip ci] Update version
zowe-robot Aug 25, 2025
77eff20
chore: Update all non-major dependencies (v3.x.x) (#4293)
zowe-robot Aug 26, 2025
ca6de11
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.5'.
zowe-robot Aug 26, 2025
7bc622b
[Gradle Release plugin] Create new version: 'v3.3.6-SNAPSHOT'.
zowe-robot Aug 26, 2025
2261c14
[skip ci] Update version
zowe-robot Aug 26, 2025
6ddb3b1
fix: Increase stomp tests connection timeout for miniplex (#4296)
richard-salac Aug 28, 2025
665e046
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.6'.
zowe-robot Aug 29, 2025
591779b
[Gradle Release plugin] Create new version: 'v3.3.7-SNAPSHOT'.
zowe-robot Aug 29, 2025
d23de08
[skip ci] Update version
zowe-robot Aug 29, 2025
f351680
chore: Exclude discoverable-client from sonar analysis (#4298)
richard-salac Aug 29, 2025
7508894
feat: multiple OIDC providers at the same time (#4295)
achmelo Aug 29, 2025
65f979f
fix: start caching service with disabled cert verification (#4299)
achmelo Sep 2, 2025
4899161
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.7'.
zowe-robot Sep 2, 2025
46e85a6
[Gradle Release plugin] Create new version: 'v3.3.8-SNAPSHOT'.
zowe-robot Sep 2, 2025
f39e104
[skip ci] Update version
zowe-robot Sep 2, 2025
7a974e4
chore: remove obsolete caching from OIDCAuthSourceService (#4302)
richard-salac Sep 3, 2025
2521df5
chore: test ssl verification disabled (#4301)
achmelo Sep 3, 2025
797d32a
feat: Support configurable username field for oidc tokens (#4300)
richard-salac Sep 4, 2025
5182748
chore: enable gateway actuator endpoints in debug mode (#4305)
achmelo Sep 4, 2025
0a02ecb
chore: improve debug log for oidc token user mapping (#4306)
richard-salac Sep 4, 2025
a687847
fix: cherry pick apiml.gateway.servicesToDisableRetry to modulith (#4…
richard-salac Sep 4, 2025
148ddd5
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.8'.
zowe-robot Sep 5, 2025
80b53bb
[Gradle Release plugin] Create new version: 'v3.3.9-SNAPSHOT'.
zowe-robot Sep 5, 2025
a97e1f9
[skip ci] Update version
zowe-robot Sep 5, 2025
387c41e
chore: Update all non-major dependencies (v3.x.x) (#4297)
zowe-robot Sep 5, 2025
44cc788
fix: Custom Disk Health Configuration (#4269)
hrishikesh-nalawade Sep 9, 2025
2e08dbf
fix: API ML services log cleanup (#4284)
hrishikesh-nalawade Sep 10, 2025
742ba4e
Automatic update for the Changelog for v3.3.0 release (#4230)
zowe-robot Sep 10, 2025
0c35c6f
feat: (enabler-nodejs) Expose Eureka class directly to pass config (#…
pketki Sep 10, 2025
ea4d138
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.9'.
zowe-robot Sep 12, 2025
130c6c4
[Gradle Release plugin] Create new version: 'v3.3.10-SNAPSHOT'.
zowe-robot Sep 12, 2025
f7d2c87
[skip ci] Update version
zowe-robot Sep 12, 2025
5ce00f3
Support multi-value OIDC claims for userId mapping (#4308)
richard-salac Sep 16, 2025
1137b5f
chore: Upgrade transitive dependency fileupload to 1.6.0 (#4317)
pavel-jares-bcm Sep 17, 2025
8e47499
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.10'.
zowe-robot Sep 19, 2025
d68ac08
[Gradle Release plugin] Create new version: 'v3.3.11-SNAPSHOT'.
zowe-robot Sep 19, 2025
5a1d8ed
[skip ci] Update version
zowe-robot Sep 19, 2025
3052b6f
feat: Support Keycloak as OIDC provider in integration tests (#4321)
richard-salac Sep 22, 2025
4e2e096
chore: Upgrade java dependencies (#4326)
richard-salac Sep 23, 2025
8ebfcd9
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.11'.
zowe-robot Sep 26, 2025
c283afa
[Gradle Release plugin] Create new version: 'v3.3.12-SNAPSHOT'.
zowe-robot Sep 26, 2025
6a53651
[skip ci] Update version
zowe-robot Sep 26, 2025
b52247e
fix: z/OSMF static definition for AT-TLS (#4327)
pablocarle Sep 26, 2025
8986960
fix: set redirectUri default in java code (#4329)
pablocarle Sep 29, 2025
9e7173c
fix: respect encoded slashes in redirect header (#4328)
achmelo Sep 29, 2025
477defd
chore: debug log (#4332)
achmelo Sep 29, 2025
aa85927
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.12'.
zowe-robot Sep 29, 2025
a1cd95d
[Gradle Release plugin] Create new version: 'v3.3.13-SNAPSHOT'.
zowe-robot Sep 29, 2025
80eccb1
[skip ci] Update version
zowe-robot Sep 29, 2025
698b2e0
fix: update modulith version of z/OSMF static definition (#4333)
pablocarle Sep 29, 2025
e39becc
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.13'.
zowe-robot Oct 3, 2025
324b997
[Gradle Release plugin] Create new version: 'v3.3.14-SNAPSHOT'.
zowe-robot Oct 3, 2025
b502e87
[skip ci] Update version
zowe-robot Oct 3, 2025
f6280a4
fix: avoid duplicate startup message (#4339)
achmelo Oct 3, 2025
0ee8535
fix: keep all gateways registered (#4345)
achmelo Oct 8, 2025
8e139fc
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.14'.
zowe-robot Oct 10, 2025
6ac4c63
[Gradle Release plugin] Create new version: 'v3.3.15-SNAPSHOT'.
zowe-robot Oct 10, 2025
c2d9596
[skip ci] Update version
zowe-robot Oct 10, 2025
1de6993
fix: Fix of Tomcat customizers to be supported also by reactive stuff…
pavel-jares-bcm Oct 10, 2025
36e1a3e
fix: Requirement of client certificate on ZAAS call when AT-TLS is us…
taban03 Oct 17, 2025
ce502b7
fix: correct description in API doc (#4348)
achmelo Oct 20, 2025
8827b64
chore: sperate enablers and core components release (#4353)
achmelo Oct 22, 2025
bc9c226
[skip ci] Update version
zowe-robot Oct 22, 2025
aa387c8
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.16'.
zowe-robot Oct 23, 2025
fb8ec9c
chore: separate tag for enablers (#4356)
achmelo Oct 23, 2025
465d5de
[Gradle Release plugin] [skip ci] Before tag commit 'enablers-v3.3.17'.
zowe-robot Oct 23, 2025
cf4b25d
[Gradle Release plugin] Create new version: 'enablers-v3.3.18-SNAPSHOT'.
zowe-robot Oct 23, 2025
d535742
[Gradle Release plugin] [skip ci] Before tag commit 'v3.3.16'.
zowe-robot Oct 24, 2025
28d5432
chore: env update in release (#4359)
achmelo Oct 27, 2025
97b0e61
Merge branch 'passticket-delegations' of https://github.com/Joe-Winch…
Goutham024 Oct 29, 2025
a0ea314
added the license
Goutham024 Oct 29, 2025
8eed88a
Merge branch 'v3.x.x' into passticket-delegations
Goutham024 Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ RouterFunction<ServerResponse> routes() {
.andRoute(path("/gateway/api/v1/auth/keys/public/current"), resendTo("/api/v1/auth/keys/public/current"))
.andRoute(path("/gateway/api/v1/auth/oidc-token/validate"), resendTo("/api/v1/auth/oidc-token/validate"))
.andRoute(path("/gateway/api/v1/auth/oidc/webfinger"), resendTo("/api/v1/auth/oidc/webfinger"))
.andRoute(path("/gateway/auth/check"), resendTo("/auth/check"));
.andRoute(path("/gateway/auth/check"), resendTo("/auth/check"))
.andRoute(path("/gateway/api/v1/auth/delegations/passticket"), resendTo("/api/v1/auth/delegations/passticket"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class WebSecurity {
public static final String OAUTH_2_AUTHORIZATION_URI = CONTEXT_PATH + "/oauth2/authorization/{registrationId}";
public static final String OAUTH_2_REDIRECT_URI = CONTEXT_PATH + "/login/oauth2/code/**";
public static final String OAUTH_2_REDIRECT_LOGIN_URI = CONTEXT_PATH + "/login/oauth2/code/{registrationId}";
public static final String STS_PASSTICKET_URL = "/gateway/api/v1/auth/delegations/passticket";

@Value("${apiml.security.oidc.cookie.sameSite:Lax}")
public String sameSite;
Expand Down Expand Up @@ -367,7 +368,7 @@ SecurityWebFilterChain defaultSecurityWebFilterChain(ServerHttpSecurity http) {
@Bean
@Order(1)
@ConditionalOnMissingBean(name = "modulithConfig")
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http, AuthConfigurationProperties authConfigurationProperties, AuthExceptionHandlerReactive authExceptionHandlerReactive) {
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http, AuthConfigurationProperties authConfigurationProperties, AuthExceptionHandlerReactive authExceptionHandlerReactive) {
return defaultSecurityConfig(http)
.securityMatcher(ServerWebExchangeMatchers.pathMatchers(
REGISTRY_PATH,
Expand All @@ -380,6 +381,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http, AuthConfi
CONFORMANCE_LONG_URL,
VALIDATE_SHORT_URL,
VALIDATE_LONG_URL,
STS_PASSTICKET_URL,
"/application/**"
))
.authorizeExchange(authorizeExchangeSpec -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.zaas.controllers;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.zowe.commons.usermap.MapperResponse;
import org.zowe.apiml.passticket.PassTicketService;
import org.zowe.apiml.zaas.security.mapping.NativeMapperWrapper;


/**
* Controller offer method to control security. It can contain method for user
* and also method for calling services
* by gateway to distribute state of authentication between nodes.
*/
@RequiredArgsConstructor
@RestController
@RequestMapping(StsController.CONTROLLER_PATH)
@Slf4j
public class StsController {

@Value("${apiml.security.oidc.registry:}")
protected String registry;

private final PassTicketService passTicketService;
private final NativeMapperWrapper nativeMapper;

public static final String CONTROLLER_PATH = "/zaas/api/v1/auth/delegations";
public static final String PASSTICKET_PATH = "/passticket";

@PostMapping(value = StsController.PASSTICKET_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "The authenticated service uses this endpoint to request a PassTicket for a target user (identified by emailId) for a specific z/OS application (applid). The incoming Bearer token is validated to ensure the requester is authorized to perform delegation before the ticket is generated.", tags = {
"Security" }, security = {
@SecurityRequirement(name = "Bearer"),
@SecurityRequirement(name = "LoginBasicAuth"),
@SecurityRequirement(name = "ClientCert")
})
public ResponseEntity<PassTicketResponse> getPassTicket(@RequestBody PassTicketRequest passticketRequest)
throws Exception {
String applID = passticketRequest.getApplId();
String emailID = passticketRequest.getEmailId();
String zosUserId = "";

if (Strings.isBlank(emailID) || Strings.isBlank(applID)) {
return ResponseEntity.badRequest().build();
}
try {
MapperResponse response = nativeMapper.getUserIDForDN(emailID, registry);
if (response.getRc() == 0 && StringUtils.isNotEmpty(response.getUserId())) {
zosUserId = response.getUserId();
}
log.info("Getting ZOS_User_id: {} ", zosUserId);
var ticket = passTicketService.generate(zosUserId, applID);
log.info("Getting request email id: {} and ZOS_Userid: {}", emailID, zosUserId);
return ResponseEntity.ok(new PassTicketResponse(ticket, zosUserId));
} catch (Exception ex) {
log.error("Error calling delegations passticket api", ex);
throw ex;
}
}

@Data
public static class PassTicketRequest {
private String emailId;
private String applId;
}

@Data
@Builder
public static class PassTicketResponse {
private String passticket;
private String tsoUserid;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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.zaas.controllers;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.*;
import org.springframework.http.ResponseEntity;
import org.zowe.apiml.passticket.PassTicketService;
import org.zowe.apiml.zaas.security.mapping.NativeMapperWrapper;
import org.zowe.commons.usermap.MapperResponse;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class StsControllerTest {

@Mock
private PassTicketService passTicketService;

@Mock
private NativeMapperWrapper nativeMapper;

@InjectMocks
private StsController stsController;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
stsController.registry = "testRegistry";
}

@Test
void testGetPassTicket_Success() throws Exception {
StsController.PassTicketRequest request = new StsController.PassTicketRequest();
request.setApplId("TESTAPP");
request.setEmailId("[email protected]");

MapperResponse mapperResponse = new MapperResponse("ZOSUSER", 0, 0, 0, 0);

when(nativeMapper.getUserIDForDN("[email protected]", "testRegistry")).thenReturn(mapperResponse);
when(passTicketService.generate("ZOSUSER", "TESTAPP")).thenReturn("TICKET123");

ResponseEntity<StsController.PassTicketResponse> response = stsController.getPassTicket(request);
assertEquals(200, response.getStatusCode().value());
assertNotNull(response.getBody());
assertEquals("TICKET123", response.getBody().getPassticket());
assertEquals("ZOSUSER", response.getBody().getTsoUserid());

verify(nativeMapper).getUserIDForDN("[email protected]", "testRegistry");
verify(passTicketService).generate("ZOSUSER", "TESTAPP");
}

@Test
void testGetPassTicket_BadRequest_BlankEmail() throws Exception {
StsController.PassTicketRequest request = new StsController.PassTicketRequest();
request.setApplId("APPID");
request.setEmailId("");

ResponseEntity<StsController.PassTicketResponse> response = stsController.getPassTicket(request);

assertEquals(400, response.getStatusCode().value());
verifyNoInteractions(passTicketService, nativeMapper);
}

@Test
void testGetPassTicket_BadRequest_BlankApplId() throws Exception {
StsController.PassTicketRequest request = new StsController.PassTicketRequest();
request.setEmailId("[email protected]");
request.setApplId("");

ResponseEntity<StsController.PassTicketResponse> response = stsController.getPassTicket(request);

assertEquals(400, response.getStatusCode().value());
verifyNoInteractions(passTicketService, nativeMapper);
}

@Test
void testGetPassTicket_NativeMapperFailure() throws Exception {
StsController.PassTicketRequest request = new StsController.PassTicketRequest();
request.setApplId("APPID");
request.setEmailId("[email protected]");

when(nativeMapper.getUserIDForDN(anyString(), anyString())).thenThrow(new RuntimeException("Mapper failed"));

Exception exception = assertThrows(RuntimeException.class, () -> stsController.getPassTicket(request));
assertEquals("Mapper failed", exception.getMessage());
}

@Test
void testGetPassTicket_MapperReturnsNoUser() throws Exception {
StsController.PassTicketRequest request = new StsController.PassTicketRequest();
request.setApplId("APPID");
request.setEmailId("[email protected]");

MapperResponse mapperResponse = new MapperResponse("", 0, 0, 0, 0);

when(nativeMapper.getUserIDForDN(anyString(), anyString())).thenReturn(mapperResponse);
when(passTicketService.generate("", "APPID")).thenReturn("TICKET123");

ResponseEntity<StsController.PassTicketResponse> response = stsController.getPassTicket(request);

assertEquals(200, response.getStatusCode().value());
assertEquals("TICKET123", response.getBody().getPassticket());
assertEquals("", response.getBody().getTsoUserid());
}
}