Skip to content

Commit

Permalink
Merge pull request #4 from bci-oss/feature/self-registration-to-disco…
Browse files Browse the repository at this point in the history
…very-Finder

Self-registration-Implementation
  • Loading branch information
tunacicek authored May 2, 2023
2 parents 7f170c9 + 0c9b9c0 commit 8eaf73c
Show file tree
Hide file tree
Showing 28 changed files with 993 additions and 50 deletions.
73 changes: 41 additions & 32 deletions README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import org.eclipse.tractusx.bpndiscovery.model.Error;
import org.eclipse.tractusx.bpndiscovery.model.ErrorResponse;
import org.eclipse.tractusx.bpndiscovery.service.EntityNotFoundException;
import org.eclipse.tractusx.bpndiscovery.service.ValidationException;
import org.eclipse.tractusx.bpndiscovery.service.exception.EntityNotFoundException;
import org.eclipse.tractusx.bpndiscovery.service.exception.ValidationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery;

import org.eclipse.tractusx.bpndiscovery.service.RegisterService;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Profile( "!test" )
@Component
@Slf4j
public class ApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent> {

private final RegisterService registerService;

public ApplicationReadyEventListener( RegisterService registerService ) {
this.registerService = registerService;
}

@Override
public void onApplicationEvent( ApplicationReadyEvent event ) {
registerService.registerAfterStartup();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jdbc.repository.config.EnableJdbcAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJdbcAuditing
@EnableConfigurationProperties( BpnDiscoveryProperties.class )
@EnableConfigurationProperties( { BpnDiscoveryProperties.class, DiscoveryFinderClientProperties.class } )
@ComponentScan( basePackages = { "org.eclipse.tractusx.bpndiscovery", "org.openapitools.configuration" } )
@EnableScheduling
public class BpnDiscoveryApplication {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class BpnDiscoveryProperties {
@NotEmpty( message = "allowedTypes (oen,etc.) must not be empty" )
private List<String> allowedTypes;

private String description;
@NotEmpty( message = "endppointAddress must not be empty" )
private String endpointAddress;
private String documentation;

private final Idm idm = new Idm();

/**
Expand All @@ -55,6 +60,7 @@ public static class Idm {
*/
@NotEmpty( message = "bpnId claimName must not be empty" )
private String bpnIdClaimName;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
@EnableConfigurationProperties( DiscoveryFinderClientProperties.class )
public class DiscoveryFinderClientConfiguration {

@Bean
WebClient webClient( OAuth2AuthorizedClientManager auth2AuthorizedClientManager, DiscoveryFinderClientProperties discoveryFinderProperties ) {

ServletOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( auth2AuthorizedClientManager );
oauth.setDefaultClientRegistrationId( "discoveryfinder-client" );
return WebClient.builder().baseUrl( discoveryFinderProperties.getBaseUrl() ).apply( oauth.oauth2Configuration() ).build();
}

@Bean
OAuth2AuthorizedClientManager auth2AuthorizedClientManager( ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientService oAuth2AuthorizedClientService ) {

OAuth2AuthorizedClientProvider auth2AuthorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
.authorizationCode().refreshToken().clientCredentials().build();

AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager =
new AuthorizedClientServiceOAuth2AuthorizedClientManager( clientRegistrationRepository, oAuth2AuthorizedClientService );

authorizedClientManager.setAuthorizedClientProvider( auth2AuthorizedClientProvider );

return authorizedClientManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import jakarta.validation.constraints.NotEmpty;
import lombok.Data;

@Data
@Validated
@ConfigurationProperties( prefix = "discoveryfinder-client" )
public class DiscoveryFinderClientProperties {
@NotEmpty( message = "baseUrl must not be empty" )
private String baseUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery.dto.discoveryfinder;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class DiscoveryEndpoint {

@JsonProperty( "type" )
private String type;

@JsonProperty( "description" )
private String description;

@JsonProperty( "endpointAddress" )
private String endpointAddress;

@JsonProperty( "documentation" )
private String documentation;

@JsonProperty( "resourceId" )
private String resourceId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery.dto.discoveryfinder;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DiscoveryEndpointCollection {

@JsonProperty( "endpoints" )
private List<DiscoveryEndpoint> endpoints;

public DiscoveryEndpointCollection addEndpointsItem( DiscoveryEndpoint endpointsItem ) {
if ( this.endpoints == null ) {
this.endpoints = new ArrayList<>();
}
this.endpoints.add( endpointsItem );
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/********************************************************************************
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.bpndiscovery.dto.discoveryfinder;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

import jakarta.validation.Valid;

public class SearchRequest {

@JsonProperty( "types" )
@Valid
private List<String> types = new ArrayList<>();

public SearchRequest types( List<String> types ) {
this.types = types;
return this;
}

public SearchRequest addTypesItem( String typesItem ) {
this.types.add( typesItem );
return this;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.eclipse.tractusx.bpndiscovery.model.BpnDiscovery;
import org.eclipse.tractusx.bpndiscovery.repository.BpnDiscoveryRepository;
import org.eclipse.tractusx.bpndiscovery.security.ClientAware;
import org.eclipse.tractusx.bpndiscovery.service.exception.EntityNotFoundException;
import org.eclipse.tractusx.bpndiscovery.service.exception.ValidationException;
import org.eclipse.tractusx.bpndiscovery.service.utils.UuidUtils;
import org.eclipse.tractusx.bpndiscovery.service.validator.BpnDiscoveryValidator;
import org.springframework.dao.DuplicateKeyException;
Expand Down
Loading

0 comments on commit 8eaf73c

Please sign in to comment.