java http 인증 방식
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
boolean authenticated = false;
String authorization = request.getHeader("authorization");
System.out.println("authorization:" + authorization);
if (authorization != null) {
if (authorization.startsWith("Basic")) {
authorization = authorization.substring(authorization
.indexOf(' ') + 1);
byte[] bytes = decoder.decodeBuffer(authorization);
authorization = new String(bytes);
String userName = authorization.substring(0, authorization
.indexOf(':'));
String password = authorization.substring(authorization
.indexOf(':') + 1);
System.out.println("userName:" + userName);
System.out.println("password:" + password);
authenticated = userName.equals("abc")
&& password.equals("abc");
} else if (authorization.startsWith("Digest")) {
String userName = authorization.substring(authorization
.indexOf("username="));
userName = userName.substring("username=\"".length());
userName = userName.substring(0, userName.indexOf('"'));
String password = authorization.substring(authorization
.indexOf("response="));
password = password.substring("response=\"".length());
password = password.substring(0, password.indexOf('"'));
authenticated = userName.equals("abc")
&& password
.equals("3cf1135d3b8e20dd9272d06288569a56");
}
}
if (!authenticated) {
// response.addHeader("WWW-Authenticate","Digest realm=\"Tomcat Manager Application\"");
response.addHeader("WWW-Authenticate",
"Basic realm=\"Tomcat Manager Application\"");
response.sendError(401, "Unauthorized");
} else {
out.println("hello abc");
}
%>
</body>
</html>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.