Skip to content

task completed #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
80 changes: 80 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,86 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.4</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;



@Configuration
@SpringBootApplication
@ComponentScan(basePackages = "com.accenture.codingtest.springbootcodingtest")

public class SpringBootCodingTestApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootCodingTestApplication.class, args);
System.out.println("****************BOOOOOOOOOOOOOOTED*******************");
}

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

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
UserDetailsService userDetailsService;

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

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().antMatchers("/v1/**","/swagger-resources/configuration/ui", "/swagger-resources",
"/swagger-ui.html", "/webjars/**")
.permitAll()
.antMatchers("/v1/User/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/v1/Task/**", "/v1/Project/**").access("hasRole('ROLE_PROJECT_OWNER')")

.anyRequest().authenticated().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);

}

@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();

}

@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManager();

}

CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedOrigin("");
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}


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

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {


public static final String AUTHORIZATION_HEADER= "Authorization";

private ApiKey apiKeys() {

return new ApiKey ("Jwt",AUTHORIZATION_HEADER ,"header");

}

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}






}


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.accenture.codingtest.springbootcodingtest.constant;

import org.springframework.stereotype.Component;

@Component
public class RoleConstants {

public static final String DEFAULT_ROLE = "ROLE_USER";
public static final String[] ADMIN_ACCESS = {"ROLE_ADMIN" ,"ROLE_PRODUCT_OWNER"};
public static final String[] PRODUCT_OWNER_ACCESS = {"ROLE_PRODUCT_OWNER"};

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

public class TaskStatus {


public static final String[] TaskStatus = {"NOT_STARTED","IN_PROGRESS","READY_FOR_TEST","COMPLETED"};

public static final String NOT_STARTED = "NOT_STARTED";

public static final String IN_PROGRESS = "IN_PROGRESS";

public static final String READY_FOR_TEST = "READY_FOR_TEST";

public static final String COMPLETED = "COMPLETED";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.accenture.codingtest.springbootcodingtest.filter.JwtUtil;
import com.accenture.codingtest.springbootcodingtest.model.JwtRequestModel;
import com.accenture.codingtest.springbootcodingtest.model.JwtResponseModel;
import com.accenture.codingtest.springbootcodingtest.model.TaskModel;
import com.accenture.codingtest.springbootcodingtest.service.GroupUserDetailsService;

@RestController
public class JwtController {

@Autowired
private JwtUtil jwtUtil;

@Autowired
private GroupUserDetailsService groupUserDetailsService;

@Autowired
private AuthenticationManager authenticationManager;

@PostMapping(value = "/Token/GenerateToken")
public ResponseEntity<?> GenerateToken(@RequestBody JwtRequestModel jwtRequestM) throws Exception {
try {

this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(jwtRequestM.getUsername(), jwtRequestM.getPassword()));

}catch(UsernameNotFoundException e)
{
e.printStackTrace();
throw new Exception("Bad Credentials");
}
//fine area
UserDetails userDetails = this.groupUserDetailsService.loadUserByUsername(jwtRequestM.getUsername());

String token = jwtUtil.generateToken(jwtRequestM.getUsername());
System.out.println(token);


return ResponseEntity.ok( new JwtResponseModel(token));
// }


}

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

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.accenture.codingtest.springbootcodingtest.model.ProjectModel;
import com.accenture.codingtest.springbootcodingtest.service.ProjectService;

@RestController
@RequestMapping("/v1")
@SuppressWarnings("rawtypes")
public class ProjectController {

@Autowired
ProjectService projectService;


@PostMapping(value = "/Project/Project")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
@Secured("ROLE_PRODUCT_OWNER")
public ResponseEntity<ProjectModel> project(@RequestBody ProjectModel projectModel) throws Exception {
ProjectModel projectModel1 = projectService.project(projectModel);
return new ResponseEntity<>(projectModel1, HttpStatus.CREATED);
}

@PutMapping(value = "/Project/updateProjectIdempotent")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
@Secured("ROLE_PRODUCT_OWNER")
public ResponseEntity<String> updateProjectIdempotent(@PathVariable UUID id) throws Exception{
ProjectModel projectModel = projectService.getProjectById(id);
return new ResponseEntity<>(projectService.updateProjectIdempotent(projectModel), HttpStatus.OK);
}

@PatchMapping(value = "/Project/updateProject")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
@Secured("ROLE_PRODUCT_OWNER")
public ResponseEntity<String> updateProjects (@PathVariable UUID id) throws Exception{
ProjectModel projectModel = projectService.getProjectById(id);
return new ResponseEntity<>(projectService.updateProjects(projectModel,null), HttpStatus.OK);
}

@DeleteMapping(value = "/Project/DeleteProject")
public ResponseEntity<String> deleteProjectById (@PathVariable UUID id) throws Exception{
return new ResponseEntity<>(projectService.deleteProjectById(id), HttpStatus.OK);
}

@GetMapping(value = "/Project/GetProjectById")
public ResponseEntity<ProjectModel> getProjectById (@PathVariable UUID id) throws Exception{
return new ResponseEntity<>(projectService.getProjectById(id), HttpStatus.OK);
}

@GetMapping(value = "/Project/GetAllProjects")
public ResponseEntity<List<ProjectModel>> getAllProjects () throws Exception{
return new ResponseEntity<>(projectService.getAllProjects(), HttpStatus.OK);
}



}


Loading