0
OpenNMS 서버로 리디렉션되는 간단한 페이지를 만들려고합니다.JSF가 비밀번호로 리디렉션
나는 OpenNMS는 "기본 인증"을 사용하는 것을 알고 나는이 같은 요청을 수행 할 때
URL url = new URL(webPage);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
을 나는 어떤 문제가하지는.
그러나 내가 ExternalContext (또는 이와 비슷한)를 시도 할 때 나는 항상 로그인 페이지로 리디렉션됩니다.
XTML :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:inputText value="#{newJSFManagedBean.user}" label="user" />
<p:inputText value="#{newJSFManagedBean.pass}" label="pass" />
<p:commandButton value="redirect1" action="#{newJSFManagedBean.redirect}"/>
<!-- <ui:include src="http://10.46.16.85:8980/opennms/"/>-->
</h:form>
</h:body>
</html>
콩 :
public String redirect() throws IOException, ServletException {
System.err.println("" + this.pass + "" + this.user);
FacesContext facesContext = FacesContext.getCurrentInstance();
String name = "admin";
String password = "admin";
String authString = name + ":" + password;
System.out.println("auth string: " + authString);
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
Cookie userCookie = new Cookie("Authorization", "Basic " + authStringEnc);
userCookie.setMaxAge(3600);
((HttpServletResponse) facesContext.getExternalContext()
.getResponse()).addCookie(userCookie);
HttpServletResponse response = ((HttpServletResponse) facesContext.getExternalContext().getResponse());
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println("blicaivens"+req.getHeader("Authorization"));
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
session.setAttribute("Authorization", "Basic " + authStringEnc);
response.setHeader("Authorization", "Basic " + authStringEnc);
req.setAttribute("Authorization", "Basic " + authStringEnc);
externalContext.addResponseHeader("Authorization", "Basic " + authStringEnc);
externalContext.redirect("http://10.46.16.85:8980/opennms/index.jsp?");
return null;
}
당신은 내가 I've는 모든 노력을 생각 볼 수 있듯이 (요청, 응답, 세션
내 "코드"이것이다 , 등) 나는 성공하지 못했습니다.
나를 안내 할 수있는 사람이 있습니까?