-1

私は問題があります。私のアプリには、(カスタム認証プロバイダークラスで)認証に使用される既存のオブジェクトがあります。このオブジェクトには接続に関する情報があるため、このオブジェクトは重要です。認証後、このオブジェクトは存在します。次に、このオブジェクトをJSPページに渡します。どうすればいいのかわかりません。

doGet()このクラスのメソッドを作成し、JSPでrequest.setAttribute("object", object)このオブジェクトを作成して取得しようとしましrequest.getAttribute("object")たが、機能しません。また、使ってみましたが、うまくいき<jsp:useBean>ません。他に解決策はありません。

手伝ってくれませんか?前もって感謝します。

4

1 に答える 1

0

わかりましたので、ldap サーバー (ldapConnect クラス) に接続するカスタム認証プロバイダーに retrieveUser メソッドがあります。

@Override
protected UserDetails retrieveUser(String username,
        UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {

    log.entry("retrieveUser", authentication.getPrincipal());

    LdapUser userDetail = null;

    UsernamePasswordAuthenticationToken userToken = authentication;
    String userName = userToken.getName();
    userName = userName != null ? userName.toLowerCase() : userName;
    String password = userToken.getCredentials().toString();

    if (password == null || "".equals(password)) {
        log.debug("retrieveUser", "no password provided");
        throw new AuthenticationCredentialsNotFoundException(
                "Invalid login or password");
    }

    // try to connect with ldap and check retrieved username and
    // password
    LdapConnect ldapConnect = new LdapConnect();
    connect = ldapConnect.connection(userName, password);

    if (connect) {
        log.debug("retrieve user", "correct connection with ldap");
        userDetail = new LdapUser();
        setUserDetails(userDetail, ldapConnect.getCtx(), username);
        userDetail.setLdapConnect(ldapConnect);
    }

    if (userDetail == null) {
        throw new UsernameNotFoundException("User not found");
    }

    return userDetail;

}

その後、既存の LdapConnect クラス (このクラスの 1 つの属性に正確に) にアクセスしたいので、LdapConnect クラスを HttpServlet クラスから拡張し、doGet メソッドを実装しました。

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setAttribute("ctx", ctx);
    getServletContext().getRequestDispatcher("/ldap_saved.jsp").forward(
            request, response);
}

最後に、jsp ファイルの LdapClass から ctx 属性を取得しようとします。

    <%DirContext ctx = (DirContext) request.getAttribute("ctx");%>
<%=ctx.toString();%>

しかし、この方法では既存の ctx オブジェクトを取得できません。

于 2013-01-29T08:13:56.733 に答える