Skip to content

Commit

Permalink
Set org name as TOTP issuer display name for sub orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
dewniMW committed Nov 28, 2023
1 parent 76db932 commit 008de14
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions component/authenticator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
org.wso2.carbon.identity.handler.event.account.lock.exception;
version="${carbon.identity.account.lock.handler.imp.pkg.version.range}",
org.owasp.encoder; version="${encoder.wso2.import.version.range}",
org.wso2.carbon.identity.organization.management.service;version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.organization.management.service.exception;version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.organization.management.service.util;version="${org.wso2.carbon.identity.organization.management.core.version.range}",
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Export-Package>!org.wso2.carbon.identity.application.authenticator.totp.internal.*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.wso2.carbon.identity.event.services.IdentityEventService;
import org.wso2.carbon.identity.governance.IdentityGovernanceService;
import org.wso2.carbon.identity.handler.event.account.lock.service.AccountLockService;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.idp.mgt.IdpManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;
Expand Down Expand Up @@ -224,4 +225,19 @@ protected void unsetClaimMetadataManagementService(ClaimMetadataManagementServic
}
TOTPDataHolder.setClaimManagementService(null);
}

@Reference(name = "identity.organization.management.component",
service = OrganizationManager.class,
cardinality = ReferenceCardinality.OPTIONAL,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetOrganizationManager")
protected void setOrganizationManager(OrganizationManager organizationManager) {

TOTPDataHolder.getInstance().setOrganizationManager(organizationManager);
}

protected void unsetOrganizationManager(OrganizationManager organizationManager) {

TOTPDataHolder.getInstance().setOrganizationManager(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.wso2.carbon.identity.event.services.IdentityEventService;
import org.wso2.carbon.identity.governance.IdentityGovernanceService;
import org.wso2.carbon.identity.handler.event.account.lock.service.AccountLockService;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.idp.mgt.IdpManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;
Expand All @@ -39,6 +40,7 @@ public class TOTPDataHolder {
private AccountLockService accountLockService;
private IdentityGovernanceService identityGovernanceService;
private IdpManager idpManager;
private OrganizationManager organizationManager;

private static ClaimMetadataManagementService claimManagementService;

Expand Down Expand Up @@ -182,4 +184,24 @@ public static void setClaimManagementService(ClaimMetadataManagementService clai

TOTPDataHolder.claimManagementService = claimManagementService;
}

/**
* Set {@link OrganizationManager}.
*
* @param organizationManager Instance of {@link OrganizationManager}.
*/
public void setOrganizationManager(OrganizationManager organizationManager) {

this.organizationManager = organizationManager;
}

/**
* Get {@link OrganizationManager}.
*
* @return Instance of {@link OrganizationManager}
*/
public OrganizationManager getOrganizationManager() {

return organizationManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.governance.IdentityGovernanceException;
import org.wso2.carbon.identity.handler.event.account.lock.exception.AccountLockServiceException;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
Expand Down Expand Up @@ -90,11 +93,11 @@

import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.ENABLE_TOTP_REQUEST_PAGE;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.ENROL_USER_IN_AUTHENTICATIONFLOW;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.ERROR_PAGE;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.SUPER_TENANT_DOMAIN;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.TOTP_HIDE_USERSTORE_FROM_USERNAME;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.TOTP_LOGIN_PAGE;
import static org.wso2.carbon.identity.application.authenticator.totp.TOTPAuthenticatorConstants.ENROL_USER_IN_AUTHENTICATIONFLOW;

/**
* TOTP Util class.
Expand Down Expand Up @@ -156,7 +159,18 @@ public static String getTOTPIssuerDisplayName(String tenantDomain, Authenticatio
issuer = (String) context.getProperty(TOTPAuthenticatorConstants.TOTP_ISSUER);
}
if (StringUtils.isBlank(issuer)) {
issuer = tenantDomain;
try {
// For sub organizations, issuer display name should be the organization name.
if (OrganizationManagementUtil.isOrganization(tenantDomain)) {
OrganizationManager organizationManager = TOTPDataHolder.getInstance().getOrganizationManager();
String organizationId = organizationManager.resolveOrganizationId(tenantDomain);
issuer = organizationManager.getOrganizationNameById(organizationId);
} else {
issuer = tenantDomain;
}
} catch (OrganizationManagementException e) {
throw new TOTPException("Error while resolving organization for tenant domain: " + tenantDomain, e);
}
}
return issuer;
}
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<version>${org.wso2.carbon.identity.organization.management.core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.extension.identity.authenticator.utils</groupId>
Expand Down Expand Up @@ -160,8 +159,10 @@
<!--Carbon identity version-->
<carbon.identity.framework.version>5.25.522</carbon.identity.framework.version>

<org.wso2.carbon.identity.organization.management.core.version>1.0.0
<org.wso2.carbon.identity.organization.management.core.version>1.0.92
</org.wso2.carbon.identity.organization.management.core.version>
<org.wso2.carbon.identity.organization.management.core.version.range>[1.0.0, 2.0.0)
</org.wso2.carbon.identity.organization.management.core.version.range>

<carbon.identity.version>5.0.8</carbon.identity.version>
<carbon.identity.package.export.version>${carbon.identity.version}</carbon.identity.package.export.version>
Expand Down

0 comments on commit 008de14

Please sign in to comment.