저는 웹 응용 프로그램에서 Omnifaces를 사용하고 있으며 현재 HttpFilter를 사용하여 로그인 권한을 부여하고 있습니다.로그인을 승인하는 동안 HttpFilter에 이상한 문제가 발생했습니다.
여기 내 필터 클래스
@WebFilter("/backend/*")
public class AuthorizationFilter extends HttpFilter {
@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response,
HttpSession session, FilterChain chain) throws ServletException, IOException {
if (session != null && session.getAttribute("userManagedBean") != null) {
chain.doFilter(request, response);
} else {
response.sendRedirect(request.getContextPath() + "/frontend/login.xhtml?faces-redirect=true");
}
}
}
응용 프로그램은 여전히 문제없이 실행된다. 또한 로그인없이 /backend/*.xhtml
에 액세스 할 수도 있습니다.
오류 로그가 없습니다.
누구나 이런 이상한 문제에 대해 알고 있습니까?
@ManagedBean
@SessionScoped
public class UserManagedBean extends TblStaff implements Serializable {
private TblStaff staff = null;
private String currentLogin;
private String username;
private String password;
private boolean loggedIn;
private ExternalContext ec;
@ManagedProperty(value="#{navigationBean}")
private NavigationBean navigationBean;
public UserManagedBean() {
super();
}
public String login() {
int isValid = doLogin();
if (isValid == 1) {
StaffBLL staffBLL = new StaffBLL();
staff = staffBLL.getStaffByUsername(username);
String destinationUrl = null;
if (staff.getRoleId() == 1) {
loggedIn = true;
setCurrentLogin("admin");
destinationUrl = navigationBean.redirectToBackend();
} else if (staff.getRoleId() == 2) {
loggedIn = true;
setCurrentLogin("manager");
destinationUrl = navigationBean.redirectToManager();
} else if (staff.getRoleId() == 3) {
loggedIn = true;
setCurrentLogin("faculty");
destinationUrl = navigationBean.redirectToFaculty();
}
return destinationUrl;
} else {
return navigationBean.toLogin();
}
}
public static void setSession(String key, Object value) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
session.setAttribute(key, value);
}
public static Object getSession(String key) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
return session.getAttribute(key);
}
public String logout() {
loggedIn = false;
ec = FacesContext.getCurrentInstance().getExternalContext();
ec.invalidateSession();
setCurrentLogin(null);
return navigationBean.toFrontend();
}
public void logoutAdmin(ActionEvent actionEvent) throws IOException {
loggedIn = false;
ec = FacesContext.getCurrentInstance().getExternalContext();
ec.invalidateSession();
setCurrentLogin(null);
ec.redirect(ec.getRequestContextPath() + "/frontend/index.xhtml?faces-redirect=true");
}
public int doLogin() {
CallableStatement objCall;
SHAConverter hash = new SHAConverter();
int result = -1;
String[] params = new String[3];
params[0] = username;
params[1] = hash.hashBasic(password);
params[2] = null;
try {
objCall = SQLHelper.execute("procLogin", params);
result = objCall.getInt("Result");
} catch (SQLException ex) {
System.out.println("Error: " + ex.getMessage());
}
return result;
}
어떻게 세션에서'userManagedBean' 속성을 설정하고 지우시겠습니까? 코드를 보여줄 수 있습니까? –
분명히'userManagedBean'이 null이 아닙니다. – kolossus
@DavidLevesque : 질문을 업데이트했습니다. –