Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public EgovLoginFailHandler(EgovSecurityConfig config) {
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
if (ObjectUtils.isEmpty(config)) {
throw new NoSuchBeanDefinitionException("### EgovLoginFailHandler getAccessDeniedUrl not found.");
throw new NoSuchBeanDefinitionException("### EgovLoginFailHandler getLoginFailureUrl not found.");
}

String failureUrl;
if (StringUtils.hasText(config.getAccessDeniedUrl())) {
failureUrl = config.getAccessDeniedUrl();
if (StringUtils.hasText(config.getLoginFailureUrl())) {
failureUrl = config.getLoginFailureUrl();
} else {
failureUrl = DEFAULT_LOGIN_FAILURE_URL;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.egovframe.rte.fdl.security.bean;

import org.egovframe.rte.fdl.security.config.EgovSecurityConfig;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.authentication.BadCredentialsException;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class EgovLoginFailHandlerTest {

@Test
public void onAuthenticationFailure_usesLoginFailureUrl() throws Exception {
EgovSecurityConfig config = new EgovSecurityConfig();
config.setLoginFailureUrl("/uat/uia/loginFail.do");
// 접근거부 URL 은 로그인 실패와 다른 화면이다. 둘을 구분해 두고 어느 쪽으로 가는지 본다.
config.setAccessDeniedUrl("/system/accessDenied.do");

EgovLoginFailHandler handler = new EgovLoginFailHandler(config);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();

handler.onAuthenticationFailure(request, response, new BadCredentialsException("bad"));

assertEquals("/uat/uia/loginFail.do", response.getForwardedUrl());
}

@Test
public void onAuthenticationFailure_fallsBackToDefaultUrl_whenLoginFailureUrlBlank() throws Exception {
EgovSecurityConfig config = new EgovSecurityConfig();
config.setLoginFailureUrl(" ");
config.setAccessDeniedUrl("/system/accessDenied.do");

EgovLoginFailHandler handler = new EgovLoginFailHandler(config);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();

assertDoesNotThrow(() -> handler.onAuthenticationFailure(request, response, new BadCredentialsException("bad")));
assertEquals("/index.html", response.getForwardedUrl());
}

}