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;
}
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"));
}
}
}
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);
}
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);
}
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;
}
Aggregations