Package com.github.ebnew.ki4so.core.authentication

Examples of com.github.ebnew.ki4so.core.authentication.AuthenticationImpl


    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    result = new LoginResult();
    request.getSession().setAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION, "service");
    result.setSuccess(true);
    AuthenticationImpl authentication = new AuthenticationImpl();
    Map<String, Object> attributes = new HashMap<String, Object>();
    authentication.setAttributes(attributes);
    attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
    result.setAuthentication(authentication);
    mvResult = loginResultToView.loginResultToView(mv, result, request, response);
    //检查输出结果。
    Assert.assertNotNull(mvResult);
    Assert.assertNull(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION));
    Assert.assertEquals("loginSucess", mvResult.getViewName());
    Assert.assertEquals(authentication, mvResult.getModel().get("authentication"));
    Assert.assertEquals("ki4so-sever-key", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
   
   

    /**
     * 测试登录成功的情况,结果中存在service参数,则应该跳转到该地址去。
     */
    mv = new ModelAndView();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    result = new LoginResult();
    result.setSuccess(true);
    authentication = new AuthenticationImpl();
    attributes = new HashMap<String, Object>();
    authentication.setAttributes(attributes);
    attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
    attributes.put(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY, "ki4so-client-key");
    attributes.put(WebConstants.SERVICE_PARAM_NAME, "htpp://localhost:8080/space-web/hello.jsp");
    result.setAuthentication(authentication);
    mvResult = loginResultToView.loginResultToView(mv, result, request, response);
    //检查输出结果。
    Assert.assertNotNull(mvResult);
    Assert.assertNull(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION));
    Assert.assertTrue(mvResult.getView() instanceof RedirectView);
    RedirectView view = (RedirectView)mvResult.getView();
    Assert.assertEquals("htpp://localhost:8080/space-web/hello.jsp?"+WebConstants.KI4SO_CLIENT_ENCRYPTED_CREDENTIAL_COOKIE_KEY+"=ki4so-client-key",view.getUrl());
    Assert.assertEquals(authentication, mvResult.getModel().get("authentication"));
    Assert.assertEquals("ki4so-sever-key", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
   
   
    /**
     * 测试登录成功的情况,结果中存在service参数,且URL地址中是带"?"的。
     */
    mv = new ModelAndView();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    result = new LoginResult();
    result.setSuccess(true);
    authentication = new AuthenticationImpl();
    attributes = new HashMap<String, Object>();
    authentication.setAttributes(attributes);
    attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
    attributes.put(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY, "ki4so-client-key");
    attributes.put(WebConstants.SERVICE_PARAM_NAME, "htpp://localhost:8080/space-web/hello.jsp?hello=word");
    result.setAuthentication(authentication);
    mvResult = loginResultToView.loginResultToView(mv, result, request, response);
View Full Code Here

TOP

Related Classes of com.github.ebnew.ki4so.core.authentication.AuthenticationImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.