use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AbstractUploadAction method deleteFile.
public ActionResponse<Void> deleteFile() {
if (isTargetUndefined()) {
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, META_DATA_MISSING);
}
if (!authorizationManager.hasUploadDeletePermission(target.getContext(), target.getDescriptorKey())) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
try {
String targetFilename = target.getFilename();
File fileToValidate = filePersistenceUtil.createUploadsFile(targetFilename);
filePersistenceUtil.delete(fileToValidate);
} catch (IOException ex) {
logger.error("Error deleting file - file: {}, context: {}, descriptor: {} ", target.getFilename(), target.getContext(), target.getDescriptorKey().getUniversalKey());
logger.error("Error deleting file caused by: ", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, "Error deleting uploaded file from server.");
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AuthenticationActions method authenticateUser.
public ActionResponse<Void> authenticateUser(HttpServletRequest servletRequest, HttpServletResponse servletResponse, LoginConfig loginConfig) throws BadCredentialsException {
ActionResponse<Void> response = new ActionResponse<>(HttpStatus.UNAUTHORIZED);
try {
Authentication pendingAuthentication = createUsernamePasswordAuthToken(loginConfig);
Authentication authentication = authenticationProvider.authenticate(pendingAuthentication);
boolean authenticated = authentication.isAuthenticated() && !authentication.getAuthorities().isEmpty();
if (authenticated) {
CsrfToken token = csrfTokenRepository.generateToken(servletRequest);
csrfTokenRepository.saveToken(token, servletRequest, servletResponse);
servletResponse.setHeader(token.getHeaderName(), token.getToken());
response = new ActionResponse<>(HttpStatus.NO_CONTENT);
} else {
servletRequest.getSession().invalidate();
}
} catch (AuthenticationException ex) {
logger.error("Error Authenticating user.", ex);
}
return response;
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class CertificateActions method updateWithoutChecks.
@Override
protected ActionResponse<CertificateModel> updateWithoutChecks(Long id, CertificateModel resource) {
try {
Optional<CustomCertificateModel> existingCertificate = certificateAccessor.getCertificate(id);
String logableId = escapeUtil.replaceWithUnderscore(resource.getId());
String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
logger.info("Updating certificate with id: {} and alias: {}", logableId, loggableAlias);
if (existingCertificate.isPresent()) {
CertificateModel certificateModel = importCertificate(resource);
return new ActionResponse<>(HttpStatus.NO_CONTENT, certificateModel);
}
logger.error("Certificate with id: {} missing.", logableId);
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Certificate not found.");
} catch (AlertException ex) {
logger.error("Error occurred updating certificate", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class CertificateActions method deleteWithoutChecks.
@Override
protected ActionResponse<CertificateModel> deleteWithoutChecks(Long id) {
try {
Optional<CustomCertificateModel> certificate = certificateAccessor.getCertificate(id);
if (certificate.isPresent()) {
CustomCertificateModel certificateModel = certificate.get();
logger.info("Delete certificate with id: {} and alias: {}", certificateModel.getNullableId(), certificateModel.getAlias());
trustStoreService.removeCertificate(certificateModel);
certificateAccessor.deleteCertificate(id);
}
} catch (AlertException ex) {
logger.error("Error deleting certificate", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error deleting certificate: %s", ex.getMessage()));
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class RoleActions method updateWithoutChecks.
@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
try {
String roleName = resource.getRoleName();
Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
if (existingRole.isPresent()) {
logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
if (!existingRole.get().getName().equals(roleName)) {
authorizationManager.updateRoleName(id, roleName);
}
Set<PermissionModel> permissions = resource.getPermissions();
PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
Aggregations