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
109 changes: 74 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.accenture.codingtest</groupId>
<artifactId>spring-boot-coding-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-coding-test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.accenture.codingtest</groupId>
<artifactId>spring-boot-coding-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-coding-test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
</dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.accenture.codingtest.springbootcodingtest;

import org.modelmapper.ModelMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringBootCodingTestApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootCodingTestApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SpringBootCodingTestApplication.class, args);
}

@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.accenture.codingtest.springbootcodingtest.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;


@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;

@Bean
protected AuthenticationManager getAuthenticationManager() throws Exception {
return super.authenticationManager();
}

@Bean
PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("PATCH");
config.addAllowedMethod("DELETE");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}


@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());

}


@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().antMatchers("/v1/**")
.permitAll()
.antMatchers("/v1/User/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/v1/Task/**", "/v1/Project/**").access("hasRole('ROLE_PROJECT_OWNER')");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import com.accenture.codingtest.springbootcodingtest.model.ProjectDto;
import com.accenture.codingtest.springbootcodingtest.service.ProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.UUID;

@RestController
@RequestMapping("/api/v1/projects")
@RequiredArgsConstructor
public class ProjectController {
private final ProjectService projectService;

@GetMapping
public Collection<ProjectDto> findAll() {
return projectService.findAll();
}

@GetMapping("/{id}")
public ProjectDto findById(@PathVariable("id") String id) {
return projectService.findById(UUID.fromString(id));
}

@PostMapping("/")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
public ProjectDto create(@RequestBody ProjectDto projectDto) {
return projectService.create(projectDto);
}

@PutMapping("/{id}")
public ProjectDto update(@PathVariable("id") String id, @RequestBody ProjectDto projectDto) {
return projectService.update(UUID.fromString(id), projectDto);
}

@PatchMapping("/{id}")
public ProjectDto updatePartially(@PathVariable("id") String id, @RequestBody ProjectDto projectDto) {
return projectService.updatePartially(UUID.fromString(id), projectDto);
}

@DeleteMapping("/{id}")
public ResponseEntity deleteById(@PathVariable("id") String id) {
projectService.deleteById(UUID.fromString(id));
return ResponseEntity.ok().build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import com.accenture.codingtest.springbootcodingtest.model.TaskDto;
import com.accenture.codingtest.springbootcodingtest.service.TaskService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.UUID;

@RestController
@RequestMapping("/api/v1/tasks")
@RequiredArgsConstructor
public class TaskController {
private final TaskService taskService;

@GetMapping
public Collection<TaskDto> findAll() {
return taskService.findAll();
}

@GetMapping("/{id}")
public TaskDto findById(@PathVariable("id") String id) {
return taskService.findById(UUID.fromString(id));
}

@PostMapping("/")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
public TaskDto create(@RequestBody TaskDto taskDto) {
return taskService.create(taskDto);
}

@PutMapping("/{id}")
public TaskDto update(@PathVariable("id") String id, @RequestBody TaskDto taskDto) {
return taskService.update(UUID.fromString(id), taskDto);
}

@PatchMapping("/{id}")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
public TaskDto updatePartially(@PathVariable("id") String id, @RequestBody TaskDto taskDto) {
return taskService.updatePartially(UUID.fromString(id), taskDto);
}

@DeleteMapping("/{id}")
public ResponseEntity deleteById(@PathVariable("id") String id) {
taskService.deleteById(UUID.fromString(id));
return ResponseEntity.ok().build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import com.accenture.codingtest.springbootcodingtest.model.UserDto;
import com.accenture.codingtest.springbootcodingtest.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.UUID;

@RestController
@RequestMapping("/api/v1/users")
@RequiredArgsConstructor
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@Secured("ROLE_ADMIN")
public class UserController {
private final UserService userService;

@GetMapping
public Collection<UserDto> findAll() {
return userService.findAll();
}

@GetMapping("/{id}")
public UserDto findById(@PathVariable("id") String id) {
return userService.findById(UUID.fromString(id));
}

@PostMapping("/")
public UserDto create(@RequestBody UserDto userDto) {
return userService.create(userDto);
}

@PutMapping("/{id}")
public UserDto update(@PathVariable("id") String id, @RequestBody UserDto userDto) {
return userService.update(UUID.fromString(id), userDto);
}

@PatchMapping("/{id}")
public UserDto updatePartially(@PathVariable("id") String id, @RequestBody UserDto userDto) {
return userService.updatePartially(UUID.fromString(id), userDto);
}

@DeleteMapping("/{id}")
public ResponseEntity deleteById(@PathVariable("id") String id) {
userService.deleteById(UUID.fromString(id));
return ResponseEntity.ok().build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.accenture.codingtest.springbootcodingtest.entity;

import lombok.Data;

import javax.persistence.*;
import java.util.UUID;

@Entity
@Data
@Table
public class Project {
@Id
@GeneratedValue
private UUID id;
@Column(nullable = false)
private String name;
}
Loading