⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex6_30.txt

📁 j2ee core design patterns
💻 TXT
字号:
Example 6.30 Security Context Propagation Using LoginContext
public class FrontController extends HttpServlet {

  . . .
  protected void process(HttpServletRequest request,
      HttpServletResponse response) throws java.io.IOException {

    // create Context Object from request
    RequestContext requestContext =
        RequestContextFactory.getInstance().
        createRequestContext(request);
    // Authenticate using JAAS framework
    // Get Authentication Credentials
    String username = requestContext.getStringParameter("UserName");
    String password = requestContext.getStringParameter("Password");
    try {
      // LoginContext is a factory class for the underlying pluggable
      // authentication modules
      LoginContext loginContext = new LoginContext("AuthLevel1",
          new AuthCallbackHandler(username, password));

      // authenticate the Subject
      loginContext.login();

      // get the authenticated Subject
      Subject subject = loginContext.getSubject();

      // propagate Security Context in session scope
      HttpSession session = request.getSession();
      session.setAttribute("SecurityContext", subject);
    } catch (LoginException le) {
      // handle exception
    }
    . . .
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -