99
99
import org .wso2 .carbon .utils .CarbonUtils ;
100
100
import org .wso2 .carbon .utils .DiagnosticLog ;
101
101
102
- import java .time .Instant ;
103
- import java .time .format .DateTimeFormatter ;
104
102
import java .util .ArrayList ;
105
103
import java .util .Arrays ;
106
104
import java .util .Collections ;
@@ -1428,17 +1426,21 @@ private static void triggerPostIssueTokenEvent(OAuth2AccessTokenReqDTO tokenReqD
1428
1426
}
1429
1427
return ;
1430
1428
}
1429
+ if (existingTokenUsed (tokReqMsgCtx )) {
1430
+ if (log .isDebugEnabled ()) {
1431
+ log .debug ("Existing token is used. Hence skipping the post issue token event." );
1432
+ }
1433
+ return ;
1434
+ }
1431
1435
String userType = StringUtils .EMPTY ;
1432
1436
String organizationId = StringUtils .EMPTY ;
1433
1437
String tenantDomain = StringUtils .EMPTY ;
1434
1438
String clientId = StringUtils .EMPTY ;
1435
1439
String accessingOrganizationId = StringUtils .EMPTY ;
1436
1440
String tokenId = StringUtils .EMPTY ;
1437
1441
String grantType = StringUtils .EMPTY ;
1438
- String issuedTime ;
1442
+ String issuedTime = String . valueOf ( tokReqMsgCtx . getAccessTokenIssuedTime ()) ;
1439
1443
1440
- issuedTime = DateTimeFormatter .ISO_INSTANT .format (
1441
- Instant .ofEpochMilli (tokReqMsgCtx .getAccessTokenIssuedTime ()));
1442
1444
Object userTypeObject = tokReqMsgCtx .getProperty (OAuthConstants .UserType .USER_TYPE );
1443
1445
if (userTypeObject instanceof String ) {
1444
1446
userType = (String ) userTypeObject ;
@@ -1463,18 +1465,17 @@ private static void triggerPostIssueTokenEvent(OAuth2AccessTokenReqDTO tokenReqD
1463
1465
if (tokenReqDTO .getGrantType () != null ) {
1464
1466
grantType = tokenReqDTO .getGrantType ();
1465
1467
}
1466
- if (!existingTokenUsed (tokReqMsgCtx )) {
1467
- Map <String , Object > eventProperties = new HashMap <>();
1468
- eventProperties .put (OIDCConstants .Event .TOKEN_ID , tokenId );
1469
- eventProperties .put (OIDCConstants .Event .TENANT_DOMAIN , tenantDomain );
1470
- eventProperties .put (OIDCConstants .Event .USER_TYPE , userType );
1471
- eventProperties .put (OIDCConstants .Event .CLIENT_ID , clientId );
1472
- eventProperties .put (OIDCConstants .Event .GRANT_TYPE , grantType );
1473
- eventProperties .put (OIDCConstants .Event .ISSUED_TIME , issuedTime );
1474
- eventProperties .put (OIDCConstants .Event .ISSUER_ORGANIZATION_ID , organizationId );
1475
- eventProperties .put (OIDCConstants .Event .ACCESSING_ORGANIZATION_ID , accessingOrganizationId );
1476
- OAuth2TokenUtil .postIssueToken (eventProperties );
1477
- }
1468
+
1469
+ Map <String , Object > eventProperties = new HashMap <>();
1470
+ eventProperties .put (OIDCConstants .Event .TOKEN_ID , tokenId );
1471
+ eventProperties .put (OIDCConstants .Event .TENANT_DOMAIN , tenantDomain );
1472
+ eventProperties .put (OIDCConstants .Event .USER_TYPE , userType );
1473
+ eventProperties .put (OIDCConstants .Event .CLIENT_ID , clientId );
1474
+ eventProperties .put (OIDCConstants .Event .GRANT_TYPE , grantType );
1475
+ eventProperties .put (OIDCConstants .Event .ISSUED_TIME , issuedTime );
1476
+ eventProperties .put (OIDCConstants .Event .ISSUER_ORGANIZATION_ID , organizationId );
1477
+ eventProperties .put (OIDCConstants .Event .ACCESSING_ORGANIZATION_ID , accessingOrganizationId );
1478
+ OAuth2TokenUtil .postIssueToken (eventProperties );
1478
1479
}
1479
1480
1480
1481
private static Boolean existingTokenUsed (OAuthTokenReqMessageContext tokReqMsgCtx ) {
0 commit comments