use of org.usermanagement.exception.RequestValidationException 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.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class SamlValidator method validateEntityId.
/**
* Validate entity id.
*
* @param file the metadata file
* @param url the metadata url
* @return the entity id
*/
private String validateEntityId(MultipartFile file, String url) {
String entityId = null;
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
Document doc = null;
if (file != null) {
doc = docBuilder.parse(file.getInputStream());
} else if (url != null) {
doc = docBuilder.parse(new URL(url).openStream());
}
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName(doc.getDocumentElement().getNodeName());
for (int temp = 0; temp < nodeList.getLength(); temp++) {
Node node = nodeList.item(temp);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
entityId = element.getAttribute("entityID");
}
}
return entityId;
} catch (Exception e) {
LOGGER.error("Error occurred while validating entity ID" + e);
throw new RequestValidationException(messageUtil.getAttributeMetadataInvalid("url"));
}
}
use of org.usermanagement.exception.RequestValidationException 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.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class LinkStoreConfigValidator method validate.
/**
* Validate.
*
* @param linkStoreConfigDto the link store config dto
*/
public void validate(final LinkStoreConfigDto linkStoreConfigDto) {
List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
if (CollectionUtil.isEmpty(oauthConfigEntityList)) {
LOGGER.warn(messageUtil.getStoreMustConfigured());
throw new RequestValidationException(messageUtil.getStoreMustConfigured());
}
List<String> urls = StoreUrl.getUrlName(StoreType.LINK_STORE.getCode());
for (Entry<String, UrlDto> urlEntrySet : linkStoreConfigDto.getUrls().entrySet()) {
if (!urls.contains(urlEntrySet.getKey())) {
LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
} else if (ValidatorUtil.isNull(urlEntrySet.getValue().getUrl())) {
LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotNull("url of " + urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotNull(urlEntrySet.getKey()));
} else if (ValidatorUtil.isNull(urlEntrySet.getValue().getMethodType())) {
LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
}
}
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class SwitchStoreConfigValidator method validate.
/**
* Validate.
*
* @param switchStoreConfigDto the link store config dto
*/
public void validate(final SwitchStoreConfigDto switchStoreConfigDto) {
List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
if (CollectionUtil.isEmpty(oauthConfigEntityList)) {
LOGGER.warn(messageUtil.getStoreMustConfigured());
throw new RequestValidationException(messageUtil.getStoreMustConfigured());
}
List<String> urls = StoreUrl.getUrlName(StoreType.SWITCH_STORE.getCode());
for (Entry<String, UrlDto> urlEntrySet : switchStoreConfigDto.getUrls().entrySet()) {
if (!urls.contains(urlEntrySet.getKey())) {
LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
} else if (ValidatorUtil.isNull(urlEntrySet.getValue().getUrl())) {
LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotNull("url of " + urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotNull(urlEntrySet.getKey()));
} else if (ValidatorUtil.isNull(urlEntrySet.getValue().getMethodType())) {
LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
throw new RequestValidationException(messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
}
}
}
Aggregations