Search in sources :

Example 6 with SamlConfigEntity

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

the class SamlService method update.

/**
 * Updates the provider.
 *
 * @param uuid the uuid
 * @param file the metadata file
 * @param name the provider name
 * @param url the metadata url
 * @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 update(String uuid, MultipartFile file, String name, String url, String entityId, boolean status, String attribute, boolean userCreation, List<Long> roleIds) {
    SamlConfigEntity samlConfigEntity = samlValidator.validateUpdateProvider(uuid, file, name, entityId, url, userCreation, roleIds);
    Set<RoleEntity> roleEntities = roleService.getRolesById(roleIds);
    boolean requireManagerUpdate = SamlConversionUtil.toUpdateSamlConfigEntity(samlConfigEntity, roleEntities, file, name, url, entityId, status, userCreation, attribute);
    samlRepository.save(samlConfigEntity);
    if (requireManagerUpdate) {
        metadataManager.updateProviderToMetadataManager(samlConfigEntity.getUuid(), samlConfigEntity.getType().name());
    }
    return SamlConversionUtil.toSamlConfig(samlConfigEntity);
}
Also used : RoleEntity(org.usermanagement.dao.entity.RoleEntity) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity)

Example 7 with SamlConfigEntity

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

the class SamlService method getAllActiveIdp.

/**
 * Gets all the active providers.
 *
 * @return the active providers
 */
public List<SamlConfig> getAllActiveIdp() {
    List<SamlConfigEntity> samlConfigEntityList = samlRepository.findAllByStatus(true);
    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)

Example 8 with SamlConfigEntity

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

the class SamlService method deleteByUuid.

/**
 * Delete provider.
 *
 * @param uuid the uuid
 * @return delete message
 */
public Message deleteByUuid(String uuid) {
    SamlConfigEntity samlConfigEntity = samlValidator.getEntityByUuid(uuid);
    samlRepository.delete(samlConfigEntity);
    metadataManager.deleteProviderFromMetadataManager(samlConfigEntity);
    return new Message("Provider deleted successfully");
}
Also used : Message(org.usermanagement.model.Message) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity)

Example 9 with SamlConfigEntity

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

the class SamlService method getById.

/**
 * Gets the provider detail.
 * @param uuid the uuid of provider.
 * @return the SamlConfig
 */
@Transactional
public SamlConfig getById(String uuid) {
    SamlConfigEntity samlConfigEntity = samlValidator.getEntityByUuid(uuid);
    SamlConfig samlConfig = SamlConversionUtil.toSamlConfig(samlConfigEntity);
    Blob blob = samlConfigEntity.getMetadata();
    byte[] bdata;
    if (blob != null) {
        try {
            bdata = blob.getBytes(1, (int) blob.length());
            String metadata = new String(bdata);
            samlConfig.setMetadata(metadata);
        } catch (Exception e) {
            LOGGER.error("Error occurred while getting provider detail" + e);
        }
    }
    return samlConfig;
}
Also used : Blob(java.sql.Blob) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) SamlConfig(org.openkilda.saml.model.SamlConfig) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with SamlConfigEntity

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

the class SamlConversionUtil method toSamlConfigEntity.

/**
 * To saml config entity.
 *
 * @param file the metadata file
 * @param name the provider name
 * @param url the metadata url
 * @param entityId the entityId
 * @param status the provider status
 * @param attribute the attribute
 * @param userCreation the userCreation
 * @param roleEntities the role entities
 * @return the saml config entity
 */
public static SamlConfigEntity toSamlConfigEntity(MultipartFile file, String name, String url, String entityId, boolean status, String attribute, boolean userCreation, Set<RoleEntity> roleEntities) {
    SamlConfigEntity samlConfigEntity = new SamlConfigEntity();
    Blob blob = null;
    try {
        if (file != null) {
            byte[] bytes = file.getBytes();
            try {
                blob = new SerialBlob(bytes);
            } catch (SerialException e) {
                LOGGER.error("Error occurred while saving saml provider" + e);
            } catch (SQLException e) {
                LOGGER.error("Error occurred while saving saml provider" + e);
            }
            samlConfigEntity.setType(IConstants.ProviderType.FILE);
        } else if (url != null) {
            samlConfigEntity.setType(IConstants.ProviderType.URL);
        }
        if (userCreation) {
            samlConfigEntity.setUserCreation(true);
            samlConfigEntity.setRoles(roleEntities);
        }
        samlConfigEntity.setMetadata(blob);
        samlConfigEntity.setEntityId(entityId);
        samlConfigEntity.setAttribute(attribute);
        samlConfigEntity.setUrl(url);
        samlConfigEntity.setName(name);
        samlConfigEntity.setStatus(status);
        samlConfigEntity.setUuid(UUID.randomUUID().toString());
        return samlConfigEntity;
    } catch (FileNotFoundException e) {
        LOGGER.error("Error occurred while saving saml provider" + e);
    } catch (IOException e) {
        LOGGER.error("Error occurred while saving saml provider" + e);
    }
    return samlConfigEntity;
}
Also used : SerialBlob(javax.sql.rowset.serial.SerialBlob) Blob(java.sql.Blob) SerialException(javax.sql.rowset.serial.SerialException) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) SerialBlob(javax.sql.rowset.serial.SerialBlob) IOException(java.io.IOException) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity)

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