/**
   * Test method for {@link
   * se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl#getAuditLogInfoContainer(java.lang.String,
   * java.lang.String, javax.portlet.PortletRequest)} .
   */
  @Test
  public final void testGetAuditLogInfoContainerUserFromLdap() {
    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();

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

    LdapUser ldapUser = new SimpleLdapUser("dn");
    ldapUser.setAttributeValue("cn", "searcherId");
    given(ldapService.getLdapUserByUid("remoteUid")).willReturn(ldapUser);

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

    assertEquals("searcherId", container.getSearcherId());
  }
コード例 #2
0
  private Person findOrCreateEnabledPersonForCurrentPortletUser(final PortletRequest req)
      throws UserNotEnabledException, UnableToCreateAccountException {
    Person person = null;
    @SuppressWarnings("unchecked")
    Map<String, String> userInfo = (Map<String, String>) req.getAttribute(PortletRequest.USER_INFO);
    String username = null;
    if (userInfo != null) {
      username = userInfo.get(PortletRequest.P3PUserInfos.USER_LOGIN_ID.toString());
    }
    username = StringUtils.isNotBlank(username) ? username : req.getRemoteUser();
    if (!(StringUtils.isNotBlank(username))) {
      throw new IllegalArgumentException("Cannot lookup nor create an account without a username");
    }

    try {
      person = findEnabledPersonByUsernameOrFail(username);
    } catch (ObjectNotFoundException e) {
      try {
        return personService.createUserAccountForCurrentPortletUser(username, req);
      } catch (ObjectExistsException ee) {
        try {
          person = findEnabledPersonByUsernameOrFail(username);
        } catch (ObjectNotFoundException eee) {
          throw new UnableToCreateAccountException(
              "Couldn't create account with username"
                  + username
                  + " because an account with that username seemed"
                  + " to already exist, but was unable to load that"
                  + " existing account.",
              eee);
        } // UserNotEnabledException is helpfully descriptive so just
        // let it bubble up
      }
    }
    return person;
  }
  /**
   * 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());
  }