Compare commits
2 Commits
a9c5fb2283
...
h-hein2
| Author | SHA1 | Date | |
|---|---|---|---|
| 19d27c7722 | |||
| 13241369ae |
@@ -14,46 +14,59 @@ import com.example.demo.service.LoginAttemptService;
|
|||||||
|
|
||||||
// ログイン失敗時の処理
|
// ログイン失敗時の処理
|
||||||
@Component
|
@Component
|
||||||
public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
|
public class CustomAuthenticationFailureHandler
|
||||||
|
extends SimpleUrlAuthenticationFailureHandler {
|
||||||
|
|
||||||
private LoginAttemptService loginAttemptService;
|
private final LoginAttemptService loginAttemptService;
|
||||||
|
|
||||||
public CustomAuthenticationFailureHandler(LoginAttemptService loginAttemptService) {
|
public CustomAuthenticationFailureHandler(
|
||||||
this.loginAttemptService = loginAttemptService;
|
LoginAttemptService loginAttemptService) {
|
||||||
}
|
this.loginAttemptService = loginAttemptService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
public void onAuthenticationFailure(
|
||||||
AuthenticationException exception) throws IOException, ServletException {
|
HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
AuthenticationException exception)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
|
||||||
// 画面から入力されたメールアドレスを取得
|
// 画面から入力されたメールアドレスを取得
|
||||||
String mailAddress = request.getParameter("mailAddress");
|
String mailAddress = request.getParameter("mailAddress");
|
||||||
|
|
||||||
if (mailAddress != null && !mailAddress.isBlank()) {
|
// メールアドレスが空欄の場合
|
||||||
String mail = mailAddress.trim();
|
if (mailAddress == null || mailAddress.isBlank()) {
|
||||||
|
getRedirectStrategy().sendRedirect(
|
||||||
|
request, response, "/login?error=empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (loginAttemptService.isBlocked(mail)) {
|
String mail = mailAddress.trim();
|
||||||
getRedirectStrategy().sendRedirect(
|
|
||||||
request, response, "/login?error=locked");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 失敗回数を1増やす
|
// すでにロックされている場合
|
||||||
loginAttemptService.loginFailed(mail);
|
if (loginAttemptService.isBlocked(mail)) {
|
||||||
|
getRedirectStrategy().sendRedirect(
|
||||||
|
request, response, "/login?error=locked");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// すでにロック中なら失敗回数を増やさない
|
// ログイン失敗回数を増やす
|
||||||
if (loginAttemptService.isBlocked(mail)) {
|
loginAttemptService.loginFailed(mail);
|
||||||
getRedirectStrategy().sendRedirect(
|
|
||||||
request, response, "/login?error=locked");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// あと何回失敗されるとロックされるか取得
|
// 失敗回数の上限に達した場合
|
||||||
int remaining = loginAttemptService.getRemainingAttempts(mail);
|
if (loginAttemptService.isBlocked(mail)) {
|
||||||
|
getRedirectStrategy().sendRedirect(
|
||||||
|
request, response, "/login?error=locked");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getRedirectStrategy().sendRedirect(
|
// 残りのログイン試行回数を取得
|
||||||
request, response, "/login?error=failed&remaining=" + remaining);
|
int remaining =
|
||||||
}
|
loginAttemptService.getRemainingAttempts(mail);
|
||||||
|
|
||||||
}
|
getRedirectStrategy().sendRedirect(
|
||||||
|
request, response,
|
||||||
|
"/login?error=failed&remaining=" + remaining);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +110,8 @@ public class EmployeeService {
|
|||||||
e.add("社員名よみを入力してください。");
|
e.add("社員名よみを入力してください。");
|
||||||
else if (f.getKnEmployee().length() > 100)
|
else if (f.getKnEmployee().length() > 100)
|
||||||
e.add("社員名よみは100文字以内で入力してください。");
|
e.add("社員名よみは100文字以内で入力してください。");
|
||||||
|
else if (!f.getKnEmployee().matches("^[\\u3040-\\u309F]+$"))
|
||||||
|
e.add("社員名よみはひらがなで入力してください");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkMail(EmployeeForm f, Integer selfId, List<String> e) {
|
private void checkMail(EmployeeForm f, Integer selfId, List<String> e) {
|
||||||
|
|||||||
@@ -127,3 +127,8 @@ th { background: #eaf4f6; }
|
|||||||
.page-number:hover {
|
.page-number:hover {
|
||||||
background: #d5edf1;
|
background: #d5edf1;
|
||||||
}
|
}
|
||||||
|
.page-number.active {
|
||||||
|
background: #176a78;
|
||||||
|
color: #fff;
|
||||||
|
border-color: #176a78;
|
||||||
|
}
|
||||||
@@ -65,6 +65,7 @@
|
|||||||
th:href="@{/books(page=${bookPage.number-1}, nmBook=${nmBook}, publisher=${publisher}, note=${note})}">前へ</a>
|
th:href="@{/books(page=${bookPage.number-1}, nmBook=${nmBook}, publisher=${publisher}, note=${note})}">前へ</a>
|
||||||
<span th:each="pageNum : ${pageNumbers}">
|
<span th:each="pageNum : ${pageNumbers}">
|
||||||
<a class="page-number"
|
<a class="page-number"
|
||||||
|
th:classappend="${pageNum == bookPage.number} ? ' active' : ''"
|
||||||
th:href="@{/books(page=${pageNum}, nmBook=${nmBook}, publisher=${publisher}, note=${note})}"
|
th:href="@{/books(page=${pageNum}, nmBook=${nmBook}, publisher=${publisher}, note=${note})}"
|
||||||
th:text="${pageNum + 1}"></a>
|
th:text="${pageNum + 1}"></a>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user