CORS changes to work with frontend application. Modified getThread method
This commit is contained in:
parent
bc27408b83
commit
e7737c5f9d
@ -24,7 +24,7 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
implementation 'com.auth0:java-jwt:3.4.0'
|
implementation 'com.auth0:java-jwt:3.4.0'
|
||||||
implementation 'org.openpnp:opencv:3.2.0-0'
|
// implementation name: 'opencv-420'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
testImplementation('org.junit.jupiter:junit-jupiter-api')
|
testImplementation('org.junit.jupiter:junit-jupiter-api')
|
||||||
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine')
|
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine')
|
||||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
|||||||
|
#Thu Feb 13 22:25:46 CET 2020
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@ -2,8 +2,8 @@ package pl.edu.amu.wmi.bookapi;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.*;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.crypto.bcrypt.*;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class BookapiApplication {
|
public class BookapiApplication {
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.api;
|
package pl.edu.amu.wmi.bookapi.api;
|
||||||
|
|
||||||
import org.apache.coyote.Response;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import pl.edu.amu.wmi.bookapi.api.dto.BookDto;
|
import pl.edu.amu.wmi.bookapi.api.dto.BookDto;
|
||||||
import pl.edu.amu.wmi.bookapi.service.BookService;
|
import pl.edu.amu.wmi.bookapi.service.BookService;
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package pl.edu.amu.wmi.bookapi.api;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
//@Component
|
||||||
|
//@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
public class CustomCorsFilter implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
|
||||||
|
|
||||||
|
HttpServletRequest request = (HttpServletRequest) req;
|
||||||
|
HttpServletResponse response = (HttpServletResponse) res;
|
||||||
|
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
||||||
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
||||||
|
response.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");
|
||||||
|
|
||||||
|
System.out.println(response.getHeaderNames());
|
||||||
|
chain.doFilter(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,12 @@ package pl.edu.amu.wmi.bookapi.api;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import pl.edu.amu.wmi.bookapi.api.dto.MessageDto;
|
import pl.edu.amu.wmi.bookapi.api.dto.MessageDto;
|
||||||
import pl.edu.amu.wmi.bookapi.service.MessageService;
|
import pl.edu.amu.wmi.bookapi.service.MessageService;
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.api;
|
package pl.edu.amu.wmi.bookapi.api;
|
||||||
|
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.crypto.bcrypt.*;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import pl.edu.amu.wmi.bookapi.exceptions.RegisterException;
|
import pl.edu.amu.wmi.bookapi.exceptions.RegisterException;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
import pl.edu.amu.wmi.bookapi.repositories.*;
|
import pl.edu.amu.wmi.bookapi.repositories.UserRepository;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
|
||||||
@ -26,17 +28,14 @@ public class UserController {
|
|||||||
|
|
||||||
@PostMapping("/sign-up")
|
@PostMapping("/sign-up")
|
||||||
public void signUp(@RequestBody UserDocument user) throws RegisterException {
|
public void signUp(@RequestBody UserDocument user) throws RegisterException {
|
||||||
|
System.out.println("Registering user");
|
||||||
|
System.out.println(user);
|
||||||
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
|
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
|
||||||
try {
|
try {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
System.out.println("hello");
|
|
||||||
} catch (DuplicateKeyException e) {
|
} catch (DuplicateKeyException e) {
|
||||||
throw new RegisterException("Login already in use");
|
throw new RegisterException("Login already in use");
|
||||||
}
|
}
|
||||||
}
|
System.out.println(userRepository.findAll());
|
||||||
|
|
||||||
@PostMapping("/sign-in")
|
|
||||||
public void signIn(@RequestBody UserDocument user) throws LoginException {
|
|
||||||
Object princ = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@ package pl.edu.amu.wmi.bookapi.config;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.time.Clock;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class DateTimeProvider {
|
public class DateTimeProvider {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.models;
|
package pl.edu.amu.wmi.bookapi.models;
|
||||||
|
|
||||||
import org.springframework.data.annotation.*;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.mongodb.core.index.Indexed;
|
import org.springframework.data.mongodb.core.index.Indexed;
|
||||||
import org.springframework.data.mongodb.core.mapping.*;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
public class UserDocument {
|
public class UserDocument {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.repositories;
|
package pl.edu.amu.wmi.bookapi.repositories;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import pl.edu.amu.wmi.bookapi.api.dto.BookDto;
|
|
||||||
import pl.edu.amu.wmi.bookapi.models.BookDocument;
|
import pl.edu.amu.wmi.bookapi.models.BookDocument;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.repositories;
|
package pl.edu.amu.wmi.bookapi.repositories;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import org.springframework.data.mongodb.repository.Query;
|
|
||||||
import pl.edu.amu.wmi.bookapi.models.ThreadDocument;
|
import pl.edu.amu.wmi.bookapi.models.ThreadDocument;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ThreadRepository extends MongoRepository<ThreadDocument, String>, ThreadRepositoryCustom {
|
public interface ThreadRepository extends MongoRepository<ThreadDocument, String>, ThreadRepositoryCustom {
|
||||||
// @Query("'participantsIds': { $in: [?0, ?1]}")
|
// @Query("'participantsIds': { $in: [?0, ?1]}")
|
||||||
// List<ThreadDocument> findByParticipants(String participantId1, String participantId2);
|
// List<ThreadDocument> findByParticipants(String participantId1, String participantId2);
|
||||||
@Query("{'participantsIds': {$in: [?0]}}")
|
// @Query("{'participantsIds': {$in: [?0]}}")
|
||||||
List<ThreadDocument> findByParticipant(String participant);
|
// List<ThreadDocument> findByParticipant(String participant);
|
||||||
}
|
}
|
@ -6,4 +6,5 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ThreadRepositoryCustom {
|
public interface ThreadRepositoryCustom {
|
||||||
List<ThreadDocument> findByParticipants(String participantId1, String participantId2);
|
List<ThreadDocument> findByParticipants(String participantId1, String participantId2);
|
||||||
|
List<ThreadDocument> findByParticipant(String participant);
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,14 @@ public class ThreadRepositoryCustomImpl implements ThreadRepositoryCustom {
|
|||||||
|
|
||||||
return mongoTemplate.find(query, ThreadDocument.class);
|
return mongoTemplate.find(query, ThreadDocument.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThreadDocument> findByParticipant(String participant) {
|
||||||
|
Query query = new Query();
|
||||||
|
query.addCriteria(
|
||||||
|
Criteria.where("participantsIds").in(List.of(participant))
|
||||||
|
);
|
||||||
|
|
||||||
|
return mongoTemplate.find(query, ThreadDocument.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.repositories;
|
package pl.edu.amu.wmi.bookapi.repositories;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.repository.*;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
|
||||||
public interface UserRepository extends MongoRepository<UserDocument, String> {
|
public interface UserRepository extends MongoRepository<UserDocument, String> {
|
||||||
UserDocument findByUsername(String username);
|
UserDocument findByUsername(String username);
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.security;
|
package pl.edu.amu.wmi.bookapi.security;
|
||||||
|
|
||||||
import com.auth0.jwt.*;
|
import com.auth0.jwt.JWT;
|
||||||
import com.fasterxml.jackson.databind.*;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.security.authentication.*;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.core.*;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.userdetails.*;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.web.authentication.*;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
import org.springframework.web.cors.CorsUtils;
|
||||||
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.http.*;
|
import javax.servlet.ServletException;
|
||||||
import java.io.*;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.*;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static com.auth0.jwt.algorithms.Algorithm.*;
|
import static com.auth0.jwt.algorithms.Algorithm.HMAC512;
|
||||||
|
|
||||||
public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
@ -33,6 +39,11 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
|
|||||||
public Authentication attemptAuthentication(HttpServletRequest req,
|
public Authentication attemptAuthentication(HttpServletRequest req,
|
||||||
HttpServletResponse res) throws AuthenticationException {
|
HttpServletResponse res) throws AuthenticationException {
|
||||||
try {
|
try {
|
||||||
|
if (CorsUtils.isPreFlightRequest(req)) {
|
||||||
|
res.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
UserDocument creds = new ObjectMapper()
|
UserDocument creds = new ObjectMapper()
|
||||||
.readValue(req.getInputStream(), UserDocument.class);
|
.readValue(req.getInputStream(), UserDocument.class);
|
||||||
|
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.security;
|
package pl.edu.amu.wmi.bookapi.security;
|
||||||
|
|
||||||
import com.auth0.jwt.*;
|
import com.auth0.jwt.JWT;
|
||||||
import com.auth0.jwt.algorithms.*;
|
import com.auth0.jwt.algorithms.Algorithm;
|
||||||
import org.springframework.security.authentication.*;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.core.context.*;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.web.authentication.www.*;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.http.*;
|
import javax.servlet.ServletException;
|
||||||
import java.io.*;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.*;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.*;
|
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.HEADER_STRING;
|
||||||
|
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.SECRET;
|
||||||
|
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.TOKEN_PREFIX;
|
||||||
|
|
||||||
public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
|
public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.security;
|
package pl.edu.amu.wmi.bookapi.security;
|
||||||
|
|
||||||
import org.springframework.security.core.userdetails.*;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.stereotype.*;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import pl.edu.amu.wmi.bookapi.repositories.*;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
import pl.edu.amu.wmi.bookapi.repositories.UserRepository;
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserDetailsSecurityServiceImpl implements UserDetailsService {
|
public class UserDetailsSecurityServiceImpl implements UserDetailsService {
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.security;
|
package pl.edu.amu.wmi.bookapi.security;
|
||||||
|
|
||||||
import org.springframework.context.annotation.*;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.*;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.web.builders.*;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.*;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.http.*;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.security.crypto.bcrypt.*;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.web.cors.*;
|
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;
|
||||||
|
|
||||||
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.*;
|
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.LOG_IN_URL;
|
||||||
|
import static pl.edu.amu.wmi.bookapi.security.JWTAuthenticationFilter.SIGN_UP_URL;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class WebSecurity extends WebSecurityConfigurerAdapter {
|
public class WebSecurity extends WebSecurityConfigurerAdapter {
|
||||||
@ -23,13 +27,14 @@ public class WebSecurity extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.cors().and().csrf().disable()
|
http.csrf().disable()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
// .antMatchers(HttpMethod.GET, "/api/books", "/api/messages/", "/api/messages/*", "/api/books/public").permitAll()
|
// .antMatchers(HttpMethod.GET, "/api/books", "/api/messages/", "/api/messages/*", "/api/books/public").permitAll()
|
||||||
// .antMatchers(HttpMethod.DELETE, "/api/books/*").permitAll()
|
// .antMatchers(HttpMethod.DELETE, "/api/books/*").permitAll()
|
||||||
// .antMatchers(HttpMethod.PATCH, "/api/books/*").permitAll()
|
// .antMatchers(HttpMethod.PATCH, "/api/books/*").permitAll()
|
||||||
.antMatchers(HttpMethod.POST,
|
.antMatchers(HttpMethod.POST,
|
||||||
SIGN_UP_URL).permitAll()
|
SIGN_UP_URL,
|
||||||
|
LOG_IN_URL).permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.addFilter(
|
.addFilter(
|
||||||
@ -42,8 +47,10 @@ public class WebSecurity extends WebSecurityConfigurerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JWTAuthenticationFilter getConfiguredJwtAuthenticationFilter() throws Exception{
|
private JWTAuthenticationFilter getConfiguredJwtAuthenticationFilter() throws Exception{
|
||||||
|
System.out.println("JWT Auth");
|
||||||
JWTAuthenticationFilter jwtFilter = new JWTAuthenticationFilter(authenticationManager());
|
JWTAuthenticationFilter jwtFilter = new JWTAuthenticationFilter(authenticationManager());
|
||||||
jwtFilter.setFilterProcessesUrl("/users/login");
|
jwtFilter.setFilterProcessesUrl("/users/login");
|
||||||
|
|
||||||
return jwtFilter;
|
return jwtFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,9 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.service;
|
package pl.edu.amu.wmi.bookapi.service;
|
||||||
|
|
||||||
import org.opencv.core.Core;
|
|
||||||
import org.opencv.core.Mat;
|
|
||||||
import org.opencv.core.MatOfByte;
|
|
||||||
import org.opencv.imgcodecs.Imgcodecs;
|
|
||||||
import org.opencv.imgproc.Imgproc;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static java.lang.System.loadLibrary;
|
|
||||||
import static org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ImageProcessingService {
|
public class ImageProcessingService {
|
||||||
|
|
||||||
@ -28,32 +13,34 @@ public class ImageProcessingService {
|
|||||||
|
|
||||||
public String getDecodedEan(MultipartFile imageFile) throws Exception {
|
public String getDecodedEan(MultipartFile imageFile) throws Exception {
|
||||||
|
|
||||||
String fileId = UUID.randomUUID().toString();
|
|
||||||
Path path = Path.of(new File(".").getCanonicalPath());
|
|
||||||
|
|
||||||
byte[] starting = imageFile.getBytes();
|
|
||||||
|
|
||||||
saveImg(starting, path, fileId, 1);
|
|
||||||
|
|
||||||
Mat mat = Imgcodecs.imdecode(new MatOfByte(starting), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
|
|
||||||
|
|
||||||
Mat gray = new Mat();
|
|
||||||
Imgproc.cvtColor(mat, gray, COLOR_BGR2GRAY);
|
|
||||||
|
|
||||||
byte[] grayed = mat2byteArr(gray);
|
|
||||||
|
|
||||||
saveImg(grayed, path, fileId, 2);
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
//
|
||||||
|
// String fileId = UUID.randomUUID().toString();
|
||||||
|
// Path path = Path.of(new File(".").getCanonicalPath());
|
||||||
|
//
|
||||||
|
// byte[] starting = imageFile.getBytes();
|
||||||
|
//
|
||||||
|
// saveImg(starting, path, fileId, 1);
|
||||||
|
//
|
||||||
|
// Mat mat = Imgcodecs.imdecode(new MatOfByte(starting), Imgcodecs.IMREAD_GRAYSCALE);
|
||||||
|
//
|
||||||
|
// Mat gray = new Mat();
|
||||||
|
// Imgproc.cvtColor(mat, gray, COLOR_BGR2GRAY);
|
||||||
|
//
|
||||||
|
// byte[] grayed = mat2byteArr(gray);
|
||||||
|
//
|
||||||
|
// saveImg(grayed, path, fileId, 2);
|
||||||
|
//
|
||||||
|
// return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] mat2byteArr(Mat mat) {
|
// private byte[] mat2byteArr(Mat mat) {
|
||||||
byte[] bytes = new byte[0];
|
// byte[] bytes = new byte[0];
|
||||||
mat.get(0, 0, bytes);
|
// mat.get(0, 0, bytes);
|
||||||
return bytes;
|
// return bytes;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void saveImg(byte[] bytes, Path path, String imageName, Integer version) throws IOException {
|
// private void saveImg(byte[] bytes, Path path, String imageName, Integer version) throws IOException {
|
||||||
Files.write(Path.of(path.toString(), "/" + imageName + "__v" + version + ".png"), bytes);
|
// Files.write(Path.of(path.toString(), "/" + imageName + "__v" + version + ".png"), bytes);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package pl.edu.amu.wmi.bookapi;
|
package pl.edu.amu.wmi.bookapi;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.data.mongodb.core.*;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class BookapiApplicationTests {
|
class BookapiApplicationTests {
|
||||||
@ -14,7 +14,6 @@ class BookapiApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
mongoTemplate.save(new UserDocument("test", "test"));
|
|
||||||
System.out.println(mongoTemplate.findAll(UserDocument.class));
|
System.out.println(mongoTemplate.findAll(UserDocument.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.Integration;
|
package pl.edu.amu.wmi.bookapi.Integration;
|
||||||
|
|
||||||
import com.mongodb.*;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.*;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.boot.test.context.*;
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
import org.springframework.data.mongodb.core.*;
|
|
||||||
import org.springframework.data.mongodb.core.query.*;
|
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
public class BaseInt {
|
public class BaseInt {
|
||||||
public MongoTemplate mongoTemplate;
|
public MongoTemplate mongoTemplate;
|
||||||
|
@ -18,10 +18,10 @@ import pl.edu.amu.wmi.bookapi.models.BookDocument;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
|
@ -12,14 +12,13 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.IntegrationTestUtil;
|
import pl.edu.amu.wmi.bookapi.fixtures.IntegrationTestUtil;
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.api.BookControllerRequest;
|
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.api.MessageControllerRequests;
|
import pl.edu.amu.wmi.bookapi.fixtures.api.MessageControllerRequests;
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.api.UserControllerRequests;
|
import pl.edu.amu.wmi.bookapi.fixtures.api.UserControllerRequests;
|
||||||
import pl.edu.amu.wmi.bookapi.models.MessageDocument;
|
import pl.edu.amu.wmi.bookapi.models.MessageDocument;
|
||||||
import pl.edu.amu.wmi.bookapi.models.ThreadDocument;
|
import pl.edu.amu.wmi.bookapi.models.ThreadDocument;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.Integration.api;
|
package pl.edu.amu.wmi.bookapi.Integration.api;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.*;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.*;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.*;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.*;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.*;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.data.mongodb.core.*;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.web.servlet.*;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.*;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import pl.edu.amu.wmi.bookapi.fixtures.api.*;
|
import pl.edu.amu.wmi.bookapi.fixtures.IntegrationTestUtil;
|
||||||
|
import pl.edu.amu.wmi.bookapi.fixtures.api.UserControllerRequests;
|
||||||
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package pl.edu.amu.wmi.bookapi.fixtures;
|
package pl.edu.amu.wmi.bookapi.fixtures;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.mongodb.core.*;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.query.*;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.stereotype.*;
|
import org.springframework.stereotype.Component;
|
||||||
import pl.edu.amu.wmi.bookapi.models.*;
|
import pl.edu.amu.wmi.bookapi.models.BookDocument;
|
||||||
|
import pl.edu.amu.wmi.bookapi.models.MessageDocument;
|
||||||
|
import pl.edu.amu.wmi.bookapi.models.ThreadDocument;
|
||||||
|
import pl.edu.amu.wmi.bookapi.models.UserDocument;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class IntegrationTestUtil {
|
public class IntegrationTestUtil {
|
||||||
|
@ -7,7 +7,10 @@ import org.springframework.test.web.servlet.ResultActions;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
|
||||||
public class BookControllerRequest {
|
public class BookControllerRequest {
|
||||||
private final MockMvc mvc;
|
private final MockMvc mvc;
|
||||||
|
@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
import pl.edu.amu.wmi.bookapi.api.dto.MessageDto;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
|
||||||
public class MessageControllerRequests {
|
public class MessageControllerRequests {
|
||||||
private final MockMvc mvc;
|
private final MockMvc mvc;
|
||||||
@ -23,7 +23,7 @@ public class MessageControllerRequests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ResultActions getMessages(String bearer, String threadId) throws Exception {
|
public ResultActions getMessages(String bearer, String threadId) throws Exception {
|
||||||
return mvc.perform(get("/api/messages" + threadId)
|
return mvc.perform(get("/api/messages/" + threadId)
|
||||||
.header("Authorization", bearer));
|
.header("Authorization", bearer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import org.springframework.test.web.servlet.ResultActions;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user