Search in sources :

Example 76 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImplTest method testCreateApplication.

@Test(dataProvider = "addApplicationDataProvider")
public void testCreateApplication(Object serviceProvider, String tenantDomain, String username) throws IdentityApplicationManagementException {
    // Adding application.
    addApplicationConfigurations((ServiceProvider) serviceProvider);
    String resourceId = applicationManagementService.createApplication((ServiceProvider) serviceProvider, tenantDomain, username);
    // Retrieving application by ResourceId
    ServiceProvider expectedSP = applicationManagementService.getApplicationByResourceId(resourceId, tenantDomain);
    Assert.assertEquals(resourceId, expectedSP.getApplicationResourceId());
    ApplicationBasicInfo applicationBasicInfo = applicationManagementService.getApplicationBasicInfoByResourceId(resourceId, tenantDomain);
    Assert.assertEquals(applicationBasicInfo.getApplicationName(), ((ServiceProvider) serviceProvider).getApplicationName());
    // Deleting added application
    applicationManagementService.deleteApplicationByResourceId(resourceId, tenantDomain, username);
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo) Test(org.testng.annotations.Test)

Example 77 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationMgtUtilTest method testIsValidApplicationOwner.

@Test(dataProvider = "validApplicationOwnerDataProvider")
public void testIsValidApplicationOwner(String username, String tenantDomain, Boolean hasOwner, Boolean expected) throws IdentityApplicationManagementException, UserStoreException {
    ServiceProvider serviceProvider = new ServiceProvider();
    if (hasOwner) {
        User user = new User();
        user.setUserName(username);
        user.setTenantDomain(tenantDomain);
        serviceProvider.setOwner(user);
    }
    mockUserStoreManager();
    when(mockUserStoreManager.isExistingUser(anyString())).thenReturn(FALSE);
    when(mockUserRealm.getRealmConfiguration()).thenReturn(mockRealmConfiguration);
    when(mockRealmConfiguration.getAdminUserName()).thenReturn("admin");
    when(mockRealmConfiguration.getUserStoreProperty(anyString())).thenReturn("property");
    when(mockCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
    assertEquals(ApplicationMgtUtil.isValidApplicationOwner(serviceProvider), expected);
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 78 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class FileBasedApplicationDAO method getServiceProviderToLocalIdPClaimMapping.

@Override
public Map<String, String> getServiceProviderToLocalIdPClaimMapping(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();
    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }
    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();
    if (claimMappings != null && claimMappings.length > 0) {
        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null && mapping.getLocalClaim().getClaimUri() != null && mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getRemoteClaim().getClaimUri(), mapping.getLocalClaim().getClaimUri());
            }
        }
    }
    return claimMap;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 79 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationIdentityProviderMgtListener method doPostUpdateIdP.

@Override
public boolean doPostUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    try {
        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        ConnectedAppsResult connectedApplications;
        String updatedIdpId = identityProvider.getResourceId();
        ApplicationDAO applicationDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        int offset = 0;
        do {
            connectedApplications = identityProviderManager.getConnectedApplications(updatedIdpId, null, offset, tenantDomain);
            for (String appResourceId : connectedApplications.getApps()) {
                ServiceProvider serviceProvider = applicationDAO.getApplicationByResourceId(appResourceId, tenantDomain);
                applicationDAO.clearApplicationFromCache(serviceProvider, tenantDomain);
            }
            offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
        } while (connectedApplications.getTotalAppCount() > offset);
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProviderManagementException("Error while running post IDP update tasks.", e);
    }
    return true;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) CacheBackedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 80 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationIdentityProviderMgtListener method updateApplicationWithFederatedAuthenticator.

/**
 * Update the service providers, with the default authenticator of the identity provider.
 *
 * @param identityProvider
 * @param tenantDomain
 * @param serviceProvider
 * @param authStep
 * @throws IdentityApplicationManagementException
 * @throws IdentityProviderManagementException
 */
private void updateApplicationWithFederatedAuthenticator(IdentityProvider identityProvider, String tenantDomain, ServiceProvider serviceProvider, AuthenticationStep authStep) throws IdentityApplicationManagementException, IdentityProviderManagementException {
    IdentityProvider fedIdp = authStep.getFederatedIdentityProviders()[0];
    if (StringUtils.equals(fedIdp.getIdentityProviderName(), identityProvider.getIdentityProviderName())) {
        String defaultAuthName = fedIdp.getDefaultAuthenticatorConfig().getName();
        if (identityProvider.getDefaultAuthenticatorConfig() != null) {
            String currentDefaultAuthName = identityProvider.getDefaultAuthenticatorConfig().getName();
            boolean isCurrentDefaultAuthEnabled = identityProvider.getDefaultAuthenticatorConfig().isEnabled();
            if (!StringUtils.equals(currentDefaultAuthName, defaultAuthName)) {
                FederatedAuthenticatorConfig currentDefaultAuthenticatorConfig = identityProvider.getDefaultAuthenticatorConfig();
                fedIdp.setDefaultAuthenticatorConfig(currentDefaultAuthenticatorConfig);
                fedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { currentDefaultAuthenticatorConfig });
                ApplicationMgtSystemConfig.getInstance().getApplicationDAO().updateApplication(serviceProvider, tenantDomain);
            } else if (!isCurrentDefaultAuthEnabled && StringUtils.equals(currentDefaultAuthName, defaultAuthName)) {
                throw new IdentityProviderManagementException("Error in disabling default federated authenticator" + " as it is referred by service providers.");
            }
        }
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19