コード例 #1
0
  @Before
  public void before() throws IOException, JDOMException {

    factory = fixture.getFactory();
    fixture.initSystemData();

    StringBuffer standardConfigXml = new StringBuffer();
    standardConfigXml.append("<config name=\"MyContentType\" version=\"1.0\">");
    standardConfigXml.append("     <form>");

    standardConfigXml.append("         <title name=\"myTitle\"/>");

    standardConfigXml.append("         <block name=\"TestBlock1\">");

    standardConfigXml.append(
        "             <input name=\"myTitle\" required=\"true\" type=\"text\">");
    standardConfigXml.append("                 <display>My title</display>");
    standardConfigXml.append("                 <xpath>contentdata/mytitle</xpath>");
    standardConfigXml.append("             </input>");

    standardConfigXml.append("             <input name=\"myBinaryfile\" type=\"uploadfile\">");
    standardConfigXml.append("                 <display>My binaryfile</display>");
    standardConfigXml.append("                 <xpath>contentdata/mybinaryfile</xpath>");
    standardConfigXml.append("             </input>");

    standardConfigXml.append("         </block>");
    standardConfigXml.append("     </form>");
    standardConfigXml.append("</config>");
    standardConfig = XMLDocumentFactory.create(standardConfigXml.toString()).getAsJDOMDocument();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);
  }
コード例 #2
0
  public void testServiceFailure() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();

    Role role = new Role();
    role.setName("testRole");
    User user = new User();
    user.addAutority(role);
    reqCtx.getRequest().getSession().setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);

    Page page = new Page();
    page.setCode("login");
    page.setGroup("free");
    page.setModel(new PageModel());

    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, page);

    Lang lang = new Lang();
    lang.setCode("it");
    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, lang);

    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setRemoteAddr("255.255.255.255");
    request.addHeader("Referer", "homeTest");
    request.addHeader("User-Agent", "Mio Test Browser");
    request.addHeader("accept-language", "sardo");

    int status = _statMonitor.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    this.deleteStatsRecord();
  }
コード例 #3
0
  @Test
  public void testAttemptAuthentication() throws IOException, ServletException {
    VistaBasicAuthenticationFilter f = new VistaBasicAuthenticationFilter();
    f.setAuthenticationManager(mockAuthenticationManager);
    f.setAuthenticationEntryPoint(authenticationEntryPoint);
    f.afterPropertiesSet();

    String vistaId = "9F2B";
    String division = "500";
    String accessCode = "10VEHU";
    String verifyCode = "VEHU10";

    byte[] token =
        new String(vistaId + ";" + division + ":" + accessCode + ";" + verifyCode)
            .getBytes("UTF-8");
    request.addHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token), "UTF-8"));
    request.setRemoteAddr("10.0.1.34");
    request.setRemoteHost("www.example.org");
    request.setRequestURI("/foo.xml");
    request.setMethod("GET");

    VistaAuthenticationToken authRequest =
        new VistaAuthenticationToken(
            "9F2B", "500", "10VEHU", "VEHU10", "10.0.1.34", "www.example.org");
    when(mockAuthenticationManager.authenticate(AuthenticationTokenMatchers.eq(authRequest)))
        .thenReturn(
            new VistaAuthenticationToken(
                new VistaUser(
                    new RpcHost("localhost"),
                    "9F2B",
                    "500",
                    "500",
                    "12345",
                    "500:10VEHU;VEHU10",
                    "Vehu,Ten",
                    true,
                    true,
                    true,
                    true,
                    new ArrayList<GrantedAuthority>()),
                "500:10VEHU;VEHU10",
                "10.0.1.34",
                null,
                new ArrayList<GrantedAuthority>()));

    f.doFilter(request, response, filterChain);

    assertSame(request, filterChain.getRequest());
    assertSame(response, filterChain.getResponse());

    verify(mockAuthenticationManager).authenticate(AuthenticationTokenMatchers.eq(authRequest));
  }
コード例 #4
0
  @Before
  public void before() throws IOException, JDOMException {
    factory = fixture.getFactory();
    fixture.initSystemData();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);

    createContentTypeXml();

    saveNeededEntities();

    UserEntity runningUser = fixture.findUserByName("testuser");
    PortalSecurityHolder.setImpersonatedUser(runningUser.getKey());

    createUpdateContent();
    createUpdateContentWithBinary();
  }
  /**
   * Test method for {@link
   * se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl#getAuditLogInfoContainer(java.lang.String,
   * java.lang.String, javax.portlet.PortletRequest)} .
   */
  @Test
  public final void testGetAuditLogInfoContainer() {
    MockPortletRequest portletRequest = new MockPortletRequest();

    Map<String, String> uInfoMap = new HashMap<String, String>();
    uInfoMap.put(PortletRequest.P3PUserInfos.USER_LOGIN_ID.toString(), "remoteUid");
    portletRequest.setAttribute(PortletRequest.USER_INFO, uInfoMap);

    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setRemoteAddr("127.0.0.1");
    httpRequest.setRemoteHost("remoteHost");
    httpRequest.setRemotePort(123);

    given(converter.getHttpServletRequest(portletRequest)).willReturn(httpRequest);

    AuditLogInfoContainer container = factory.getAuditLogInfoContainer("patientId", portletRequest);

    assertEquals("patientId", container.getPatientId());
    assertEquals("[LiferayUser:]remoteUid", container.getSearcherId());
    assertEquals("remoteUid", container.getRemoteUser());
    assertEquals("127.0.0.1 [Default]", container.getRemoteIpAddress());
    assertEquals("remoteHost", container.getRemoteHost());
    assertEquals(123, container.getRemotePort());
  }
コード例 #6
0
  @Before
  public void before() throws IOException, JDOMException {

    factory = fixture.getFactory();

    fixture.initSystemData();

    StringBuffer configXml = new StringBuffer();
    configXml.append("<config name=\"MyContentType\" version=\"1.0\">");
    configXml.append("     <form>");

    configXml.append("         <title name=\"myTitle\"/>");

    configXml.append("         <block name=\"General\">");

    configXml.append("             <input name=\"myTitle\" required=\"true\" type=\"text\">");
    configXml.append("                 <display>My title</display>");
    configXml.append("                 <xpath>contentdata/mytitle</xpath>");
    configXml.append("             </input>");

    configXml.append("         </block>");

    configXml.append("         <block name=\"Related content\">");

    configXml.append(
        "             <input name=\"myMultipleRelatedContent\" type=\"relatedcontent\" multiple=\"true\">");
    configXml.append("                 <display>My related content</display>");
    configXml.append("                 <xpath>contentdata/myrelatedcontents</xpath>");
    configXml.append("             </input>");

    configXml.append(
        "             <input name=\"mySoleRelatedContent\" type=\"relatedcontent\" multiple=\"false\">");
    configXml.append("                 <display>My sole related content</display>");
    configXml.append("                 <xpath>contentdata/mysolerelatedcontent</xpath>");
    configXml.append("                 <contenttype name=\"MyContentType\"/>");
    configXml.append("             </input>");

    configXml.append("         </block>");
    configXml.append("     </form>");
    configXml.append("</config>");
    configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();
    config = XMLDocumentFactory.create(configXml.toString()).getAsJDOMDocument();

    fixture.createAndStoreNormalUserWithUserGroup("testuser", "testuser fullname", "testuserstore");
    hibernateTemplate.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));
    hibernateTemplate.save(
        factory.createContentType(
            "MyContentType", ContentHandlerName.CUSTOM.getHandlerClassShortName(), config));
    hibernateTemplate.save(factory.createUnit("MyUnit"));
    hibernateTemplate.save(
        factory.createCategory(
            "MyCategory", null, "MyContentType", "MyUnit", "testuser", "testuser"));
    hibernateTemplate.save(
        factory.createCategoryAccess(
            "MyCategory", fixture.findUserByName("testuser"), "read, create, approve"));

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);
  }