Search in sources :

Example 46 with ServiceProvider

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

the class CacheBackedApplicationDAO method updateApplication.

public void updateApplication(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider storedApp = getApplication(serviceProvider.getApplicationID());
    clearAllAppCache(storedApp, tenantDomain);
    appDAO.updateApplication(serviceProvider, tenantDomain);
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 47 with ServiceProvider

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

the class CacheBackedApplicationDAO method getApplicationFromCache.

private ServiceProvider getApplicationFromCache(int appId, String tenantDomain) {
    ServiceProvider serviceProvider = null;
    ServiceProviderIDCacheKey cacheKey = new ServiceProviderIDCacheKey(appId);
    ServiceProviderIDCacheEntry entry = appCacheByID.getValueFromCache(cacheKey, tenantDomain);
    if (entry != null) {
        serviceProvider = entry.getServiceProvider();
    }
    if (serviceProvider == null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache missing for the application with id " + appId);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache present for the application with id " + appId);
        }
    }
    return serviceProvider;
}
Also used : ServiceProviderIDCacheKey(org.wso2.carbon.identity.application.mgt.internal.cache.ServiceProviderIDCacheKey) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ServiceProviderIDCacheEntry(org.wso2.carbon.identity.application.mgt.internal.cache.ServiceProviderIDCacheEntry)

Example 48 with ServiceProvider

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

the class FileBasedApplicationDAO method getAllRequestedClaimsByServiceProvider.

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

Example 49 with ServiceProvider

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

the class ApplicationManagementServiceImpl method getServiceProviderNameByClientId.

/**
 * @param clientId
 * @param clientType
 * @param tenantDomain
 * @return
 * @throws IdentityApplicationManagementException
 */
@Override
public String getServiceProviderNameByClientId(String clientId, String clientType, String tenantDomain) throws IdentityApplicationManagementException {
    String name = null;
    // invoking the listeners
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreGetServiceProviderNameByClientId(clientId, clientType, tenantDomain)) {
            return null;
        }
    }
    if (StringUtils.isNotEmpty(clientId)) {
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        name = appDAO.getServiceProviderNameByClientId(clientId, clientType, tenantDomain);
        if (name == null) {
            name = new FileBasedApplicationDAO().getServiceProviderNameByClientId(clientId, clientType, tenantDomain);
        }
    }
    if (name == null) {
        ServiceProvider defaultSP = ApplicationManagementServiceComponent.getFileBasedSPs().get(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
        name = defaultSP.getApplicationName();
    }
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostGetServiceProviderNameByClientId(name, clientId, clientType, tenantDomain)) {
            return null;
        }
    }
    return name;
}
Also used : FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 50 with ServiceProvider

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

the class ApplicationManagementServiceImpl method marshalSP.

/**
 * Convert service provider object of service provider to xml formatted string
 *
 * @param serviceProvider service provider to be marshaled
 * @param tenantDomain    tenant domain
 * @return xml formatted string of the service provider
 * @throws IdentityApplicationManagementException Identity Application Management Exception
 */
private String marshalSP(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ServiceProvider.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        DocumentBuilderFactory docBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
        Document document = docBuilderFactory.newDocumentBuilder().newDocument();
        marshaller.marshal(serviceProvider, document);
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "AuthenticationScript inboundConfiguration");
        StringWriter stringBuilder = new StringWriter();
        StreamResult result = new StreamResult(stringBuilder);
        transformer.transform(new DOMSource(document), result);
        return stringBuilder.getBuffer().toString();
    } catch (JAXBException | ParserConfigurationException | TransformerException e) {
        throw new IdentityApplicationManagementException(String.format("Error in exporting Service Provider %s@%s", serviceProvider.getApplicationName(), tenantDomain), e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) JAXBException(javax.xml.bind.JAXBException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) StringWriter(java.io.StringWriter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

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