use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class HomeActions method verifyAuthentication.
public ActionResponse<Void> verifyAuthentication(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
CsrfToken csrfToken = csrfTokenRespository.loadToken(servletRequest);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
boolean isAnonymous = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).anyMatch(authority -> authority.equals(ROLE_ANONYMOUS));
boolean authorized = authentication.isAuthenticated() && !isAnonymous && csrfToken != null && !authentication.getAuthorities().isEmpty();
if (!authorized) {
servletRequest.getSession().invalidate();
return new ActionResponse<>(HttpStatus.UNAUTHORIZED);
} else {
servletResponse.addHeader(csrfToken.getHeaderName(), csrfToken.getToken());
}
return new ActionResponse<>(HttpStatus.OK);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class ProviderConfigSelectCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
String providerName = fieldModel.getDescriptorName();
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(providerName);
List<LabelValueSelectOption> options = List.of();
if (descriptorKey.isPresent()) {
List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), ConfigContextEnum.GLOBAL);
options = configurationModels.stream().map(this::createNameToIdOption).flatMap(Optional::stream).collect(Collectors.toList());
}
LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
return new ActionResponse<>(HttpStatus.OK, optionList);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class ProcessingSelectCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
String channelName = fieldModel.getFieldValue(ChannelDescriptor.KEY_CHANNEL_NAME).orElse("");
List<LabelValueSelectOption> options = Arrays.stream(ProcessingType.values()).filter(processingType -> this.shouldInclude(processingType, channelName)).map(processingType -> new LabelValueSelectOption(processingType.getLabel(), processingType.name())).collect(Collectors.toList());
LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
return new ActionResponse<>(HttpStatus.OK, optionList);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class SystemActions method getSystemMessagesAfter.
private ActionResponse<MultiSystemMessageModel> getSystemMessagesAfter(String startDate) throws ParseException {
OffsetDateTime date = DateUtils.parseDateFromJsonString(startDate);
List<SystemMessageModel> messages = systemMessageAccessor.getSystemMessagesAfter(date);
return new ActionResponse<>(HttpStatus.OK, new MultiSystemMessageModel(messages));
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class DescriptorMetadataActions method getDescriptorsByPermissions.
public ActionResponse<DescriptorsResponseModel> getDescriptorsByPermissions(@Nullable String name, @Nullable String type, @Nullable String context) {
Predicate<Descriptor> descriptorFilter = ignored -> true;
Set<ConfigContextEnum> requestedContexts = Set.of(ConfigContextEnum.GLOBAL, ConfigContextEnum.DISTRIBUTION);
if (StringUtils.isNotBlank(name)) {
descriptorFilter = descriptorFilter.and(descriptor -> name.equals(descriptor.getDescriptorKey().getUniversalKey()));
}
if (StringUtils.isNotBlank(type)) {
descriptorFilter = descriptorFilter.and(descriptor -> type.equals(descriptor.getType().name()));
}
if (StringUtils.isNotBlank(context)) {
ConfigContextEnum requestedContext = EnumUtils.getEnum(ConfigContextEnum.class, context);
if (null != requestedContext) {
requestedContexts = Set.of(requestedContext);
} else {
requestedContexts = Set.of();
}
}
return createDescriptorResponse(descriptorFilter, requestedContexts);
}
Aggregations