完成几个页面
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package net.alawn.bill.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @Author: Alawn
|
||||
* @Description:
|
||||
* @Date: Create in 16:53 2019-05-17
|
||||
*/
|
||||
//@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
// registry.addMapping("/basic/**")
|
||||
// .allowedOrigins("http://domain2.com")
|
||||
// .allowedMethods("GET","POST","PUT", "DELETE")
|
||||
// .allowedHeaders("header1", "header2", "header3")
|
||||
// .exposedHeaders("header1", "header2")
|
||||
// .allowCredentials(false).maxAge(3600);
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("PUT", "DELETE", "GET", "POST", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.exposedHeaders("access-control-allow-headers",
|
||||
"access-control-allow-methods",
|
||||
"access-control-allow-origin",
|
||||
"access-control-max-age",
|
||||
"X-Frame-Options")
|
||||
.allowCredentials(true).maxAge(3600);
|
||||
}
|
||||
|
||||
}
|
||||
+32
-1
@@ -1,5 +1,7 @@
|
||||
package net.alawn.bill.security;
|
||||
package net.alawn.bill.config;
|
||||
|
||||
import net.alawn.bill.security.JwtAuthenticationEntryPoint;
|
||||
import net.alawn.bill.security.JwtAuthenticationTokenFilter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -21,6 +23,11 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
import org.springframework.security.web.firewall.HttpFirewall;
|
||||
import org.springframework.security.web.firewall.StrictHttpFirewall;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author: Alawn
|
||||
@@ -78,7 +85,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
/** Security Http 配置 */
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// http // 去掉跨域
|
||||
http.csrf().disable() // 去掉跨域
|
||||
.cors()
|
||||
.and()
|
||||
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler)
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
@@ -86,6 +96,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/druid/**").permitAll()
|
||||
.antMatchers("/swagger*").permitAll()
|
||||
.antMatchers( HttpMethod.GET, "/","/*.html", "/favicon.ico", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
|
||||
// .antMatchers("/resources/**").permitAll()
|
||||
.antMatchers("/auth/**").permitAll()
|
||||
.antMatchers("/bill/**").authenticated()
|
||||
.antMatchers("/basic/**/*").authenticated()
|
||||
@@ -104,6 +115,26 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
http.headers().cacheControl(); // 禁用缓存
|
||||
}
|
||||
|
||||
/** Security 跨域设置 */
|
||||
@Bean
|
||||
CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowedOrigins(Arrays.asList("*"));
|
||||
configuration.setAllowedMethods(Arrays.asList("PUT", "DELETE", "GET", "POST", "OPTIONS"));
|
||||
configuration.setAllowedHeaders(Arrays.asList("*"));
|
||||
configuration.addExposedHeader("Location"); // 暴露 Location header
|
||||
configuration.addExposedHeader("access-control-allow-headers");
|
||||
configuration.addExposedHeader("access-control-allow-methods");
|
||||
configuration.addExposedHeader("access-control-allow-origin");
|
||||
configuration.addExposedHeader("access-control-max-age");
|
||||
configuration.addExposedHeader("X-Frame-Options");
|
||||
configuration.setAllowCredentials(true);
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
/** Security Web 配置 */
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@@ -47,7 +48,7 @@ public class BasicController {
|
||||
@Autowired
|
||||
TitleRepo titleRepo;
|
||||
|
||||
@RequestMapping(value = "/post",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/posts",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Post> addPost(@RequestBody AddPost addPost, Principal principal) throws URISyntaxException {
|
||||
AuthUser authUser = (AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
@@ -61,7 +62,17 @@ public class BasicController {
|
||||
return ResponseEntity.ok(post);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/post/{id}",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/posts",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<List<Post>> fetchPosts() {
|
||||
AuthUser authUser = (AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
long userId = authUser.getId();
|
||||
|
||||
List<Post> posts = postRepo.findByUserId(userId);
|
||||
return ResponseEntity.ok(posts);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/posts/{id}",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Post> getPost(@PathVariable long id){
|
||||
log.info("post id:" + id);
|
||||
@@ -78,7 +89,7 @@ public class BasicController {
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/merchant",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/merchants",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Merchant> addMerchant(@RequestBody AddMerchant addMerchant) throws URISyntaxException {
|
||||
/** 登记 Post */
|
||||
@@ -87,7 +98,15 @@ public class BasicController {
|
||||
return ResponseEntity.ok(merchant);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/merchant/{id}",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/merchants",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<List<Merchant>> fetchMerchants() throws URISyntaxException {
|
||||
List<Merchant> merchants = merchantRepo.findAll();
|
||||
return ResponseEntity.ok(merchants);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/merchants/{id}",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Merchant> getMerchant(@PathVariable long id){
|
||||
/** 登记 Post */
|
||||
@@ -100,21 +119,26 @@ public class BasicController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/title",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/titles",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Title> addTitle(@RequestBody AddTitle addTitle) throws URISyntaxException {
|
||||
/** 登记 Post */
|
||||
public ResponseEntity<Title> addTitle(@RequestBody AddTitle addTitle) {
|
||||
/** 登记 Title */
|
||||
Title title = titleRepo.save(addTitle.build());
|
||||
titleRepo.flush();
|
||||
return ResponseEntity.ok(title);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/title/{id}",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/titles",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<List<Title>> addTitle() {
|
||||
List<Title> titles = titleRepo.findAll();
|
||||
return ResponseEntity.ok(titles);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/titles/{id}",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Title> getTitle(@PathVariable long id){
|
||||
/** 登记 Post */
|
||||
/** 登记 Title */
|
||||
Optional<Title> title = titleRepo.findById(id);
|
||||
if(title.isPresent()) {
|
||||
return ResponseEntity.ok(title.get());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.alawn.bill.entity.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -20,6 +21,7 @@ import javax.persistence.Table;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Post extends Base{
|
||||
@JsonIgnore
|
||||
private long userId ;
|
||||
private String address ;
|
||||
private String contact ;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package net.alawn.bill.exception;
|
||||
|
||||
/**
|
||||
* @Author: Alawn
|
||||
* @Description:
|
||||
* @Date: Create in 15:52 2019-03-28
|
||||
*/
|
||||
|
||||
public class UserAlreadyExistException extends CommonException {
|
||||
|
||||
private final static RespMsg msg = RespMsg.USER_ALREADY_EXIST;
|
||||
|
||||
public UserAlreadyExistException() {
|
||||
super(msg.code(),msg.message());
|
||||
}
|
||||
|
||||
public UserAlreadyExistException(String message) {
|
||||
super(msg.code(),message);
|
||||
}
|
||||
|
||||
public UserAlreadyExistException(String format, Object... arguments) {
|
||||
super(msg.code(),format, arguments);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.alawn.bill.repository;
|
||||
|
||||
import net.alawn.bill.entity.po.Book;
|
||||
import net.alawn.bill.entity.po.Item;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.alawn.bill.entity.po.Merchant;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: Alawn
|
||||
* @Description:
|
||||
@@ -13,5 +15,4 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MerchantRepo extends JpaRepository<Merchant, Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.alawn.bill.entity.po.Post;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: Alawn
|
||||
* @Description:
|
||||
@@ -13,5 +15,5 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PostRepo extends JpaRepository<Post, Long> {
|
||||
|
||||
List<Post> findByUserId(long userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user