Search in sources :

Example 1 with OauthConfigEntity

use of org.openkilda.store.auth.dao.entity.OauthConfigEntity 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()));
        }
    }
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) UrlDto(org.openkilda.store.model.UrlDto) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 2 with OauthConfigEntity

use of org.openkilda.store.auth.dao.entity.OauthConfigEntity 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()));
        }
    }
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) UrlDto(org.openkilda.store.model.UrlDto) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 3 with OauthConfigEntity

use of org.openkilda.store.auth.dao.entity.OauthConfigEntity in project open-kilda by telstra.

the class AuthService method getOauthConfig.

/**
 * Gets the oauth config.
 *
 * @return the oauth config
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public OauthTwoConfigDto getOauthConfig() {
    LOGGER.info("Get oauth configuration");
    List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
    OauthConfigEntity oauthConfigEntity = null;
    if (oauthConfigEntityList.size() > 0) {
        oauthConfigEntity = oauthConfigEntityList.get(0);
    }
    if (oauthConfigEntity == null) {
        oauthConfigEntity = new OauthConfigEntity();
    }
    return OauthConfigConverter.toOauthTwoConfigDto(oauthConfigEntity);
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OauthConfigEntity

use of org.openkilda.store.auth.dao.entity.OauthConfigEntity in project open-kilda by telstra.

the class AuthService method saveOrUpdateOauthConfig.

/**
 * Save or update oauth config.
 *
 * @param oauthTwoConfigDto the oauth two config dto
 * @return the oauth two config dto
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public OauthTwoConfigDto saveOrUpdateOauthConfig(final OauthTwoConfigDto oauthTwoConfigDto) {
    LOGGER.info("Save or update oauth configuration");
    List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
    OauthConfigEntity oauthConfigEntity = null;
    if (oauthConfigEntityList.size() > 0) {
        oauthConfigEntity = oauthConfigEntityList.get(0);
    }
    if (oauthConfigEntity == null) {
        oauthConfigEntity = new OauthConfigEntity();
    }
    oauthConfigEntity = OauthConfigConverter.toOauthConfigEntity(oauthTwoConfigDto, oauthConfigEntity);
    oauthConfigEntity = oauthConfigRepository.save(oauthConfigEntity);
    return OauthConfigConverter.toOauthTwoConfigDto(oauthConfigEntity);
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OauthConfigEntity (org.openkilda.store.auth.dao.entity.OauthConfigEntity)4 UrlDto (org.openkilda.store.model.UrlDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestValidationException (org.usermanagement.exception.RequestValidationException)2