2013-07-30 1 views

답변

0

BASIC 인증을 사용해야한다. 같은 번호로 JAAS을 사용해야합니다. This tutorialFORM 기반 인증을 제공합니다. 당신이 BASIC 인증을 원하는대로하지만, 당신이

request.getUserPrincipal().getName().toString(); 
0

를 다음과 같이 당신은 다음 링크를 참조 할 수 있습니다 이것에 대한 기본 인증을 사용해야하는 사용자 주체를 검색 할 수 있습니다

<login-config> 
    <auth-method>BASIC</auth-method> 
</login-config> 

필요, 그것은 기본 인증을 제공합니다 서블릿 사용.

<login-config> 
     <auth-method>BASIC</auth-method> 
</login-config> 

그것은 또한 web.xml에 에서 기본 인증을 구성, 당신은 바람둥이 - users.xml에서의

<?xml version='1.0' encoding='utf-8'?> 
<tomcat-users> 
    <role rolename="tomcat"/> 
    <user username="tomcat" password="tomcat" roles="tomcat"/> 
    <user username="yourname" password="yourpassword" roles="tomcat"/> 
    <user username="test" password="test"/> 
</tomcat-users> 

를 추가 할 필요가

예 링크 : http://www.avajava.com/tutorials/lessons/how-do-i-use-basic-authentication-with-tomcat.html?page=1

그것을 희망 당신에게 도움이됩니다.

+0

감사합니다. 매우 도움이되었다. –

0
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    request.setCharacterEncoding("windows-31j"); 
    response.setContentType("text/html; charset=windows-31j"); 
    String auth = request.getHeader("Authorization"); 
    if (auth == null) 
    { 
     response.setStatus(401); 
     response.setHeader("Cache-Control","no-store"); 
     response.setDateHeader("Expires",0); 
     response.setHeader("WWW-authenticate","Basic Realm=\"AuthDemo Server\""); 

    } else { 
     response.getWriter().print("Authorization :" + request.getHeader("Authorization")); 
    } 

      } 
     } 
관련 문제