tomcat-user.xml
web.xml에 추가
<security-role>
<role-name>role1</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>JSPBook</web-resource-name>
<!-- 접근을 제한할 요청 경로 -->
<url-pattern>/ch10/security01.jsp</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<description></description>
<!-- 권한이 부여된 role 이름 -->
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>
<!-- 시큐리티 인증 설정 -->
<login-config>
<!-- BASIC 인증 처리 기법으로 설정 -->
<auth-method>BASIC</auth-method>
</login-config>
security01.jsp를 실행하면
tomcat에서 설정해준 이름과 비밀번호를 입력하면
인증이 완료됨
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>Security</title>
</head>
<body>
<h2>인증 성공했습니다.</h2>
</body>
</html>
web.xml 설정
security01.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>Security</title>
</head>
<body>
<h2>인증 성공했습니다.</h2>
<h4>사용자명 : <%=request.getRemoteUser()%></h4>
<h4>인증방법 : <%=request.getRemoteUser()%></h4>
<h4>
역할명(role) tomcat에 속한 사용자가 로그인한건가요?
<%=request.isUserInRole("tomcat") %>
</h4>
<h4>
역할명(role) role1에 속한 사용자가 로그인한건가요?
<%=request.isUserInRole("role1") %>
</h4>
</body>
</html>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>Security</title>
</head>
<body>
<!-- 폼 기반 인증 처리를 위해 j_security_check을 사용 -->
<form name="loginForm" action="j_security_check"
method="post">
<p>사용자명 : <input type="text" name="j_username" /></p>
<p>비밀번호 : <input type="password" name="j_password" /></p>
<p><input type="submit" value="전송" /></p>
</form>
</body>
</html>
login_failed.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>Security</title>
</head>
<body>
<h2>인증 실패했습니다.</h2>
</body>
</html>