Search in sources :

Example 1 with SamlConfigEntity

use of org.openkilda.saml.dao.entity.SamlConfigEntity in project open-kilda by telstra.

the class SamlValidator method validateUpdateProvider.

/**
 * Validate update provider.
 *
 * @param uuid the uuid
 * @param file the metadata file
 * @param name the provider name
 * @param entityId the entityId
 * @param url the metadata url
 * @param userCreation the userCreation
 * @param roleIds the role ids
 * @return the saml config entity
 */
public SamlConfigEntity validateUpdateProvider(String uuid, MultipartFile file, String name, String entityId, String url, boolean userCreation, List<Long> roleIds) {
    SamlConfigEntity samlConfigEntity = getEntityByUuid(uuid);
    SamlConfigEntity configEntity = samlRepository.findByUuidNotAndEntityIdOrUuidNotAndNameEqualsIgnoreCase(uuid, entityId, uuid, name);
    if (configEntity != null) {
        throw new RequestValidationException(messageUtil.getAttributeUnique("Provider name or Entity Id"));
    }
    if (file != null) {
        if (!FilenameUtils.getExtension(file.getOriginalFilename()).equals("xml")) {
            throw new RequestValidationException(messageUtil.getAttributeMetadataInvalid("file"));
        }
    }
    if (file == null && url == null) {
        if (!samlConfigEntity.getEntityId().equals(entityId)) {
            throw new RequestValidationException(messageUtil.getAttributeInvalid("Entity Id", entityId));
        }
    } else {
        String metadataEntityId = validateEntityId(file, url);
        if (!metadataEntityId.equals(entityId)) {
            throw new RequestValidationException("Entity Id must be same as Metadata Entity Id");
        }
    }
    if (userCreation) {
        if (roleIds.isEmpty() || roleIds == null) {
            throw new RequestValidationException(messageUtil.getAttributeNotNull("role"));
        }
    }
    return samlConfigEntity;
}
Also used : SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 2 with SamlConfigEntity

use of org.openkilda.saml.dao.entity.SamlConfigEntity in project open-kilda by telstra.

the class SamlValidator method validateCreateProvider.

/**
 * Validate create provider.
 *
 * @param file the metadata file
 * @param name the provider name
 * @param entityId the entityId
 * @param url the metadata url
 * @param userCreation the userCreation
 * @param roleIds the role ids
 */
public void validateCreateProvider(MultipartFile file, String name, String entityId, String url, boolean userCreation, List<Long> roleIds) {
    SamlConfigEntity samlConfigEntity = samlRepository.findByEntityIdOrNameEqualsIgnoreCase(entityId, name);
    if (samlConfigEntity != null) {
        throw new RequestValidationException(messageUtil.getAttributeUnique("Provider name or Entity Id"));
    }
    if (file == null && url == null) {
        throw new RequestValidationException(messageUtil.getAttributeNotNull("Metadata file or url"));
    }
    if (file != null) {
        if (!FilenameUtils.getExtension(file.getOriginalFilename()).equals("xml")) {
            throw new RequestValidationException(messageUtil.getAttributeMetadataInvalid("file"));
        }
    }
    String metadataEntityId = validateEntityId(file, url);
    if (!metadataEntityId.equals(entityId)) {
        throw new RequestValidationException("Entity Id must be same as Metadata Entity Id");
    }
    if (userCreation) {
        if (roleIds.isEmpty() || roleIds == null) {
            throw new RequestValidationException(messageUtil.getAttributeNotNull("role"));
        }
    }
}
Also used : SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 3 with SamlConfigEntity

use of org.openkilda.saml.dao.entity.SamlConfigEntity in project open-kilda by telstra.

the class SecurityConfig method metadata.

@Bean
@Qualifier("metadata")
public CachingMetadataManager metadata(ExtendedMetadataDelegate extendedMetadataDelegate) throws MetadataProviderException, IOException {
    List<MetadataProvider> metadataProviderList = new ArrayList<>();
    List<SamlConfigEntity> samlConfigEntityList = samlRepository.findAll();
    if (samlConfigEntityList != null) {
        for (final SamlConfigEntity samlConfigEntity : samlConfigEntityList) {
            if (samlConfigEntity.getUrl() != null) {
                UrlMetadataProvider urlMetadataProvider = new UrlMetadataProvider(new Timer(true), new HttpClient(), samlConfigEntity.getUuid());
                urlMetadataProvider.setParserPool(ParserPoolHolder.getPool());
                ExtendedMetadataDelegate metadataDelegate = new ExtendedMetadataDelegate(urlMetadataProvider, extendedMetadata());
                metadataDelegate.setMetadataTrustCheck(false);
                metadataDelegate.setMetadataRequireSignature(false);
                metadataProviderList.add(metadataDelegate);
            } else {
                DbMetadataProvider metadataProvider = new DbMetadataProvider(new Timer(true), samlConfigEntity.getUuid());
                metadataProvider.setParserPool(ParserPoolHolder.getPool());
                ExtendedMetadataDelegate metadataDelegate = new ExtendedMetadataDelegate(metadataProvider, extendedMetadata());
                metadataDelegate.setMetadataTrustCheck(false);
                metadataDelegate.setMetadataRequireSignature(false);
                metadataProviderList.add(metadataDelegate);
            }
        }
    }
    return new CachingMetadataManager(metadataProviderList);
}
Also used : DbMetadataProvider(org.openkilda.saml.provider.DbMetadataProvider) Timer(java.util.Timer) UrlMetadataProvider(org.openkilda.saml.provider.UrlMetadataProvider) DbMetadataProvider(org.openkilda.saml.provider.DbMetadataProvider) MetadataProvider(org.opensaml.saml2.metadata.provider.MetadataProvider) UrlMetadataProvider(org.openkilda.saml.provider.UrlMetadataProvider) HttpClient(org.apache.commons.httpclient.HttpClient) ArrayList(java.util.ArrayList) ExtendedMetadataDelegate(org.springframework.security.saml.metadata.ExtendedMetadataDelegate) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) CachingMetadataManager(org.springframework.security.saml.metadata.CachingMetadataManager) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Example 4 with SamlConfigEntity

use of org.openkilda.saml.dao.entity.SamlConfigEntity in project open-kilda by telstra.

the class SamlService method create.

/**
 * Creates the provider.
 *
 * @param file the metadata file
 * @param url the metadata url
 * @param name the provider name
 * @param entityId the entityId
 * @param status the provider status
 * @param attribute the attribute
 * @param userCreation the userCreation
 * @param roleIds the role Ids
 * @return the SamlConfig
 */
public SamlConfig create(MultipartFile file, String name, String url, String entityId, boolean status, boolean userCreation, List<Long> roleIds, String attribute) {
    samlValidator.validateCreateProvider(file, name, entityId, url, userCreation, roleIds);
    Set<RoleEntity> roleEntities = roleService.getRolesById(roleIds);
    SamlConfigEntity samlConfigEntity = SamlConversionUtil.toSamlConfigEntity(file, name, url, entityId, status, attribute, userCreation, roleEntities);
    samlRepository.save(samlConfigEntity);
    try {
        metadataManager.loadProviderMetadata(samlConfigEntity.getUuid(), samlConfigEntity.getType().name());
    } catch (MetadataProviderException e) {
        LOGGER.error("Error occurred while loading provider" + e);
    }
    return SamlConversionUtil.toSamlConfig(samlConfigEntity);
}
Also used : RoleEntity(org.usermanagement.dao.entity.RoleEntity) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException)

Example 5 with SamlConfigEntity

use of org.openkilda.saml.dao.entity.SamlConfigEntity in project open-kilda by telstra.

the class SamlService method getAll.

/**
 * Gets all the providers.
 *
 * @return the providers
 */
public List<SamlConfig> getAll() {
    List<SamlConfigEntity> samlConfigEntityList = samlRepository.findAll();
    List<SamlConfig> samlConfigList = new ArrayList<>();
    for (SamlConfigEntity samlConfigEntity : samlConfigEntityList) {
        SamlConfig samlConfig = SamlConversionUtil.toSamlConfig(samlConfigEntity);
        samlConfigList.add(samlConfig);
    }
    return samlConfigList;
}
Also used : ArrayList(java.util.ArrayList) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) SamlConfig(org.openkilda.saml.model.SamlConfig)

Aggregations

SamlConfigEntity (org.openkilda.saml.dao.entity.SamlConfigEntity)10 ArrayList (java.util.ArrayList)3 SamlConfig (org.openkilda.saml.model.SamlConfig)3 Blob (java.sql.Blob)2 MetadataProviderException (org.opensaml.saml2.metadata.provider.MetadataProviderException)2 RoleEntity (org.usermanagement.dao.entity.RoleEntity)2 RequestValidationException (org.usermanagement.exception.RequestValidationException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Timer (java.util.Timer)1 SerialBlob (javax.sql.rowset.serial.SerialBlob)1 SerialException (javax.sql.rowset.serial.SerialException)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 DbMetadataProvider (org.openkilda.saml.provider.DbMetadataProvider)1 UrlMetadataProvider (org.openkilda.saml.provider.UrlMetadataProvider)1 MetadataProvider (org.opensaml.saml2.metadata.provider.MetadataProvider)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Bean (org.springframework.context.annotation.Bean)1 CachingMetadataManager (org.springframework.security.saml.metadata.CachingMetadataManager)1