authserver2, service database mysql to postgresql chanaging
This commit is contained in:
@@ -30,6 +30,8 @@ dependencies {
|
||||
// implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.5.RELEASE'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
|
||||
implementation 'com.google.code.gson:gson'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
@@ -19,6 +19,8 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
|
||||
// .and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/createOAuthUser").permitAll()
|
||||
.antMatchers("/createToken").permitAll()
|
||||
// .antMatchers("/oauth/token").permitAll()
|
||||
.anyRequest()
|
||||
.authenticated();
|
||||
}
|
||||
|
||||
@@ -18,17 +18,18 @@ import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
//@Order(SecurityProperties.BASIC_AUTH_ORDER -1)
|
||||
//@Order(-1)
|
||||
public class WebSecurity2Config extends WebSecurityConfigurerAdapter {
|
||||
private CustomUserDetailsServiceImpl customUserDetailsService;
|
||||
|
||||
private PasswordEncoder passwordEncoder;
|
||||
// private PasswordEncoder passwordEncoder;
|
||||
|
||||
public WebSecurity2Config(
|
||||
CustomUserDetailsServiceImpl customUserDetailsService
|
||||
CustomUserDetailsServiceImpl customUserDetailsService,
|
||||
PasswordEncoder passwordEncoder
|
||||
) {
|
||||
this.customUserDetailsService = customUserDetailsService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -42,26 +43,12 @@ public class WebSecurity2Config extends WebSecurityConfigurerAdapter {
|
||||
auth.authenticationProvider(daoAuthenticationProvider());
|
||||
}
|
||||
|
||||
// allow controller uri
|
||||
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
// .requestMatchers().antMatchers("/createOAuthUser")
|
||||
// .and()
|
||||
.authorizeRequests()
|
||||
// .antMatchers("/createOAuthUser").permitAll()
|
||||
.anyRequest()
|
||||
.authenticated();
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
||||
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
|
||||
daoAuthenticationProvider.setUserDetailsService(customUserDetailsService);
|
||||
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
|
||||
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);
|
||||
return daoAuthenticationProvider;
|
||||
}
|
||||
|
||||
@@ -71,10 +58,4 @@ public class WebSecurity2Config extends WebSecurityConfigurerAdapter {
|
||||
// return new BCryptPasswordEncoder();
|
||||
// }
|
||||
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("deprecation")
|
||||
public static NoOpPasswordEncoder passwordEncoder() {
|
||||
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,16 @@ package io.bluemoon.authorizationserver2.controller;
|
||||
|
||||
import io.bluemoon.authorizationserver2.domain.user.User;
|
||||
import io.bluemoon.authorizationserver2.service.user.UserService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,7 +38,12 @@ public class AuthController {
|
||||
System.out.println(user);
|
||||
System.out.println(header);
|
||||
|
||||
return user;
|
||||
return userService.createOAuthUser(user);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/createToken", method = RequestMethod.POST)
|
||||
public String createToken(@RequestBody User user, @RequestHeader Map header) throws IOException {
|
||||
return userService.createOAuthToken(user);
|
||||
}
|
||||
|
||||
@PutMapping(value = "/updateOAuthUser")
|
||||
@@ -45,4 +54,6 @@ public class AuthController {
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package io.bluemoon.authorizationserver2.domain.user;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
User findByUsername(String username);
|
||||
// User findByUsername(String username);
|
||||
User findByEmail(String email);
|
||||
Optional<User> findByUsername(String username);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CustomUserDetailsServiceImpl implements UserDetailsService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
System.out.println("why?????????????"+username);
|
||||
User user = userRepository.findByUsername(username);
|
||||
User user = userRepository.findByUsername(username).get();
|
||||
System.out.println(user);
|
||||
List<UserRole> userRole = userRoleRepository.findByUser(user);
|
||||
System.out.println(userRole);
|
||||
|
||||
@@ -2,9 +2,14 @@ package io.bluemoon.authorizationserver2.service.user;
|
||||
|
||||
import io.bluemoon.authorizationserver2.domain.user.User;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User createOAuthUser(User user);
|
||||
|
||||
String createOAuthToken(User user) throws IOException;
|
||||
|
||||
User updateOAuthUser(User user);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,16 @@ package io.bluemoon.authorizationserver2.service.user;
|
||||
|
||||
import io.bluemoon.authorizationserver2.domain.user.User;
|
||||
import io.bluemoon.authorizationserver2.domain.user.UserRepository;
|
||||
import io.bluemoon.authorizationserver2.utils.APIRequest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@@ -20,9 +28,37 @@ public class UserServiceImpl implements UserService{
|
||||
|
||||
@Override
|
||||
public User createOAuthUser(User user) {
|
||||
// user.setPassword(passwordEncoder().encode(user.getPassword()));
|
||||
// user.setPassword();
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createOAuthToken(User user) throws IOException {
|
||||
|
||||
Optional<User> optionalUser = userRepository.findByUsername(user.getUsername());
|
||||
|
||||
System.out.println(passwordEncoder().matches(user.getPassword(), optionalUser.get().getPassword()));
|
||||
// System.out.println(passwordEncoder().matches("1234", optionalUser.get().getPassword()));
|
||||
if (optionalUser.isPresent()) {
|
||||
if (passwordEncoder().matches(user.getPassword(), optionalUser.get().getPassword())) {
|
||||
//token 발급
|
||||
Map<String, Object> tokenInfo = new HashMap<>();
|
||||
tokenInfo.put("username", user.getUsername());
|
||||
tokenInfo.put("password", user.getPassword());
|
||||
// tokenInfo.put("password", "1234");
|
||||
tokenInfo.put("grant_type", "password");
|
||||
APIRequest.ResponseWrapper response = APIRequest.getIRequestExecutor().createOAuthToken(tokenInfo);
|
||||
System.out.println(response.getBody());
|
||||
return response.getBody();
|
||||
|
||||
}
|
||||
System.out.println("-----------------------11");
|
||||
}
|
||||
System.out.println("-----------------------22");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateOAuthUser(User user) {
|
||||
Optional<User> getUser = userRepository.findById(user.getId());
|
||||
@@ -34,4 +70,14 @@ public class UserServiceImpl implements UserService{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public PasswordEncoder passwordEncoder() {
|
||||
// return new BCryptPasswordEncoder();
|
||||
// }
|
||||
@Bean
|
||||
@SuppressWarnings("deprecation")
|
||||
public static NoOpPasswordEncoder passwordEncoder() {
|
||||
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package io.bluemoon.authorizationserver2.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.Getter;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class APIRequest {
|
||||
|
||||
private static IRequestExecutor iRequestExecutor = new DefaultRequestExecutor();
|
||||
|
||||
public static IRequestExecutor getIRequestExecutor() {
|
||||
return iRequestExecutor;
|
||||
}
|
||||
|
||||
public interface IRequestExecutor {
|
||||
ResponseWrapper createOAuthToken(Map tokenInfo) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
public static class DefaultRequestExecutor implements IRequestExecutor {
|
||||
static okhttp3.OkHttpClient client = null;
|
||||
static void init() {
|
||||
client = new okhttp3.OkHttpClient();
|
||||
}
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseWrapper createOAuthToken(Map tokenInfo) throws IOException {
|
||||
String url = "http://localhost:8081/auth/oauth/token";
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String jsonString = gson.toJson(tokenInfo);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonString);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("Authorization", Credentials.basic("a","1"))
|
||||
.post(body)
|
||||
.header("Content-type", "application/json")
|
||||
.build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
Response response = call.execute();
|
||||
ResponseWrapper result = new ResponseWrapper(response.body().string(), convertToString(response.headers()));
|
||||
System.out.println("----------===================------------");
|
||||
System.out.println(result.getBody());
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static String convertToString(Object input) {
|
||||
if (input == null) {
|
||||
return "null";
|
||||
} else if (input instanceof Map) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.STATIC)
|
||||
.excludeFieldsWithModifiers(Modifier.PROTECTED)
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
return gson.toJson((Map)input);
|
||||
} else if (input instanceof List) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.STATIC)
|
||||
.excludeFieldsWithModifiers(Modifier.PROTECTED)
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
return gson.toJson((List)input);
|
||||
} else {
|
||||
return input.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class ResponseWrapper {
|
||||
private String body;
|
||||
private String header;
|
||||
|
||||
public ResponseWrapper(String body, String header) {
|
||||
this.body = body;
|
||||
this.header = header;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,16 +4,24 @@ server.servlet.context-path=/auth
|
||||
security.oauth2.authorization.check-token-access=isAuthenticated()
|
||||
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1/oauth2?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=bluemoon
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.platform=schema
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB53Dialect
|
||||
#spring.datasource.url=jdbc:mysql://127.0.0.1/oauth2?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=bluemoon
|
||||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.platform=schema
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB53Dialect
|
||||
#spring.jpa.database = MYSQL
|
||||
|
||||
|
||||
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/mk2
|
||||
#spring.datasource.platform=postgres
|
||||
#spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
spring.jpa.database = POSTGRESQL
|
||||
|
||||
|
||||
spring.jpa.database = MYSQL
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
@@ -31,7 +31,7 @@ dependencies {
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
|
||||
implementation 'com.google.code.gson:gson'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
runtimeOnly 'org.postgresql:postgresql'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@@ -21,13 +22,10 @@ public class SignController {
|
||||
}
|
||||
|
||||
@PostMapping("/signInMiddleWare")
|
||||
public String signInMiddleWare(HttpServletRequest request) {
|
||||
System.out.println(request);
|
||||
System.out.println(request.getAuthType());
|
||||
System.out.println(request.getSession());
|
||||
System.out.println(request.getParameterMap().toString());
|
||||
public Map signInMiddleWare(HttpServletRequest request) throws IOException {
|
||||
User user = requestToUser(request);
|
||||
|
||||
return "aaaa";
|
||||
return userService.readUser(user);
|
||||
}
|
||||
|
||||
@PostMapping("/signUpMiddleWare")
|
||||
|
||||
@@ -2,12 +2,41 @@ package io.bluemoon.testservice.domain.oauth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "user", schema = "oauth2")
|
||||
public class OAuthUser {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
private String username;
|
||||
|
||||
@Column
|
||||
private String password;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
private String email;
|
||||
|
||||
@Column
|
||||
private String ResourceId;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "oAuthUser", fetch = FetchType.EAGER)
|
||||
private Collection<OAuthUserRole> userRole;
|
||||
|
||||
@Column
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.bluemoon.testservice.domain.oauth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "user_role", schema = "oauth2")
|
||||
public class OAuthUserRole {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
private String role;
|
||||
|
||||
@Column
|
||||
private String projectId;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "userId")
|
||||
private OAuthUser oAuthUser;
|
||||
|
||||
@Column
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package io.bluemoon.testservice.domain.user;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "user", schema = "service")
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -15,4 +17,10 @@ public class User {
|
||||
private String username;
|
||||
@Column
|
||||
private String password;
|
||||
@Column
|
||||
private String status;
|
||||
@Column
|
||||
private LocalDateTime createdAt;
|
||||
@Column
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package io.bluemoon.testservice.domain.user;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class UserEventListener {
|
||||
|
||||
@Async
|
||||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, classes = UserServiceImpl.UserCreateEvent.class)
|
||||
public void handle(UserServiceImpl.UserCreateEvent event) throws IOException {
|
||||
public void userCreateEventHandle(UserServiceImpl.UserCreateEvent event) throws IOException {
|
||||
User user = event.getUser();
|
||||
System.out.println("----------handler");
|
||||
System.out.println(user);
|
||||
@@ -22,17 +22,17 @@ public class UserEventListener {
|
||||
System.out.println(responseWrapper.getHeader());
|
||||
System.out.println(responseWrapper.getBody());
|
||||
|
||||
|
||||
|
||||
// oauth
|
||||
}
|
||||
|
||||
@Async
|
||||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, classes = UserServiceImpl.UserUpdateEvent.class)
|
||||
public void handle(UserServiceImpl.UserUpdateEvent event) throws IOException {
|
||||
public void userUpdateEventHandle(UserServiceImpl.UserUpdateEvent event) throws IOException {
|
||||
System.out.println("----------handler");
|
||||
User user = event.getUser();
|
||||
|
||||
// oauth
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,14 @@ package io.bluemoon.testservice.service.user;
|
||||
|
||||
import io.bluemoon.testservice.domain.user.User;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User createUser(User user);
|
||||
|
||||
User updateUser(User user);
|
||||
|
||||
Map readUser(User user) throws IOException;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,21 @@ package io.bluemoon.testservice.service.user;
|
||||
|
||||
import io.bluemoon.testservice.domain.user.User;
|
||||
import io.bluemoon.testservice.domain.user.UserRepository;
|
||||
import io.bluemoon.testservice.utils.APIRequest;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@@ -38,6 +43,29 @@ public class UserServiceImpl implements UserService, ApplicationEventPublisherAw
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map readUser(User user) throws IOException {
|
||||
System.out.println(user);
|
||||
|
||||
|
||||
Optional<User> optionalUser =
|
||||
userRepository.findByUsername(user.getUsername());
|
||||
|
||||
if (optionalUser.isPresent()) {
|
||||
System.out.println(optionalUser.get().toString());
|
||||
if (passwordEncoder().matches(user.getPassword(),optionalUser.get().getPassword())) {
|
||||
APIRequest.ResponseWrapper response = APIRequest.getIRequestExecutor().createOAuthToken(user);
|
||||
Map a = new HashMap();
|
||||
a.put("data", response);
|
||||
return a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// update password는 별로의 로직으로?
|
||||
@Override
|
||||
public User updateUser(User user) {
|
||||
@@ -64,6 +92,15 @@ public class UserServiceImpl implements UserService, ApplicationEventPublisherAw
|
||||
}
|
||||
}
|
||||
|
||||
public static class UserReadEvent {
|
||||
@Getter
|
||||
private User user;
|
||||
|
||||
private UserReadEvent(@NonNull User user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UserUpdateEvent {
|
||||
@Getter
|
||||
private User user;
|
||||
|
||||
@@ -21,6 +21,7 @@ public class APIRequest {
|
||||
|
||||
public interface IRequestExecutor {
|
||||
ResponseWrapper createOAuthUser(User user) throws IOException;
|
||||
ResponseWrapper createOAuthToken(User user) throws IOException;
|
||||
ResponseWrapper updateOAuthUser(User user);
|
||||
|
||||
ResponseWrapper createOAuthClientDetails();
|
||||
@@ -58,6 +59,27 @@ public class APIRequest {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseWrapper createOAuthToken(User user) throws IOException {
|
||||
String url = "http://localhost:8081/auth/auth";
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String jsonString = gson.toJson(user);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonString);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.header("Content-type", "application/json")
|
||||
.build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
Response response = call.execute();
|
||||
ResponseWrapper result = new ResponseWrapper(response.body().string(), convertToString(response.headers()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseWrapper updateOAuthUser(User user) {
|
||||
return null;
|
||||
|
||||
@@ -11,14 +11,20 @@ server.servlet.context-path=/api
|
||||
security.oauth2.resource.user-info-uri=http://127.0.0.1:8765/auth/check_token
|
||||
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1/local_keepgrow?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=bluemoon
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.platform=schema
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB53Dialect
|
||||
#spring.datasource.url=jdbc:mysql://127.0.0.1/local_keepgrow?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=bluemoon
|
||||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.platform=schema
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB53Dialect
|
||||
|
||||
spring.jpa.database = MYSQL
|
||||
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/mk2
|
||||
#spring.datasource.platform=postgres
|
||||
#spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
spring.jpa.database = POSTGRESQL
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
Reference in New Issue
Block a user