Skip to content

Commit

Permalink
Re-purpose Organization in pre-issue access token Request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Mar 10, 2025
1 parent 07d921a commit 70ff59d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.wso2.carbon.identity.action.execution.api.model.Event;
import org.wso2.carbon.identity.action.execution.api.model.FlowContext;
import org.wso2.carbon.identity.action.execution.api.model.Operation;
import org.wso2.carbon.identity.action.execution.api.model.Organization;
import org.wso2.carbon.identity.action.execution.api.model.Request;
import org.wso2.carbon.identity.action.execution.api.model.Tenant;
import org.wso2.carbon.identity.action.execution.api.model.User;
Expand All @@ -56,7 +55,7 @@
import org.wso2.carbon.identity.openidconnect.CustomClaimsCallbackHandler;
import org.wso2.carbon.identity.openidconnect.OIDCClaimUtil;
import org.wso2.carbon.identity.openidconnect.util.ClaimHandlerUtil;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -74,6 +73,8 @@ public class PreIssueAccessTokenRequestBuilder implements ActionExecutionRequest
public static final String CLAIMS_PATH_PREFIX = "/accessToken/claims/";
public static final String SCOPES_PATH_PREFIX = "/accessToken/scopes/";
private static final Log LOG = LogFactory.getLog(PreIssueAccessTokenRequestBuilder.class);
private static final OrganizationManager organizationManager = OAuthComponentServiceHolder.getInstance()
.getOrganizationManager();

@Override
public ActionType getSupportedActionType() {
Expand Down Expand Up @@ -112,8 +113,6 @@ private Event getEvent(OAuthTokenReqMessageContext tokenMessageContext, Map<Stri
boolean isAuthorizedForUser = isAccessTokenAuthorizedForUser(tokenReqDTO.getGrantType(), tokenMessageContext);
if (isAuthorizedForUser) {
setUserForEventBuilder(eventBuilder, authorizedUser, tokenReqDTO.getClientId(), tokenReqDTO.getGrantType());
setOrganizationForEventBuilder(eventBuilder, authorizedUser, tokenReqDTO.getClientId(),
tokenReqDTO.getGrantType());
eventBuilder.userStore(new UserStore(authorizedUser.getUserStoreDomain()));
}

Expand All @@ -139,26 +138,6 @@ private void setUserForEventBuilder(PreIssueAccessTokenEvent.Builder eventBuilde
}
}

private void setOrganizationForEventBuilder(PreIssueAccessTokenEvent.Builder eventBuilder, AuthenticatedUser user,
String clientID, String grantType) {

try {
String organizationId = user.getUserResidentOrganization();
if (organizationId != null && !organizationId.isEmpty()) {
String organizationName = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
.getOrganizationNameById(user.getUserResidentOrganization());
eventBuilder.organization(new Organization(user.getUserResidentOrganization(),
organizationName));
}
} catch (OrganizationManagementException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(
"Error occurred while retrieving organization name of the authorized user for application: " +
clientID + "for grantType: " + grantType), e);
}
}
}

private Request getRequest(OAuth2AccessTokenReqDTO tokenRequestDTO) {

TokenRequest.Builder tokenRequestBuilder = new TokenRequest.Builder();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@
<carbon.identity.organization.management.version.range>[1.1.14, 2.0.0)
</carbon.identity.organization.management.version.range>

<carbon.identity.organization.management.core.version>1.1.20
<carbon.identity.organization.management.core.version>1.1.24
</carbon.identity.organization.management.core.version>
<carbon.identity.organization.management.core.version.range>[1.0.0, 2.0.0)
</carbon.identity.organization.management.core.version.range>
Expand Down

0 comments on commit 70ff59d

Please sign in to comment.