Skip to content

Commit

Permalink
Refactor ServerIdpManagementServiceFactory class
Browse files Browse the repository at this point in the history
  • Loading branch information
NipuniBhagya committed Oct 16, 2024
1 parent 0664e9c commit 41c8354
Showing 1 changed file with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,22 @@
*/
public class ServerIdpManagementServiceFactory {

private static final ServerIdpManagementService SERVICE;
private ServerIdpManagementServiceFactory() {

static {
IdentityProviderManager identityProviderManager = IdentityProviderServiceHolder.getIdentityProviderManager();
ClaimMetadataManagementService claimMetadataManagementService = IdentityProviderServiceHolder
.getClaimMetadataManagementService();
TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
}

if (identityProviderManager == null) {
throw new IllegalStateException("IdentityProviderManager is not available from OSGi context.");
}
private static class ServerIdpManagementServiceHolder {

if (claimMetadataManagementService == null) {
throw new IllegalStateException("ClaimMetadataManagementService is not available from OSGi context.");
}
private static final ServerIdpManagementService SERVICE = createServiceInstance();
}

if (templateManager == null) {
throw new IllegalStateException("TemplateManager is not available from OSGi context.");
}
private static ServerIdpManagementService createServiceInstance() {

IdentityProviderManager identityProviderManager = getIdentityProviderManager();
ClaimMetadataManagementService claimMetadataManagementService = getClaimMetadataManagementService();
TemplateManager templateManager = getTemplateManager();

SERVICE = new ServerIdpManagementService(identityProviderManager, templateManager,
claimMetadataManagementService);
return new ServerIdpManagementService(identityProviderManager, templateManager, claimMetadataManagementService);
}

/**
Expand All @@ -60,6 +54,36 @@ public class ServerIdpManagementServiceFactory {
*/
public static ServerIdpManagementService getServerIdpManagementService() {

return SERVICE;
return ServerIdpManagementServiceHolder.SERVICE;
}

private static IdentityProviderManager getIdentityProviderManager() {

IdentityProviderManager service = IdentityProviderServiceHolder.getIdentityProviderManager();
if (service == null) {
throw new IllegalStateException("IdentityProviderManager is not available from OSGi context.");
}

return service;
}

private static ClaimMetadataManagementService getClaimMetadataManagementService() {

ClaimMetadataManagementService service = IdentityProviderServiceHolder.getClaimMetadataManagementService();
if (service == null) {
throw new IllegalStateException("ClaimMetadataManagementService is not available from OSGi context.");
}

return service;
}

private static TemplateManager getTemplateManager() {

TemplateManager service = IdentityProviderServiceHolder.getTemplateManager();
if (service == null) {
throw new IllegalStateException("TemplateManager is not available from OSGi context.");
}

return service;
}
}

0 comments on commit 41c8354

Please sign in to comment.