Search in sources :

Example 1 with MetadataConverter

use of org.wso2.carbon.idp.mgt.util.MetadataConverter in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getResidentIDPMetadata.

public String getResidentIDPMetadata(String tenantDomain) throws IdentityProviderManagementException {
    if (IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().isEmpty()) {
        throw new IdentityProviderManagementException("Error receiving Metadata object for tenant: " + tenantDomain);
    }
    IdentityProvider residentIdentityProvider = this.getResidentIdP(tenantDomain);
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = residentIdentityProvider.getFederatedAuthenticatorConfigs();
    FederatedAuthenticatorConfig samlFederatedAuthenticatorConfig = null;
    for (int i = 0; i < federatedAuthenticatorConfigs.length; i++) {
        if (federatedAuthenticatorConfigs[i].getName().equals(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME)) {
            samlFederatedAuthenticatorConfig = federatedAuthenticatorConfigs[i];
            break;
        }
    }
    if (samlFederatedAuthenticatorConfig != null) {
        try {
            for (int t = 0; t < IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().size(); t++) {
                MetadataConverter converter = IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().get(t);
                if (converter.canHandle(samlFederatedAuthenticatorConfig)) {
                    return converter.getMetadataString(samlFederatedAuthenticatorConfig);
                }
            }
        } catch (IdentityProviderSAMLException e) {
            throw new IdentityProviderManagementException("Error in retrieving metadata string for tenant:" + tenantDomain, e.getMessage());
        }
    }
    return null;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) MetadataConverter(org.wso2.carbon.idp.mgt.util.MetadataConverter) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 2 with MetadataConverter

use of org.wso2.carbon.idp.mgt.util.MetadataConverter in project carbon-identity-framework by wso2.

the class IdentityProviderManager method handleMetadata.

/**
 * If metadata file is available, creates a new FederatedAuthenticatorConfig from that
 *
 * @param identityProvider
 * @throws IdentityProviderManagementException
 */
private void handleMetadata(int tenantId, IdentityProvider identityProvider) throws IdentityProviderManagementException {
    if (IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().isEmpty()) {
        throw new IdentityProviderManagementException("Metadata Converter is not set");
    }
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    for (FederatedAuthenticatorConfig federatedAuthenticatorConfig : federatedAuthenticatorConfigs) {
        Property[] properties = federatedAuthenticatorConfig.getProperties();
        if (ArrayUtils.isNotEmpty(properties)) {
            for (Property property : properties) {
                if (property != null) {
                    if (StringUtils.isNotBlank(property.getName()) && property.getName().contains(IdPManagementConstants.META_DATA)) {
                        for (MetadataConverter metadataConverter : IdpMgtServiceComponentHolder.getInstance().getMetadataConverters()) {
                            if (metadataConverter.canHandle(property)) {
                                try {
                                    if (isMetadataFileExist(identityProvider.getIdentityProviderName(), property.getValue())) {
                                        try {
                                            metadataConverter.saveMetadataString(tenantId, identityProvider.getIdentityProviderName(), federatedAuthenticatorConfig.getName(), property.getValue());
                                        } catch (IdentityProviderManagementException e) {
                                            String data = "Couldn't save metadata in registry.SAML2SSOMetadataConverter" + " is not set. ";
                                            throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_ADD_IDP, data);
                                        }
                                    }
                                    StringBuilder certificate = new StringBuilder();
                                    try {
                                        FederatedAuthenticatorConfig metaFederated = metadataConverter.getFederatedAuthenticatorConfig(properties, certificate);
                                        String spName = "";
                                        for (Property value : properties) {
                                            if (value != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(value.getName())) {
                                                spName = value.getValue();
                                            }
                                        }
                                        if (spName.equals("")) {
                                            throw new IdentityProviderManagementException("SP name can't be empty");
                                        }
                                        if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
                                            for (int y = 0; y < metaFederated.getProperties().length; y++) {
                                                if (metaFederated.getProperties()[y] != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(metaFederated.getProperties()[y].getName())) {
                                                    metaFederated.getProperties()[y].setValue(spName);
                                                    break;
                                                }
                                            }
                                        }
                                        if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
                                            federatedAuthenticatorConfig.setProperties(metaFederated.getProperties());
                                        } else {
                                            throw new IdentityProviderManagementException("Error setting metadata using file");
                                        }
                                    } catch (IdentityProviderManagementException ex) {
                                        throw new IdentityProviderManagementException("Error converting metadata", ex);
                                    }
                                    if (certificate.toString().length() > 0) {
                                        identityProvider.setCertificate(certificate.toString());
                                    }
                                } catch (XMLStreamException e) {
                                    throw new IdentityProviderManagementException("Error while configuring metadata", e);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) MetadataConverter(org.wso2.carbon.idp.mgt.util.MetadataConverter) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 3 with MetadataConverter

use of org.wso2.carbon.idp.mgt.util.MetadataConverter in project carbon-identity-framework by wso2.

the class IdentityProviderManager method forceDeleteIDP.

private void forceDeleteIDP(String resourceId, String idpName, String tenantDomain) throws IdentityProviderManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    for (MetadataConverter metadataConverter : IdpMgtServiceComponentHolder.getInstance().getMetadataConverters()) {
        if (metadataConverter.canDelete(tenantId, idpName)) {
            metadataConverter.deleteMetadataString(tenantId, idpName);
        }
    }
    dao.forceDeleteIdPByResourceId(resourceId, tenantId, tenantDomain);
}
Also used : MetadataConverter(org.wso2.carbon.idp.mgt.util.MetadataConverter)

Aggregations

MetadataConverter (org.wso2.carbon.idp.mgt.util.MetadataConverter)3 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)2 XMLStreamException (javax.xml.stream.XMLStreamException)1 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)1 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)1 Property (org.wso2.carbon.identity.application.common.model.Property)1