custom api request
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.authorizationserver2.controller;
|
||||||
|
|
||||||
|
public class SignController {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.config;
|
||||||
|
|
||||||
|
public class WebMvcConfig {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.config;
|
||||||
|
|
||||||
|
public class WebSecurityConfig {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.controller;
|
||||||
|
|
||||||
|
public class SignController {
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package io.bluemoon.testservice.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.domain.user;
|
||||||
|
|
||||||
|
public interface UserRepository {
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.bluemoon.authorizationserver.config.handler;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class CustomAuthFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
||||||
|
// logging 붙이기
|
||||||
|
System.out.println(exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
|
public class UserEventListener {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
|
public class UserServiceImpl {
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package io.bluemoon.testservice.utils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import io.bluemoon.testservice.domain.user.User;
|
||||||
|
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 createOAuthUser(User user) throws IOException;
|
||||||
|
ResponseWrapper updateOAuthUser(User user);
|
||||||
|
|
||||||
|
ResponseWrapper createOAuthClientDetails();
|
||||||
|
ResponseWrapper updateOAuthClientDetials();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DefaultRequestExecutor implements IRequestExecutor {
|
||||||
|
static okhttp3.OkHttpClient client = null;
|
||||||
|
static void init() {
|
||||||
|
client = new okhttp3.OkHttpClient();
|
||||||
|
}
|
||||||
|
static {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseWrapper createOAuthUser(User user) throws IOException {
|
||||||
|
String url = "";
|
||||||
|
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 null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseWrapper updateOAuthUser(User user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseWrapper createOAuthClientDetails() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseWrapper updateOAuthClientDetials() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
test-service/src/main/resources/templates/signIn.html
Normal file
47
test-service/src/main/resources/templates/signIn.html
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<form role="form" th:action="@{/login}" method="post">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="username" class="col-sm-2 col-form-label">ID</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="username" placeholder="id" name="username">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="password" class="col-sm-2 col-form-label">Password</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="password" class="form-control" id="password" placeholder="password" name="password">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" id="csrf_token" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
||||||
|
<button type="submit" class="btn btn-primary">Sign in</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a href="/mk-auth/oauth2/authorization/facebook" class="btn btn-primary btn-lg active" role="button" aria-pressed="false">Facebook</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a href="/mk-auth/oauth2/authorization/google" class="btn btn-secondary btn-lg active" role="button" aria-pressed="false">Google</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user