권한에 맞는 사람이 로그인 했을경우 / 안했을 경우

조수경·2022년 1월 18일
0

JSP

목록 보기
32/45

login.jsp로 권한에

tomcat-users.xml

web.xml에 추가하기 : admin은 거부되서 tomcat으로 로그인 설정

<security-constraint>
		<web-resource-collection>
			<web-resource-name>JSPBook</web-resource-name>
			<!-- 접근을 제한할 요청 경로  -->
			<url-pattern>/ch04/addProduct.jsp</url-pattern>
			<http-method>GET</http-method>
		</web-resource-collection>
		<auth-constraint>
			<description></description>
			<!-- 권한이 부여된 role 이름 -->
			<role-name>tomcat</role-name>
		</auth-constraint>
	</security-constraint>
	<security-constraint>
		<web-resource-collection>
			<web-resource-name>JSPBook</web-resource-name>
			<!-- 접근을 제한할 요청 경로  -->
			<url-pattern>/ch03/*</url-pattern>
			<http-method>GET</http-method>
		</web-resource-collection>
		<auth-constraint>
			<description></description>
			<!-- 권한이 부여된 role 이름 -->
			<role-name>tomcat</role-name>
		</auth-constraint>
	</security-constraint>
	<!-- 시큐리티 인증 설정 -->
	<login-config>
		<!-- BASIC 인증 처리 기법으로 설정 -->
<!-- 		<auth-method>BASIC</auth-method> -->
		<!-- FORM 기반 인증 처리 기법으로 설정 -->
		<auth-method>FORM</auth-method>
		<form-login-config>
			<!-- 인증 처리를 위한 로그인 페이지 설정 -->
			<form-login-page>/ch04/login.jsp</form-login-page>
			<!-- 인증 실패 시 오류 페이지 설정 -->
			<form-error-page>/ch04/login_failed.jsp</form-error-page>
		</form-login-config>
	</login-config>

tomcat / tomcat1234로 로그인 했을 경우

tomcat / tomcat1234로 로그인 안했을 경우

login.jsp에 추가

<div class="container" align="center">
		<div class="col-md-4 col-md-offset-4">
			<h3 class="form-signin-heading">Please Sign in</h3>
			<!-- login.jsp?error=1 -->
			<c:if test="${param.error eq '1'}">
				<div class="alert alert-danger">
					아이디와 비밀번호를 확인해주세요
				</div>
			</c:if>
		</div>

login_failed.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
//로그인 인증(login.jsp)에 실패 시 강제 이동
response.sendRedirect("login.jsp?error=1");
%>

로그아웃 했을경우

	//jsp의 영역 (점점 커지는 영역)
	//page
	//request
	//session: 로그인할때 사용
	//applicatrion
	
	
	//security를 통해 로그인 인증을 할 때 웹 브라우저에 저장된 모든
	//사용자를 삭제함
	session.invalidate();
	response.sendRedirect("addProduct.jsp");//여기로 되돌아 간다

profile
신입 개발자 입니다!!!

0개의 댓글