Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.query.MutationQuery;
import org.niis.xroad.common.core.exception.ErrorCode;
Expand Down Expand Up @@ -144,7 +145,7 @@ static void saveMessageRecord(MessageRecord messageRecord) {
for (AttachmentStream attachmentStream : messageRecord.getAttachmentStreams()) {
attachmentNo++;
messageRecord.addAttachment(attachmentNo, // attachment numbering starts from one as in asic container
session.getLobHelper().createBlob(attachmentStream.getStream(), attachmentStream.getSize()));
Hibernate.getLobHelper().createBlob(attachmentStream.getStream(), attachmentStream.getSize()));
}

save(session, messageRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.niis.xroad.proxy.core.messagelog.TestUtil.createMessage;
import static org.niis.xroad.proxy.core.messagelog.TestUtil.createSignature;
Expand Down Expand Up @@ -104,9 +105,9 @@ static SoapMessageImpl createTestMessage() throws Exception {

static SignatureData createTestSignature() throws Exception {
return new SignatureData(
FileUtils.readFileToString(new File("signatures.xml")),
FileUtils.readFileToString(new File("hashchain.xml")),
FileUtils.readFileToString(new File("hashchainresult.xml"))
FileUtils.readFileToString(new File("signatures.xml"), StandardCharsets.UTF_8),
FileUtils.readFileToString(new File("hashchain.xml"), StandardCharsets.UTF_8),
FileUtils.readFileToString(new File("hashchainresult.xml"), StandardCharsets.UTF_8)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.google.common.collect.Iterators;
import com.google.common.collect.Streams;
import com.google.common.net.MediaType;
Expand Down Expand Up @@ -74,7 +74,7 @@ class MetadataClientRequestProcessor extends MessageProcessorBase {
static {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
MAPPER = mapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -86,7 +86,7 @@ public class RestMetadataServiceHandlerImpl implements RestServiceHandler {
static {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
MAPPER = mapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -98,7 +98,7 @@ public class RestMetadataServiceHandlerTest {
static {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
MAPPER = mapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.niis.xroad.common.exception.BadRequestException;
import org.niis.xroad.common.exception.ConflictException;
import org.niis.xroad.cs.admin.api.domain.ClientRegistrationRequest;
Expand Down Expand Up @@ -191,7 +192,7 @@ public ClientRegistrationRequest approve(ClientRegistrationRequest request) {
}

private SecurityServerClientEntity updateSubsystemNameIfNeeded(SecurityServerClientEntity subsystem, String subsystemName) {
if (StringUtils.isEmpty(subsystemName) || StringUtils.equals(subsystemName, subsystem.getName())) {
if (StringUtils.isEmpty(subsystemName) || Strings.CS.equals(subsystemName, subsystem.getName())) {
return subsystem;
} else {
subsystem.setName(subsystemName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.niis.xroad.common.exception.BadRequestException;
import org.niis.xroad.common.exception.ConflictException;
import org.niis.xroad.cs.admin.api.domain.ClientId;
Expand Down Expand Up @@ -93,7 +94,7 @@ public ClientRenameRequest add(ClientRenameRequest request) {
}

protected static String formatRenameComment(String oldName, String newName, String comment) {
if (StringUtils.isNotEmpty(newName) && StringUtils.isNotEmpty(oldName) && !StringUtils.equals(oldName, newName)) {
if (StringUtils.isNotEmpty(newName) && StringUtils.isNotEmpty(oldName) && !Strings.CS.equals(oldName, newName)) {
var newComment = "Changing subsystem name from '%s' to '%s'.".formatted(oldName, newName);
if (StringUtils.isNotBlank(comment)) {
newComment += " " + comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import static org.niis.xroad.common.acme.AcmeCustomSchema.XRD_ACME_PROFILE_ID;
Expand All @@ -47,8 +48,8 @@ public boolean accepts(URI serverUri) {
public URL resolve(URI serverUri) {
String protocol = XRD_ACME_PROFILE_ID.getSchema().equals(serverUri.getScheme()) ? "http" : "https";
try {
return new URL(protocol, serverUri.getHost(), serverUri.getPort(), serverUri.getPath());
} catch (MalformedURLException ex) {
return new URI(protocol, null, serverUri.getHost(), serverUri.getPort(), serverUri.getPath(), null, null).toURL();
} catch (MalformedURLException | URISyntaxException ex) {
throw new IllegalArgumentException("Bad server URI", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import static org.niis.xroad.common.acme.AcmeCustomSchema.XRD_ACME;
Expand All @@ -48,8 +49,8 @@ public boolean accepts(URI serverUri) {
public URL resolve(URI serverUri) {
String protocol = XRD_ACME.getSchema().equals(serverUri.getScheme()) ? "http" : "https";
try {
return new URL(protocol, serverUri.getHost(), serverUri.getPort(), serverUri.getPath());
} catch (MalformedURLException ex) {
return new URI(protocol, null, serverUri.getHost(), serverUri.getPort(), serverUri.getPath(), null, null).toURL();
} catch (MalformedURLException | URISyntaxException ex) {
throw new IllegalArgumentException("Bad server URI", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.util.StringUtils;

/**
* Use two csrf repositories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@


import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.niis.xroad.common.exception.NotFoundException;

import java.net.IDN;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -96,11 +98,11 @@ public static Instant fromOffsetDateTimeToInstant(OffsetDateTime offsetDateTime)
* @return true or false depending on the validity of the provided url
*/
public static boolean isValidUrl(String url) {
if (!isHttpsUrl(url) && !StringUtils.startsWith(url, HTTP_PROTOCOL)) {
if (!isHttpsUrl(url) && !Strings.CS.startsWith(url, HTTP_PROTOCOL)) {
return false;
}
try {
URL u = new URL(url);
URL u = URI.create(url).toURL();
String asciiHost = IDN.toASCII(u.getHost());
return asciiHost.matches(URL_HOST_REGEX);
} catch (MalformedURLException | IllegalArgumentException e) {
Expand All @@ -109,7 +111,7 @@ public static boolean isValidUrl(String url) {
}

public static boolean isHttpsUrl(String url) {
return StringUtils.startsWith(url, HTTPS_PROTOCOL);
return Strings.CS.startsWith(url, HTTPS_PROTOCOL);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public boolean isSslAuthentication(ServiceId serviceId) {
throw new CodedException(X_UNKNOWN_SERVICE, "Service '%s' not found", serviceId);
}
Service service = serviceOptional.get();
return (boolean) ObjectUtils.defaultIfNull(service.getSslAuthentication(), true);
return (boolean) ObjectUtils.getIfNull(service.getSslAuthentication(), true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.hibernate.Session;
import org.hibernate.SharedSessionContract;
import org.niis.xroad.globalconf.GlobalConfProvider;
Expand Down Expand Up @@ -260,7 +261,7 @@ public boolean isSslAuthentication(ServiceId serviceId) {
return tx(session -> {
Service service = getService(session, serviceId);
if (service != null) {
return ObjectUtils.defaultIfNull(
return ObjectUtils.getIfNull(
service.getSslAuthentication(), true);
}

Expand Down Expand Up @@ -364,7 +365,7 @@ public List<String> getTspUrl() {
@Override
public String getTspCostType(String tspUrl) {
return tx(session -> getConf(session).getTimestampingServices().stream()
.filter(t -> StringUtils.equals(t.getUrl(), tspUrl))
.filter(t -> Strings.CS.equals(t.getUrl(), tspUrl))
.findFirst()
.map(TimestampingService::getCostType)
.orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.springframework.stereotype.Component;

import java.util.Optional;
Expand All @@ -51,13 +51,13 @@ public Optional<String> getRename(ClientId clientId) {
}

public void set(ClientId clientId, String oldName, String newName) {
if (!StringUtils.equals(oldName, newName)) {
if (!Strings.CS.equals(oldName, newName)) {
nameCache.put(clientId, new Change(oldName, newName, false));
}
}

public void submit(ClientId clientId, String oldName, String newName) {
if (!StringUtils.equals(oldName, newName)) {
if (!Strings.CS.equals(oldName, newName)) {
nameCache.put(clientId, new Change(oldName, newName, true));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.stream.Collectors;

import static ee.ria.xroad.common.identifier.XRoadId.ENCODED_ID_SEPARATOR;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.ObjectUtils.getIfNull;

/**
* Convert Service related data between openapi and service domain classes
Expand Down Expand Up @@ -92,7 +92,7 @@ public ServiceDto convert(Service service, ClientId clientId) {
if (service.getUrl().startsWith(FormatUtils.HTTP_PROTOCOL)) {
serviceDto.setSslAuth(false);
} else {
serviceDto.setSslAuth(defaultIfNull(service.getSslAuthentication(), true));
serviceDto.setSslAuth(getIfNull(service.getSslAuthentication(), true));
}
serviceDto.setTimeout(service.getTimeout());
serviceDto.setUrl(service.getUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.bouncycastle.operator.OperatorCreationException;
import org.niis.xroad.common.core.exception.XrdRuntimeException;
import org.niis.xroad.globalconf.GlobalConfProvider;
Expand Down Expand Up @@ -297,7 +297,7 @@ private void updateClientStatuses(ServerConfEntity serverConf, SecurityServerId

if (clientId.isSubsystem()) {
subsystemNameStatus.clearIf(clientId,
(oldName, newName) -> !StringUtils.equals(oldName, globalConfProvider.getSubsystemName(clientId)));
(oldName, newName) -> !Strings.CS.equals(oldName, globalConfProvider.getSubsystemName(clientId)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.niis.xroad.common.exception.ConflictException;
import org.niis.xroad.common.exception.NotFoundException;
import org.niis.xroad.globalconf.GlobalConfProvider;
Expand Down Expand Up @@ -766,13 +767,13 @@ private Predicate<ServiceClient> getSubjectMemberOrGroupCodePredicate(String mem
XRoadId xRoadId = dto.getSubjectId();
if (xRoadId instanceof ClientId) {
String clientMemberCode = ((ClientId) xRoadId).getMemberCode();
return StringUtils.containsIgnoreCase(clientMemberCode, memberGroupCode);
return Strings.CI.contains(clientMemberCode, memberGroupCode);
} else if (xRoadId instanceof GlobalGroupId) {
String globalGroupCode = ((GlobalGroupId) xRoadId).getGroupCode();
return StringUtils.containsIgnoreCase(globalGroupCode, memberGroupCode);
return Strings.CI.contains(globalGroupCode, memberGroupCode);
} else if (xRoadId instanceof LocalGroupId) {
String localGroupCode = ((LocalGroupId) xRoadId).getGroupCode();
return StringUtils.containsIgnoreCase(localGroupCode, memberGroupCode);
return Strings.CI.contains(localGroupCode, memberGroupCode);
} else {
return false;
}
Expand All @@ -784,7 +785,7 @@ private Predicate<ServiceClient> getSubjectSubsystemCodePredicate(String subsyst
XRoadId xRoadId = dto.getSubjectId();
if (xRoadId instanceof ClientId) {
String clientSubsystemCode = ((ClientId) xRoadId).getSubsystemCode();
return StringUtils.containsIgnoreCase(clientSubsystemCode, subsystemCode);
return Strings.CI.contains(clientSubsystemCode, subsystemCode);
} else {
return false;
}
Expand Down Expand Up @@ -822,10 +823,10 @@ private Predicate<ServiceClient> getMemberNameOrGroupDescriptionPredicate(String
String subsystemName = dto.getSubsystemName();
String localGroupDescription = dto.getLocalGroupDescription();
String globalGroupDescription = dto.getGlobalGroupDescription();
return StringUtils.containsIgnoreCase(memberName, memberNameOrGroupDescription)
|| StringUtils.containsIgnoreCase(subsystemName, memberNameOrGroupDescription)
|| StringUtils.containsIgnoreCase(localGroupDescription, memberNameOrGroupDescription)
|| StringUtils.containsIgnoreCase(globalGroupDescription, memberNameOrGroupDescription);
return Strings.CI.contains(memberName, memberNameOrGroupDescription)
|| Strings.CI.contains(subsystemName, memberNameOrGroupDescription)
|| Strings.CI.contains(localGroupDescription, memberNameOrGroupDescription)
|| Strings.CI.contains(globalGroupDescription, memberNameOrGroupDescription);
};
}

Expand Down
Loading
Loading