added cors config
This commit is contained in:
@@ -4,8 +4,11 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@ComponentScan(basePackages = {"net.gepafin.tendermanagement"})
|
@ComponentScan(basePackages = {"net.gepafin.tendermanagement"})
|
||||||
@@ -19,5 +22,16 @@ public class TendermanagementApplication {
|
|||||||
System.out.println("Spring Boot started");
|
System.out.println("Spring Boot started");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
|
||||||
|
registry.addMapping("/**").allowedOrigins("http://localhost:3000")
|
||||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||||
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
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.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
@@ -32,6 +33,7 @@ import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
|
@EnableMethodSecurity(prePostEnabled = true)
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
private final TokenProvider tokenProvider;
|
private final TokenProvider tokenProvider;
|
||||||
|
|||||||
@@ -51,22 +51,23 @@ public class CallDao {
|
|||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
public CreateCallResponseBean createCall(CreateCallRequest createCallRequest, Long userId) {
|
public CreateCallResponseBean createCall(CreateCallRequest createCallRequest, Long userId) {
|
||||||
try {
|
CreateCallResponseBean createCallResponseBean = null;
|
||||||
CreateCallResponseBean createCallResponseBean=null;
|
|
||||||
CallEntity callEntity = convertToCallEntity(createCallRequest);
|
CallEntity callEntity = convertToCallEntity(createCallRequest);
|
||||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = convertToEvaluationCriteriaEntities(createCallRequest.getCriteria(), callEntity);
|
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = convertToEvaluationCriteriaEntities(
|
||||||
|
createCallRequest.getCriteria(), callEntity);
|
||||||
List<DocumentEntity> documentEntities = convertToDocumentEntities(createCallRequest.getDocs(), callEntity);
|
List<DocumentEntity> documentEntities = convertToDocumentEntities(createCallRequest.getDocs(), callEntity);
|
||||||
List<DocumentEntity> imageEntities=convertToDocumentEntities(createCallRequest.getImages(),callEntity);
|
List<DocumentEntity> imageEntities = convertToDocumentEntities(createCallRequest.getImages(), callEntity);
|
||||||
List<FaqEntity> faqEntities = convertToFaqEntities(createCallRequest.getFaq(), callEntity, userId);
|
List<FaqEntity> faqEntities = convertToFaqEntities(createCallRequest.getFaq(), callEntity, userId);
|
||||||
List<LookUpDataResponse> amiedTo=convertLookUpDataEntities(createCallRequest.getAimedTo(),callEntity,LookUpDataTypeEnum.AIMED_TO);
|
List<LookUpDataResponse> amiedTo = convertLookUpDataEntities(createCallRequest.getAimedTo(), callEntity,
|
||||||
List<LookUpDataResponse> checkList=convertLookUpDataEntities(createCallRequest.getAimedTo(),callEntity,LookUpDataTypeEnum.CHECKLIST);
|
LookUpDataTypeEnum.AIMED_TO);
|
||||||
createCallResponseBean= assembleCreateCallResponseBean(callEntity, evaluationCriteriaEntities, documentEntities, faqEntities,imageEntities);
|
List<LookUpDataResponse> checkList = convertLookUpDataEntities(createCallRequest.getAimedTo(), callEntity,
|
||||||
|
LookUpDataTypeEnum.CHECKLIST);
|
||||||
|
createCallResponseBean = assembleCreateCallResponseBean(callEntity, evaluationCriteriaEntities,
|
||||||
|
documentEntities, faqEntities, imageEntities);
|
||||||
createCallResponseBean.setAimedTo(amiedTo);
|
createCallResponseBean.setAimedTo(amiedTo);
|
||||||
createCallResponseBean.setCheckList(checkList);
|
createCallResponseBean.setCheckList(checkList);
|
||||||
return createCallResponseBean;
|
return createCallResponseBean;
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Error processing create call request", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import net.gepafin.tendermanagement.model.util.Response;
|
|||||||
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ public interface CallApi {
|
|||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||||
})
|
})
|
||||||
@PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
@PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
@PreAuthorize("hasRole('SUPER_ADMIN')")
|
||||||
public ResponseEntity<Response<CreateCallResponseBean>> createCall(HttpServletRequest request,
|
public ResponseEntity<Response<CreateCallResponseBean>> createCall(HttpServletRequest request,
|
||||||
@Parameter(description = "Call request object", required = true)
|
@Parameter(description = "Call request object", required = true)
|
||||||
@Valid @RequestBody CreateCallRequest createCallRequest);
|
@Valid @RequestBody CreateCallRequest createCallRequest);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
@Validated
|
@Validated
|
||||||
public interface RoleApi {
|
public interface RoleApi {
|
||||||
|
|
||||||
@Operation(summary = "API to create role",
|
@Operation(summary = "Api to create role",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@@ -36,7 +36,7 @@ public interface RoleApi {
|
|||||||
@Parameter(description = " Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
@Parameter(description = " Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "API to update role",
|
@Operation(summary = "Api to update role",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@@ -51,7 +51,7 @@ public interface RoleApi {
|
|||||||
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId,
|
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId,
|
||||||
@Parameter(description = "Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
@Parameter(description = "Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
||||||
|
|
||||||
@Operation(summary = "API to get role by id",
|
@Operation(summary = "Api to get role by id",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@@ -65,7 +65,7 @@ public interface RoleApi {
|
|||||||
ResponseEntity<Response<RoleEntity>> getRoleById(
|
ResponseEntity<Response<RoleEntity>> getRoleById(
|
||||||
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
|
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
|
||||||
|
|
||||||
@Operation(summary = "API to get all roles",
|
@Operation(summary = "Api to get all roles",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@@ -78,7 +78,7 @@ public interface RoleApi {
|
|||||||
produces = { "application/json" })
|
produces = { "application/json" })
|
||||||
ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles();
|
ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles();
|
||||||
|
|
||||||
@Operation(summary = "API to delete role",
|
@Operation(summary = "Api to delete role",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.validation.FieldError;
|
import org.springframework.validation.FieldError;
|
||||||
import org.springframework.validation.ObjectError;
|
import org.springframework.validation.ObjectError;
|
||||||
@@ -59,7 +60,7 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
|
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
|
||||||
@ExceptionHandler(UnauthorizedAccessException.class)
|
@ExceptionHandler({ UnauthorizedAccessException.class, AuthorizationDeniedException.class })
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Response<Object> unauthorizedAccessException(final Throwable ex) {
|
public Response<Object> unauthorizedAccessException(final Throwable ex) {
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user