Compare commits
13 Commits
master
...
spring-boo
Author | SHA1 | Date |
---|---|---|
Konstantinos Triantafyllou | 5417b6de55 | |
Konstantinos Triantafyllou | 6c935ca338 | |
Konstantinos Triantafyllou | 91f512b1e2 | |
Konstantinos Triantafyllou | 5965836486 | |
Konstantinos Triantafyllou | 524aecc002 | |
Konstantinos Triantafyllou | c234130264 | |
Konstantinos Triantafyllou | c79cfe9036 | |
Konstantinos Triantafyllou | 0b8a8c8d19 | |
Konstantinos Triantafyllou | 102dd91032 | |
Konstantinos Triantafyllou | 65aafd85ff | |
Konstantinos Triantafyllou | cefc9c31af | |
Konstantinos Triantafyllou | 544dceb7f8 | |
Konstantinos Triantafyllou | f9e1d1c5f1 |
18
README.md
18
README.md
|
@ -1,2 +1,20 @@
|
|||
# Developers API
|
||||
|
||||
API Registration through AAI API, Personal information and Login with offline_access (Refresh Token).
|
||||
|
||||
## Configuration
|
||||
|
||||
Check first [Login-core](https://code-repo.d4science.org/MaDgIK/uoa-login-core/) (offline_access)
|
||||
|
||||
### Datasource configuration
|
||||
|
||||
developers.datasource.url # Required - jdbc URL to the database
|
||||
developers.datasource.username # Optional - Database user if needed
|
||||
developers.datasource.password # Optional - Database user password if needed
|
||||
|
||||
### AAI Issuer
|
||||
developers.issuer # Required - SQL Driver - Default: org.postgresql.Driver
|
||||
|
||||
## Run
|
||||
|
||||
Check [Spring boot Documentation](https://code-repo.d4science.org/MaDgIK/Documentation/wiki/Spring-boot) (need Login)
|
||||
|
|
44
pom.xml
44
pom.xml
|
@ -4,10 +4,10 @@
|
|||
<parent>
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>uoa-spring-boot-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>2.0.3</version>
|
||||
</parent>
|
||||
<artifactId>developers-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>developers-api</name>
|
||||
<scm>
|
||||
|
@ -24,25 +24,13 @@
|
|||
<dependency>
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>uoa-login-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<!--swagger-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger-version}</version>
|
||||
</dependency>
|
||||
<!--swagger official ui-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger-version}</version>
|
||||
<version>3.0.8</version>
|
||||
</dependency>
|
||||
<!-- PostgresSQL -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.4.1211.jre7</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -52,38 +40,26 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
<configuration>
|
||||
<mainClass>eu.dnetlib.developers.DevelopersAPIApplication</mainClass>
|
||||
<executable>true</executable>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>developers-api</finalName>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package eu.dnetlib.developers;
|
||||
|
||||
import eu.dnetlib.authentication.configuration.AuthenticationConfiguration;
|
||||
import eu.dnetlib.developers.configuration.APIProperties;
|
||||
import eu.dnetlib.developers.configuration.GlobalVars;
|
||||
import eu.dnetlib.developers.configuration.Properties;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -14,11 +13,12 @@ import org.springframework.context.annotation.PropertySources;
|
|||
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.developers"})
|
||||
@PropertySources({
|
||||
@PropertySource("classpath:authentication.properties"),
|
||||
@PropertySource("classpath:authorization.properties"),
|
||||
@PropertySource("classpath:developers.properties"),
|
||||
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
||||
})
|
||||
@Import({AuthenticationConfiguration.class})
|
||||
@EnableConfigurationProperties({Properties.class, APIProperties.class, GlobalVars.class})
|
||||
@EnableConfigurationProperties({Properties.class, GlobalVars.class})
|
||||
public class DevelopersAPIApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.dnetlib.developers;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package eu.dnetlib.developers.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("api")
|
||||
public class APIProperties {
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
private String version;
|
||||
|
||||
public APIProperties() {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package eu.dnetlib.developers.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
@ -19,11 +20,9 @@ public class DataSourceConfig {
|
|||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(this.datasource.getDriver());
|
||||
dataSource.setUrl(this.datasource.getUrl());
|
||||
dataSource.setUsername(this.datasource.getUsername());
|
||||
dataSource.setPassword(this.datasource.getPassword());
|
||||
return dataSource;
|
||||
return DataSourceBuilder.create()
|
||||
.url(this.datasource.getUrl())
|
||||
.username(this.datasource.getUsername())
|
||||
.password(this.datasource.getPassword()).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package eu.dnetlib.developers.configuration;
|
||||
|
||||
public class Datasource {
|
||||
private String driver;
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
|
@ -9,14 +8,6 @@ public class Datasource {
|
|||
public Datasource() {
|
||||
}
|
||||
|
||||
public String getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public void setDriver(String driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
@ConfigurationProperties("developers-api.globalVars")
|
||||
@ConfigurationProperties("developers-api.global-vars")
|
||||
public class GlobalVars {
|
||||
public static Date date = new Date();
|
||||
private Date buildDate;
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
package eu.dnetlib.developers.configuration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* Swagger configuration class
|
||||
*/
|
||||
@Configuration
|
||||
@Profile({"swagger"})
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
private final APIProperties apiProperties;
|
||||
|
||||
@Autowired
|
||||
public SwaggerConfig(APIProperties apiProperties) {
|
||||
this.apiProperties = apiProperties;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.developers.controllers"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiLoginCore() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.groupName("Login Core")
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.authentication.controllers"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(this.apiProperties.getTitle())
|
||||
.description(this.apiProperties.getDescription())
|
||||
.version(this.apiProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs");
|
||||
registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
|
||||
registry.addRedirectViewController("/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
|
||||
registry.addRedirectViewController("/swagger-resources", "/swagger-resources");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,10 +14,7 @@ import java.util.List;
|
|||
|
||||
@RestController()
|
||||
@RequestMapping("/apis")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class APIController {
|
||||
|
||||
@Autowired
|
||||
private APIService service;
|
||||
|
||||
@Autowired
|
||||
|
@ -37,20 +34,19 @@ public class APIController {
|
|||
return ResponseEntity.ok(this.service.copyServices(services));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @AuthorizationService.hasPersonalInfo()")
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @PermissionService.hasPersonalInfo()")
|
||||
@RequestMapping(value = "/my-services", method = RequestMethod.GET)
|
||||
public ResponseEntity<List<API>> getMyServices() {
|
||||
return ResponseEntity.ok(this.service.getMyServices());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @AuthorizationService.hasPersonalInfo()")
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @PermissionService.hasPersonalInfo()")
|
||||
@RequestMapping(value = "/save/new", method = RequestMethod.POST)
|
||||
public ResponseEntity<API> create(@RequestBody ServiceForm form) {
|
||||
return ResponseEntity.ok(this.service.save(form));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @AuthorizationService.hasPersonalInfo() && @AuthorizationService.isMyService(#id)")
|
||||
@PreAuthorize("hasAnyAuthority('REGISTERED_USER') && @PermissionService.hasPersonalInfo() && @PermissionService.isMyService(#id)")
|
||||
@RequestMapping(value = "/save/{id}", method = RequestMethod.POST)
|
||||
public ResponseEntity<API> update(@PathVariable Long id, @RequestBody ServiceForm form) {
|
||||
return ResponseEntity.ok(this.service.save(form, id));
|
||||
|
|
|
@ -1,54 +1,36 @@
|
|||
package eu.dnetlib.developers.controllers;
|
||||
|
||||
import eu.dnetlib.developers.configuration.GlobalVars;
|
||||
import eu.dnetlib.developers.configuration.Properties;
|
||||
import eu.dnetlib.developers.services.DeployService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class HealthController {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
private final Properties properties;
|
||||
private final GlobalVars globalVars;
|
||||
private final DeployService deployService;
|
||||
|
||||
@Autowired
|
||||
public HealthController(Properties properties, GlobalVars globalVars) {
|
||||
this.properties = properties;
|
||||
this.globalVars = globalVars;
|
||||
public HealthController(DeployService deployService) {
|
||||
this.deployService = deployService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
||||
public String hello() {
|
||||
@RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET)
|
||||
public ResponseEntity<String> hello() {
|
||||
log.debug("Hello from Developers API service!");
|
||||
return "Hello from Developers API service!";
|
||||
return ResponseEntity.ok("Hello from Developers API service!");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('PORTAL_ADMINISTRATOR')")
|
||||
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||
public Map<String, String> checkEverything() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("developers.datasource.driver", properties.getDatasource().getDriver());
|
||||
response.put("developers.datasource.url", properties.getDatasource().getUrl());
|
||||
response.put("developers.datasource.username", properties.getDatasource().getUsername());
|
||||
response.put("developers.datasource.password", properties.getDatasource().getPassword());
|
||||
response.put("developers.issuer", properties.getIssuer());
|
||||
if(GlobalVars.date != null) {
|
||||
response.put("Date of deploy", eu.dnetlib.authentication.configuration.GlobalVars.date.toString());
|
||||
}
|
||||
if(globalVars.getBuildDate() != null) {
|
||||
response.put("Date of build", globalVars.getBuildDate());
|
||||
}
|
||||
if (globalVars.getVersion() != null) {
|
||||
response.put("Version", globalVars.getVersion());
|
||||
}
|
||||
return response;
|
||||
public ResponseEntity<Map<String, String>> checkEverything() {
|
||||
return ResponseEntity.ok(this.deployService.getProperties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.List;
|
|||
|
||||
@RestController()
|
||||
@RequestMapping("/personal/")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class PersonalInfoController {
|
||||
|
||||
PersonalInfoService service;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.dnetlib.developers.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class PersonalInfo {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package eu.dnetlib.developers.entities;
|
||||
|
||||
import eu.dnetlib.developers.dto.ServiceForm;
|
||||
import eu.dnetlib.developers.dto.ServiceRequest;
|
||||
import eu.dnetlib.developers.dto.ServiceResponse;
|
||||
import eu.dnetlib.developers.utils.StringListConverter;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package eu.dnetlib.developers.exceptions;
|
||||
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.HttpException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
public class EntityMissingException extends RuntimeException {
|
||||
public EntityMissingException(String message){
|
||||
super(message);
|
||||
public class EntityMissingException extends HttpException {
|
||||
public EntityMissingException(String message) {
|
||||
super(message, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package eu.dnetlib.developers.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public class EntityNotFoundException extends RuntimeException {
|
||||
public EntityNotFoundException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package eu.dnetlib.developers.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
public class ForbiddenException extends RuntimeException {
|
||||
public ForbiddenException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,12 @@
|
|||
package eu.dnetlib.developers.repositories;
|
||||
|
||||
import eu.dnetlib.developers.entities.PersonalInfo;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PersonalInfoDAO extends CrudRepository<PersonalInfo, Long> {
|
||||
|
||||
List<PersonalInfo> findAll();
|
||||
|
||||
PersonalInfo saveAndFlush(PersonalInfo personalInfo);
|
||||
|
||||
public interface PersonalInfoDAO extends JpaRepository<PersonalInfo, Long> {
|
||||
Optional<PersonalInfo> findById(String id);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package eu.dnetlib.developers.repositories;
|
||||
|
||||
import eu.dnetlib.developers.entities.RegisteredService;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -10,18 +10,10 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface RegisteredServiceDAO extends CrudRepository<RegisteredService, Long> {
|
||||
|
||||
List<RegisteredService> findAll();
|
||||
|
||||
public interface RegisteredServiceDAO extends JpaRepository<RegisteredService, Long> {
|
||||
@Query("select distinct rs.issuer from RegisteredService rs where rs.issuer != :#{#issuer}")
|
||||
List<String> findAllIssuersExceptActive(@Param("issuer") String issuer);
|
||||
|
||||
Optional<RegisteredService> findById(Long id);
|
||||
|
||||
Optional<RegisteredService> findByClientIdAndIssuer(String clientId, String issuer);
|
||||
|
||||
List<RegisteredService> findAllByIssuerOrderByOwnerAsc(String issuer);
|
||||
|
||||
List<RegisteredService> findAllByOwnerAndIssuerOrderByCreationDateAsc(String owner, String issuer);
|
||||
}
|
||||
|
|
|
@ -6,17 +6,18 @@ import eu.dnetlib.developers.configuration.Properties;
|
|||
import eu.dnetlib.developers.dto.*;
|
||||
import eu.dnetlib.developers.entities.RegisteredService;
|
||||
import eu.dnetlib.developers.exceptions.EntityMissingException;
|
||||
import eu.dnetlib.developers.exceptions.EntityNotFoundException;
|
||||
import eu.dnetlib.developers.exceptions.ForbiddenException;
|
||||
import eu.dnetlib.developers.repositories.RegisteredServiceDAO;
|
||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.ForbiddenException;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.security.AuthorizationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service()
|
||||
|
@ -25,12 +26,14 @@ public class APIService {
|
|||
private final RegisteredServiceDAO dao;
|
||||
private final RestTemplate template;
|
||||
private final String issuer;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public APIService(RegisteredServiceDAO dao, RestTemplate template, Properties properties) {
|
||||
public APIService(RegisteredServiceDAO dao, RestTemplate template, Properties properties, AuthorizationService authorizationService) {
|
||||
this.dao = dao;
|
||||
this.template = template;
|
||||
this.issuer = properties.getIssuer();
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
public List<APIsByIssuer> getAll() {
|
||||
|
@ -51,8 +54,7 @@ public class APIService {
|
|||
}
|
||||
|
||||
public List<API> getMyServices() {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
return this.dao.findAllByOwnerAndIssuerOrderByCreationDateAsc(authentication.getSub(), this.issuer).stream().map(service -> {
|
||||
return this.dao.findAllByOwnerAndIssuerOrderByCreationDateAsc(this.authorizationService.getAaiId(), this.issuer).stream().map(service -> {
|
||||
API api = new API();
|
||||
api.setService(service);
|
||||
api.setDetails(this.readService(service.getClientId(), service.getRegistrationAccessToken()));
|
||||
|
@ -84,16 +86,15 @@ public class APIService {
|
|||
public API save(ServiceForm form, Long id) {
|
||||
ServiceRequest request;
|
||||
API api = new API();
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
if (id != null) {
|
||||
RegisteredService service = this.dao.findById(id).orElse(null);
|
||||
if (service == null) {
|
||||
throw new EntityNotFoundException("Service with id " + id + " does not exist.");
|
||||
throw new NotFoundException("Service with id " + id + " does not exist.");
|
||||
}
|
||||
api.setService(service);
|
||||
api.setDetails(readService(service.getClientId(), service.getRegistrationAccessToken()));
|
||||
} else {
|
||||
api.setService(new RegisteredService(authentication.getSub(), issuer));
|
||||
api.setService(new RegisteredService(this.authorizationService.getAaiId(), issuer));
|
||||
}
|
||||
String keyType = form.getKeyType();
|
||||
if (keyType != null && keyType.equals("uri")) {
|
||||
|
@ -106,7 +107,7 @@ public class APIService {
|
|||
String jwksSet = String.format("{\"keys\":[%s]}", form.getValue());
|
||||
form.setJwks(gson.fromJson(jwksSet, Jwks.class));
|
||||
if (!form.getJwks().isValid()) {
|
||||
throw new EntityMissingException("Jwks value is not valid");
|
||||
throw new NotFoundException("Jwks value is not valid");
|
||||
}
|
||||
request = ServiceRequest.createServiceRequest(api.getService().getClientId(), form.getName(), form.getLogoURL(), form.getContacts(), form.getJwks());
|
||||
} else {
|
||||
|
@ -116,7 +117,7 @@ public class APIService {
|
|||
if (api.getService().getClientId() != null) {
|
||||
response = this.updateService(api.getService().getClientId(), request, api.getService().getRegistrationAccessToken());
|
||||
} else {
|
||||
if (this.dao.findAllByOwnerAndIssuerOrderByCreationDateAsc(authentication.getSub(), issuer).size() < 5) {
|
||||
if (this.dao.findAllByOwnerAndIssuerOrderByCreationDateAsc(this.authorizationService.getAaiId(), issuer).size() < 5) {
|
||||
response = this.createService(request);
|
||||
} else {
|
||||
throw new ForbiddenException("You are not allowed to own more than 5 services.");
|
||||
|
@ -135,12 +136,12 @@ public class APIService {
|
|||
public void delete(Long id) {
|
||||
RegisteredService service = this.dao.findById(id).orElse(null);
|
||||
if (service == null) {
|
||||
throw new EntityNotFoundException("Service with id " + id + " does not exist.");
|
||||
throw new NotFoundException("Service with id " + id + " does not exist.");
|
||||
} else {
|
||||
if(readService(service.getClientId(), service.getRegistrationAccessToken()) != null) {
|
||||
this.deleteService(service.getClientId(), service.getRegistrationAccessToken());
|
||||
}
|
||||
this.dao.delete(id);
|
||||
this.dao.delete(service);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +153,6 @@ public class APIService {
|
|||
ResponseEntity<String> response = template.exchange(this.issuer, HttpMethod.POST, requestEntity, String.class);
|
||||
return ServiceResponse.fromString(response.getBody());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new EntityMissingException("Register of this service couldn't be completed. Check again your parameters");
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,6 @@ public class APIService {
|
|||
ResponseEntity<String> response = template.exchange(this.issuer + "/" + clientId, HttpMethod.PUT, requestEntity, String.class);
|
||||
return ServiceResponse.fromString(response.getBody());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new EntityMissingException("Update of service with client id: " + clientId + " couldn't be completed. Check again your parameters");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package eu.dnetlib.developers.services;
|
||||
|
||||
import eu.dnetlib.developers.configuration.GlobalVars;
|
||||
import eu.dnetlib.developers.configuration.Properties;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DeployService {
|
||||
private final Properties properties;
|
||||
private final GlobalVars globalVars;
|
||||
|
||||
@Autowired
|
||||
public DeployService(Properties properties, GlobalVars globalVars) {
|
||||
this.properties = properties;
|
||||
this.globalVars = globalVars;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void checkProperties() {
|
||||
if (properties.getDatasource().getUrl() == null || properties.getDatasource().getUrl().isEmpty()) {
|
||||
throw new RuntimeException("developers.datasource.url is missing!");
|
||||
} else if (properties.getIssuer() == null || properties.getIssuer().isEmpty()) {
|
||||
throw new RuntimeException("developers.issuer is missing!");
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("developers.datasource.url", properties.getDatasource().getUrl());
|
||||
response.put("developers.datasource.username", properties.getDatasource().getUsername());
|
||||
response.put("developers.datasource.password", properties.getDatasource().getPassword());
|
||||
response.put("developers.issuer", properties.getIssuer());
|
||||
|
||||
response.put("Date of deploy", GlobalVars.date.toString());
|
||||
if (globalVars.getBuildDate() != null) {
|
||||
response.put("Date of build", globalVars.getBuildDate());
|
||||
}
|
||||
if (globalVars.getVersion() != null) {
|
||||
response.put("Version", globalVars.getVersion());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -3,31 +3,30 @@ package eu.dnetlib.developers.services;
|
|||
import eu.dnetlib.developers.entities.RegisteredService;
|
||||
import eu.dnetlib.developers.repositories.PersonalInfoDAO;
|
||||
import eu.dnetlib.developers.repositories.RegisteredServiceDAO;
|
||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.security.AuthorizationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("AuthorizationService")
|
||||
public class AuthorizationService {
|
||||
@Component("PermissionService")
|
||||
public class PermissionService {
|
||||
|
||||
private final RegisteredServiceDAO registeredServiceDAO;
|
||||
private final PersonalInfoDAO personalInfoDAO;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public AuthorizationService(RegisteredServiceDAO registeredServiceDAO, PersonalInfoDAO personalInfoDAO) {
|
||||
public PermissionService(RegisteredServiceDAO registeredServiceDAO, PersonalInfoDAO personalInfoDAO, AuthorizationService authorizationService) {
|
||||
this.registeredServiceDAO = registeredServiceDAO;
|
||||
this.personalInfoDAO = personalInfoDAO;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
public boolean isMyService(Long id) {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
RegisteredService service = this.registeredServiceDAO.findById(id).orElse(null);
|
||||
return service != null && service.getOwner().equals(authentication.getSub());
|
||||
return service != null && service.getOwner().equals(this.authorizationService.getAaiId());
|
||||
}
|
||||
|
||||
public boolean hasPersonalInfo() {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
return this.personalInfoDAO.findById(authentication.getSub()).orElseThrow(null) != null;
|
||||
return this.personalInfoDAO.findById(this.authorizationService.getAaiId()).orElseThrow(null) != null;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package eu.dnetlib.developers.services;
|
||||
|
||||
import eu.dnetlib.developers.entities.PersonalInfo;
|
||||
import eu.dnetlib.developers.exceptions.EntityNotFoundException;
|
||||
import eu.dnetlib.developers.repositories.PersonalInfoDAO;
|
||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.authorization.security.AuthorizationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,11 +12,13 @@ import java.util.List;
|
|||
@Service()
|
||||
public class PersonalInfoService {
|
||||
|
||||
private PersonalInfoDAO dao;
|
||||
private final PersonalInfoDAO dao;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public PersonalInfoService(PersonalInfoDAO dao) {
|
||||
public PersonalInfoService(PersonalInfoDAO dao, AuthorizationService authorizationService) {
|
||||
this.dao = dao;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
public List<PersonalInfo> getAll() {
|
||||
|
@ -29,13 +30,11 @@ public class PersonalInfoService {
|
|||
}
|
||||
|
||||
public PersonalInfo getPersonalInfo() {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
return this.dao.findById(authentication.getSub()).orElseThrow( () -> new EntityNotFoundException("Personal Info of user with id " + authentication.getSub() + " has not been found"));
|
||||
return this.dao.findById(this.authorizationService.getAaiId()).orElseThrow( () -> new NotFoundException("Personal Info of user with id " + this.authorizationService.getAaiId() + " has not been found"));
|
||||
}
|
||||
|
||||
public PersonalInfo savePersonalInfo(PersonalInfo personalInfo) {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
personalInfo.setId(authentication.getSub());
|
||||
personalInfo.setId(this.authorizationService.getAaiId());
|
||||
return this.dao.saveAndFlush(personalInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package eu.dnetlib.developers.utils;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
import javax.persistence.Converter;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
developers.datasource.driver=org.postgresql.Driver
|
||||
developers.datasource.url=jdbc:postgresql://dl170.madgik.di.uoa.gr:5432/usersdb
|
||||
developers.datasource.username=username
|
||||
developers.datasource.password=pass
|
||||
developers.issuer=issuer
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
|
||||
## API Documentation Properties
|
||||
api.title = Developers API
|
||||
api.description = Developers API includes authentication methods and provides functionalities to manage OpenAIRE Dynamic AAI APIs.
|
||||
|
|
Loading…
Reference in New Issue