package at.gv.egiz.moazs.preprocess; import at.gv.zustellung.app2mzs.xsd.*; import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; @Component public class MzsDeliveryRequestValidator { /** * Checks if the mandatory fields that are needed to send a tnvz:QueryPersonRequest are present. * @param request * @return true if mandatory fields are present. */ public boolean isTnvzComplete(DeliveryRequestType request) { return !request.getConfig().isPerformQueryPersonRequest() || (request.getTnvzMetaData() != null && request.getSender().getCorporateBody() != null); } /** * Check if all mandatory fields of configuration are present. * * @param profile * @return true if all mandatory fields are present. */ public boolean isConfigProfileComplete(@Nullable ConfigType profile) { return profile != null && profile.isPerformQueryPersonRequest() != null && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest()) && isClientConfigured(profile.getMSGClient()) && areSinksConfigured(profile.getMsgResponseSinks()); } private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) { return !isPerformQueryPersonRequest || (tnvzClient != null && tnvzClient.getURL() != null && tnvzClient.getReceiveTimeout() != null && tnvzClient.getConnectionTimeout() != null && isSSLConfigured(tnvzClient)); } private boolean isClientConfigured(ClientType clientParams) { return clientParams != null && clientParams.getURL() != null && isSSLConfigured(clientParams) && clientParams.getReceiveTimeout() != null && clientParams.getConnectionTimeout() != null; } private boolean isSSLConfigured(ClientType clientParams) { return !clientParams.getURL().startsWith("https") || (clientParams.getSSL() != null && clientParams.getSSL().isTrustAll() != null && clientParams.getSSL().isLaxHostNameVerification() != null && isKeyStoreConfigured(clientParams.getSSL().getKeyStore()) && isTrustStoreConfigured(clientParams.getSSL().getTrustStore())); } private boolean isKeyStoreConfigured(KeyStoreType keyStore) { return keyStore == null || (keyStore.getPassword() != null && keyStore.getFileType() != null && keyStore.getFileName() != null); } private boolean isTrustStoreConfigured(KeyStoreType trustStore) { return trustStore == null || (trustStore.getPassword() != null && "JKS".equals(trustStore.getFileType()) && trustStore.getFileName() != null); } private boolean areSinksConfigured(MsgResponseSinksType sinks) { return sinks != null && sinks.isLogResponse() != null && isSaveResponseToFileConfigured(sinks.getSaveResponseToFile()) && isForwardResponseToServiceConfigured(sinks.getForwardResponseToService()); } private boolean isSaveResponseToFileConfigured(SaveResponseToFileType fileSink) { return fileSink != null && (!fileSink.isActive() || fileSink.getPath() != null); } private boolean isForwardResponseToServiceConfigured(ForwardResponseToServiceType forwardSink) { return forwardSink != null && (!forwardSink.isActive() || isClientConfigured(forwardSink.getMzsClient())); } }