Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Each client skeleton has a default 'ApplicationInitListener' and a default 'Secu

##### (1st) application.properties
Location: `src/main/resources`
* * Decide the required security level and set the `server.ssl.enabled` and `token.security.filter.enabled` properties accordingly.
* * If `token.security.filter.enabled` is true, `server.ssl.enabled` also has to be true !!!
* Decide the required security level and set the `server.ssl.enabled` and `token.security.filter.enabled` properties accordingly.
* If `token.security.filter.enabled` is true, `server.ssl.enabled` also has to be true !!!
* [Create](https://github.com/arrowhead-f/core-java-spring#certificates) your own client certificate (or for demo purpose use the provided one) and update the further `server.ssl...` properties accordingly. *(**Note** that `server.ssl.key-store-password` and `server.ssl.key-password` must be the same.)*
* Change the `client_system_name` property to your system name. *(**Note** that it should be in line with your certificate common name e.g.: when your certificate common name is `my_awesome_client.my_cloud.my_company.arrowhed.eu`, then your system name is  `my_awesome_client`)*
* Change the `client_system_name` property to your system name. *(**Note** that it should be in line with your certificate common name e.g.: when your certificate common name is `my-awesome-client.my-cloud.my-company.arrowhed.eu`, then your system name is  `my-awesome-client`)*
* Adjust the Service Registry Core System location by the `sr_address` and `sr_port` properties.
* In case of a provider you have to set its web-server parameters by the `server.address` and `server.port` properties.
* In case of a consumer decide whether it should act as a web-server or not. If yes, then set the `spring.main.web-application-type` to 'servlet' and set further server parameters like in the provider case. If not, just leave these properties unchanged.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
############################################

# Name of the client system
client_system_name=CONSUMER_SKELETON
client_system_name=CONSUMERSKELETON

# Set the web application type to 'servlet' if your consumer client should act as a web-server
# and fill the address and port propetries with valid values [Defaults, when not adjusted: localhost:8080]
Expand All @@ -25,9 +25,9 @@ sr_port=8443
server.ssl.enabled=true

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:certificates/consumer_skeleton.p12
server.ssl.key-store=classpath:certificates/consumerskeleton.p12
server.ssl.key-store-password=123456
server.ssl.key-alias=consumer_skeleton
server.ssl.key-alias=consumerskeleton
server.ssl.key-password=123456
server.ssl.client-auth=need
server.ssl.trust-store-type=PKCS12
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class ContainerConfiguration implements WebServerFactoryCustomizer<Tomcat
// methods

//-------------------------------------------------------------------------------------------------
@SuppressWarnings("rawtypes")
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addConnectorCustomizers(connector -> {
final AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();

protocol.setMaxKeepAliveRequests(containerConfProperties.getMaxKeepAliveRequests());

//
log.info("####################################################################################");
log.info("#");
log.info("# TomcatCustomizer");
Expand All @@ -41,8 +41,7 @@ public void customize(TomcatServletWebServerFactory factory) {
log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
log.info("# max connections: {}", protocol.getMaxConnections());
log.info("#");
log.info(
"####################################################################################");
log.info("####################################################################################");
});
}

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

# Name of the client system
client_system_name=PROVIDER_SKELETON
client_system_name=PROVIDERSKELETON

# Client web-server parameters
server.address=127.0.0.1
Expand All @@ -28,9 +28,9 @@ server.ssl.enabled=true
token.security.filter.enabled=true

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:certificates/provider_skeleton.p12
server.ssl.key-store=classpath:certificates/providerskeleton.p12
server.ssl.key-store-password=123456
server.ssl.key-alias=provider_skeleton
server.ssl.key-alias=providerskeleton
server.ssl.key-password=123456
server.ssl.client-auth=need
server.ssl.trust-store-type=PKCS12
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public class ContainerConfiguration implements WebServerFactoryCustomizer<Tomcat
@Autowired
ContainerConfProperties containerConfProperties;

private final Logger log = LogManager.getLogger( ContainerConfiguration.class);
private final Logger log = LogManager.getLogger(ContainerConfiguration.class);

//=================================================================================================
// methods

//-------------------------------------------------------------------------------------------------
@SuppressWarnings("rawtypes")
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addConnectorCustomizers(connector -> {
final AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();

protocol.setMaxKeepAliveRequests(containerConfProperties.getMaxKeepAliveRequests());

//
log.info("####################################################################################");
log.info("#");
log.info("# TomcatCustomizer");
Expand All @@ -41,9 +41,7 @@ public void customize(TomcatServletWebServerFactory factory) {
log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
log.info("# max connections: {}", protocol.getMaxConnections());
log.info("#");
log.info(
"####################################################################################");
log.info("####################################################################################");
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public class PublisherController {
public String echoService() {
logger.debug("echoService started...");

publisherService.publish(PresetEventType.REQUEST_RECEIVED, Map.of( EventTypeConstants.EVENT_TYPE_REQUEST_RECEIVED_METADATA_REQUEST_TYPE, HttpMethod.GET.name() ), CommonConstants.ECHO_URI);
publisherService.publish(PresetEventType.REQUEST_RECEIVED, Map.of(EventTypeConstants.EVENT_TYPE_REQUEST_RECEIVED_METADATA_REQUEST_TYPE, HttpMethod.GET.name()), CommonConstants.ECHO_URI);

return "Got it!";
}

//-------------------------------------------------------------------------------------------------
//TODO: implement here your provider related REST end points

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
@ConditionalOnExpression(CommonConstants.$SERVER_SSL_ENABLED_WD + " and !" + ApplicationCommonConstants.$TOKEN_SECURITY_FILTER_ENABLED_WD)
public class PublisherAccessControlFilter extends AccessControlFilter {

@Override
protected void checkClientAuthorized(final String clientCN, final String method, final String requestTarget, final String requestJSON, final Map<String,String[]> queryParams) {
super.checkClientAuthorized(clientCN, method, requestTarget, requestJSON, queryParams);

//TODO: implement here your custom access filter if any further
}
}
@Override
protected void checkClientAuthorized(final String clientCN, final String method, final String requestTarget, final String requestJSON, final Map<String,String[]> queryParams) {
super.checkClientAuthorized(clientCN, method, requestTarget, requestJSON, queryParams);
//TODO: implement here your custom access filter if any further
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
if (tokenSecurityFilterEnabled) {
tokenSecurityFilter = new PublisherTokenSecurityFilter();
http.addFilterAfter(tokenSecurityFilter, SecurityContextHolderAwareRequestFilter.class);
http.addFilterAfter(tokenSecurityFilter, SecurityContextHolderAwareRequestFilter.class);
}
}

//-------------------------------------------------------------------------------------------------
public PublisherTokenSecurityFilter getTokenSecurityFilter() {
return tokenSecurityFilter;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class PublisherService {
//-------------------------------------------------------------------------------------------------
//Sample implementation of event publishing of preset event types
public void publish(final PresetEventType eventType, final Map<String, String> metadata, final String payload) {

final EventPublishRequestDTO request = getPublishRequest(eventType, metadata, payload);
arrowheadService.publishToEventHandler(request);
}
Expand Down Expand Up @@ -78,4 +77,4 @@ private SystemRequestDTO getSource() {

return source;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
############################################

# Name of the client system
client_system_name=PUBLISHER_SKELETON
client_system_name=PUBLISHERSKELETON

# Client web-server parameters
server.address=127.0.0.1
Expand All @@ -25,9 +25,9 @@ server.ssl.enabled=true
token.security.filter.enabled=false

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:certificates/publisher_skeleton.p12
server.ssl.key-store=classpath:certificates/publisherskeleton.p12
server.ssl.key-store-password=123456
server.ssl.key-alias=publisher_skeleton
server.ssl.key-alias=publisherskeleton
server.ssl.key-password=123456
server.ssl.client-auth=need
server.ssl.trust-store-type=PKCS12
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class SubscriberUtilities {

//-------------------------------------------------------------------------------------------------
public static SubscriptionRequestDTO createSubscriptionRequestDTO(final String eventType, final SystemRequestDTO subscriber, final String notificationUri) {

final SubscriptionRequestDTO subscription = new SubscriptionRequestDTO(eventType.toUpperCase(),
subscriber,
null,
SubscriberDefaults.DEFAULT_EVENT_NOTIFICATION_BASE_URI + "/" + notificationUri,
false,
null,
null,
null);
null);

return subscription;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class ContainerConfiguration implements WebServerFactoryCustomizer<Tomcat
// methods

//-------------------------------------------------------------------------------------------------
@SuppressWarnings("rawtypes")
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addConnectorCustomizers(connector -> {
final AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();

protocol.setMaxKeepAliveRequests(containerConfProperties.getMaxKeepAliveRequests());

//
log.info("####################################################################################");
log.info("#");
log.info("# TomcatCustomizer");
Expand All @@ -41,9 +41,7 @@ public void customize(TomcatServletWebServerFactory factory) {
log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
log.info("# max connections: {}", protocol.getMaxConnections());
log.info("#");
log.info(
"####################################################################################");
log.info("####################################################################################");
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String echoService() {
public void receivePublisherReceivedRequestEvent(@RequestBody final EventDTO event ) {
logger.debug("receivePublisherReceivedRequestEvent started...");

if( event.getEventType() == null) {
if (event.getEventType() == null) {
logger.debug("EventType is null.");
}

Expand All @@ -45,10 +45,10 @@ public void receivePublisherReceivedRequestEvent(@RequestBody final EventDTO eve

//-------------------------------------------------------------------------------------------------
@PostMapping(path = SubscriberConstants.START_INIT_NOTIFICATION_URI)
public void receivePublsisherStartedInitEvent(@RequestBody final EventDTO event) {
public void receivePublisherStartedInitEvent(@RequestBody final EventDTO event) {
logger.debug("receivePublsisherStartedInitEvent started... ");

if( event.getEventType() == null) {
if (event.getEventType() == null) {
logger.debug("EventType is null.");
}

Expand All @@ -57,10 +57,10 @@ public void receivePublsisherStartedInitEvent(@RequestBody final EventDTO event)

//-------------------------------------------------------------------------------------------------
@PostMapping(path = SubscriberConstants.START_RUN_NOTIFICATION_URI)
public void receivePublsisherStartedRunEvent(@RequestBody final EventDTO event ) {
public void receivePublisherStartedRunEvent(@RequestBody final EventDTO event ) {
logger.debug("receivePublsisherStartedRunEvent started... ");

if( event.getEventType() == null) {
if (event.getEventType() == null) {
logger.debug("EventType is null.");
}

Expand All @@ -69,4 +69,4 @@ public void receivePublsisherStartedRunEvent(@RequestBody final EventDTO event )

//-------------------------------------------------------------------------------------------------
//TODO: implement here additional subscriber related REST end points
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public class SubscriberNotificationAccessControlFilter extends ArrowheadFilter {
public void setEventTypeMap( final Map<String, String> eventTypeMap) { this.eventTypeMap = eventTypeMap;}
public void setServerCN( final String serverCN) { this.serverCN = serverCN; }

//=================================================================================================
// assistant methods

//-------------------------------------------------------------------------------------------------
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
Expand All @@ -53,7 +50,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons

if (eventTypeMap != null) {
for (final String notificationUri : eventTypeMap.values()) {
if (requestTarget.endsWith( SubscriberDefaults.DEFAULT_EVENT_NOTIFICATION_BASE_URI + "/" + notificationUri )) {
if (requestTarget.endsWith(SubscriberDefaults.DEFAULT_EVENT_NOTIFICATION_BASE_URI + "/" + notificationUri)) {
checkIfClientIsAnAllowedCoreSystem(getCertificateCNFromRequest(httpRequest), getServerCloudCN(serverCN), allowedCoreSystemsForSendingNotification, requestTarget);
}
}
Expand All @@ -65,6 +62,9 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
chain.doFilter(request, response);
}

//=================================================================================================
// assistant methods

//-------------------------------------------------------------------------------------------------
@Nullable
private String getCertificateCNFromRequest(final HttpServletRequest request) {
Expand Down Expand Up @@ -108,4 +108,4 @@ protected String getServerCloudCN( final String serverCN ) {

return serverFields[1];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ protected void configure( final HttpSecurity http) throws Exception {
super.configure(http);

if (sslEnabled) {

notificationFilter = new SubscriberNotificationAccessControlFilter();
http.addFilterBefore( notificationFilter , SecurityContextHolderAwareRequestFilter.class );


if (tokenSecurityFilterEnabled) {
tokenSecurityFilter = new SubscriberTokenSecurityFilter();
http.addFilterAfter(tokenSecurityFilter, SecurityContextHolderAwareRequestFilter.class);
}

}
}

Expand All @@ -57,5 +54,4 @@ public SubscriberTokenSecurityFilter getTokenSecurityFilter() {
public SubscriberNotificationAccessControlFilter getNotificationFilter() {
return notificationFilter;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons

if (eventTypeMap != null) {
for (final String notificationUri : eventTypeMap.values()) {
if ( requestTarget.endsWith(SubscriberDefaults.DEFAULT_EVENT_NOTIFICATION_BASE_URI + "/" + notificationUri)) {
if (requestTarget.endsWith(SubscriberDefaults.DEFAULT_EVENT_NOTIFICATION_BASE_URI + "/" + notificationUri)) {
chain.doFilter(request, response);
return;
}
Expand All @@ -92,7 +92,6 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
}

checkToken(clientCN, token, requestTarget);

} catch (final ArrowheadException ex) {
handleException(ex, response);
}
Expand All @@ -112,5 +111,4 @@ private String getCertificateCNFromRequest(final HttpServletRequest request) {

return null;
}

}
}
Loading