use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class LdapConfigService method create.
@Transactional(TxType.NEVER)
public LdapConfig create(IdentityUser user, LdapConfig ldapConfig) {
ldapConfig.setOwner(user.getUserId());
ldapConfig.setAccount(user.getAccount());
try {
return ldapConfigRepository.save(ldapConfig);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.LDAP_CONFIG, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ImageCatalogService method delete.
public void delete(String name) {
if (isEnvDefault(name)) {
throw new BadRequestException(String.format("%s cannot be deleted because it is an environment default image catalog.", name));
}
ImageCatalog imageCatalog = get(name);
authorizationService.hasWritePermission(imageCatalog);
imageCatalog.setArchived(true);
setImageCatalogAsDefault(null);
imageCatalog.setImageCatalogName(generateArchiveName(name));
imageCatalogRepository.save(imageCatalog);
LOGGER.info("Image catalog has been archived: {}", imageCatalog);
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class RecipeService method create.
@Transactional(TxType.NEVER)
public Recipe create(IdentityUser user, Recipe recipe) {
recipe.setOwner(user.getUserId());
recipe.setAccount(user.getAccount());
try {
return recipeRepository.save(recipe);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.RECIPE, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class FileSystemValidator method validateFilesystemRequest.
private void validateFilesystemRequest(FileSystemRequest fileSystemRequest) {
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
Validator validator = validatorFactory.getValidator();
try {
String json = JsonUtil.writeValueAsString(fileSystemRequest.getProperties());
Object fsConfig = JsonUtil.readValue(json, fileSystemRequest.getType().getClazz());
Set<ConstraintViolation<Object>> violations = validator.validate(fsConfig);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
} catch (IOException e) {
throw new BadRequestException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class LdapConfigValidator method validateLdapConnection.
private void validateLdapConnection(String protocol, String serverHost, Integer serverPort, String bindDn, String bindPassword) {
try {
LOGGER.info("Validate connection to LDAP host: '{}', port: '{}', protocol: '{}'.", serverHost, serverPort, protocol);
// BEGIN GENERATED CODE
Hashtable<String, String> env = new Hashtable<>();
// END GENERATED CODE
env.put("com.sun.jndi.ldap.read.timeout", "1000");
env.put("com.sun.jndi.ldap.connect.timeout", "5000");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
String url = new StringBuilder(protocol).append("://").append(serverHost).append(':').append(serverPort).toString();
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, bindDn);
env.put(Context.SECURITY_CREDENTIALS, bindPassword);
Context ctx = new InitialDirContext(env);
ctx.close();
} catch (NamingException e) {
throw new BadRequestException("Failed to connect to LDAP server: " + e.getMessage(), e);
}
}
Aggregations