Beispiel #1
0
  public void testAddUser() throws Exception {
    List<Map<String, String>> items = new ArrayList<Map<String, String>>();

    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User user = new User();
    user.setPermissionManager(pm);

    Group g = new Group();
    PermissionName.INTERNATIONAL_DIALING.setEnabled(g, false);
    PermissionName.LONG_DISTANCE_DIALING.setEnabled(g, false);
    PermissionName.TOLL_FREE_DIALING.setEnabled(g, false);
    PermissionName.LOCAL_DIALING.setEnabled(g, true);
    PermissionName.SIPX_VOICEMAIL.setEnabled(g, false);
    PermissionName.FREESWITH_VOICEMAIL.setEnabled(g, false);
    PermissionName.EXCHANGE_VOICEMAIL.setEnabled(g, true);

    user.addGroup(g);
    user.setUserName("goober");

    Permissions permissions = new Permissions();
    permissions.addUser(items, user, "sipx.sipfoundry.org");

    assertEquals(PERM_COUNT, items.size());
    assertEquals("sip:[email protected]", items.get(0).get("identity"));
    assertEquals("LocalDialing", items.get(0).get("permission"));

    assertEquals("sip:[email protected]", items.get(3).get("identity"));
    assertEquals("ExchangeUMVoicemailServer", items.get(3).get("permission"));

    assertEquals("sip:[email protected]", items.get(4).get("identity"));
    assertEquals("ExchangeUMVoicemailServer", items.get(4).get("permission"));
  }
Beispiel #2
0
  public IPage commit(IRequestCycle cycle) {
    if (!TapestryUtils.isValid(this)) {
      return null;
    }
    // Save the user
    CoreContext core = getCoreContext();
    User user = getUser();
    user.setImId(user.getUserName());
    EditUser.saveGroups(getSettingDao(), user.getGroups());

    // Execute the automatic assignments for the user.
    GroupAutoAssign groupAutoAssign =
        new GroupAutoAssign(
            getConferenceBridgeContext(), getCoreContext(),
            getForwardingContext(), getMailboxManager());
    groupAutoAssign.assignUserData(user);

    // On saving the user, transfer control to edituser page.
    if (FormActions.APPLY.equals(getButtonPressed())) {
      EditUser edit = (EditUser) cycle.getPage(EditUser.PAGE);
      edit.setUserId(user.getId());
      return edit;
    }

    return null;
  }
Beispiel #3
0
 public void toMyObject(Object myObject, Object apiObject, Set properties) {
   super.toMyObject(myObject, apiObject, properties);
   org.sipfoundry.sipxconfig.common.User my = (org.sipfoundry.sipxconfig.common.User) myObject;
   User api = (User) apiObject;
   if (properties.contains(ALIASES_PROP) && api.getAliases() != null) {
     my.copyAliases(Arrays.asList(api.getAliases()));
   }
 }
Beispiel #4
0
 public String getUserName() {
   UserSession userSession = getUserSession();
   if (!userSession.isLoggedIn()) {
     return StringUtils.EMPTY;
   }
   User user = userSession.getUser(getCoreContext());
   return user.getLabel();
 }
Beispiel #5
0
 @SettingEntry(path = REG_DISPLAY_NAME)
 public String getDisplayName() {
   String displayName = null;
   User user = m_line.getUser();
   if (user != null) {
     displayName = user.getDisplayName();
   }
   return displayName;
 }
Beispiel #6
0
 public Line findByUsername(String username) {
   for (Line l : getLines()) {
     User user = l.getUser();
     if (user != null && user.getUserName().equals(username)) {
       return l;
     }
   }
   return null;
 }
Beispiel #7
0
 @SettingEntry(paths = {REG_USERNAME, REG_AUTH_USERNAME})
 public String getUserName() {
   String userName = null;
   User user = m_line.getUser();
   if (user != null) {
     userName = user.getUserName();
   }
   return userName;
 }
Beispiel #8
0
 @SettingEntry(path = REG_PASSWORD)
 public String getPassword() {
   String password = null;
   User user = m_line.getUser();
   if (user != null) {
     password = user.getSipPassword();
   }
   return password;
 }
Beispiel #9
0
 public void pageBeginRender(PageEvent event) {
   User user = getUser();
   if (user == null) {
     user = getCoreContext().newUser();
     user.setSipPassword(RandomStringUtils.randomAlphanumeric(SIP_PASSWORD_LEN));
     user.setVoicemailPin(RandomStringUtils.random(VOICEMAIL_PIN_LEN, false, true));
     user.setPin(RandomStringUtils.randomAlphabetic(PASSWORD_LEN));
     setUser(user);
     UserForm.initializePin(getComponent(USER_FORM).getComponent("pin"), this, user);
     UserForm.initializeVoicemailPin(
         getComponent(USER_FORM).getComponent("voicemail_pin"), this, user);
   }
 }
Beispiel #10
0
  public void testCallGroupPerms() throws Exception {
    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User testUser = new User();
    testUser.setPermissionManager(pm);

    CoreContext coreContext = createMock(CoreContext.class);
    coreContext.getDomainName();
    expectLastCall().andReturn("host.company.com");
    coreContext.loadUsersByPage(null, null, null, 0, DaoUtils.PAGE_SIZE, "id", true);
    expectLastCall().andReturn(Collections.EMPTY_LIST);
    coreContext.newUser();
    expectLastCall().andReturn(testUser).anyTimes();

    CallGroup callGroup1 = new CallGroup();
    callGroup1.setName("sales");
    callGroup1.setEnabled(true);
    CallGroup callGroup2 = new CallGroup();
    callGroup2.setName("marketing");
    callGroup2.setEnabled(true);
    CallGroup callGroup3 = new CallGroup();
    callGroup3.setName("disabled");

    CallGroupContext callGroupContext = createMock(CallGroupContext.class);
    callGroupContext.getCallGroups();
    expectLastCall().andReturn(Arrays.asList(callGroup1, callGroup2, callGroup3));

    replay(coreContext, callGroupContext);

    Permissions permissions = new Permissions();
    permissions.setCoreContext(coreContext);
    permissions.setCallGroupContext(callGroupContext);

    List<Map<String, String>> items = permissions.generate();

    int start = SPEC_COUNT * PERM_COUNT;

    assertEquals(start + 10, items.size());

    assertEquals("sip:[email protected]", items.get(start + 0).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 4).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 5).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 9).get("identity"));

    verify(coreContext, callGroupContext);
  }
  private void savePersonalAttendant(User user) {
    getMailboxPreferences().updateUser(user);
    MailboxManager mailMgr = getMailboxManager();
    mailMgr.storePersonalAttendant(getPersonalAttendant());

    user.getSettings().getSetting(OPERATOR_SETTING).setValue(getPersonalAttendant().getOperator());
    getCoreContext().saveUser(user);
  }
Beispiel #12
0
 public void toApiObject(Object apiObject, Object myObject, Set properties) {
   super.toApiObject(apiObject, myObject, properties);
   org.sipfoundry.sipxconfig.common.User my = (org.sipfoundry.sipxconfig.common.User) myObject;
   User api = (User) apiObject;
   if (properties.contains(ALIASES_PROP) && !StringUtils.isBlank(my.getAliasesString())) {
     api.setAliases(my.getAliases().toArray(new String[0]));
   }
   if (properties.contains(GROUPS_PROP)) {
     Collection groupNames = CollectionUtils.collect(my.getGroups(), new NamedObject.ToName());
     api.setGroups((String[]) groupNames.toArray(new String[groupNames.size()]));
   }
   if (properties.contains(PERMISSIONS_PROP)) {
     Collection<String> permNames = my.getUserPermissionNames();
     if (!permNames.isEmpty()) {
       api.setPermissions(permNames.toArray(new String[permNames.size()]));
     }
   }
 }
 List<RegistrationItem> getRegistrationsByUser(List<RegistrationItem> registrations, User user) {
   List<RegistrationItem> result = new ArrayList<RegistrationItem>();
   for (RegistrationItem registration : registrations) {
     if (SipUri.extractUser(registration.getUri()).equals(user.getUserName())) {
       result.add(registration);
     }
   }
   return result;
 }
  private StandardUserDetailsService getUserDetailsTestService(CoreContext ctx, boolean imEnabled) {
    User u =
        new User() {
          @Override
          public boolean hasPermission(PermissionName permission) {
            return true;
          }
        };
    u.setUserName(USER_NAME);
    u.setUniqueId();
    AddressBookEntry abe = new AddressBookEntry();
    abe.setImId(USER_IM_ID);
    u.setAddressBookEntry(abe);
    u.setSettings(TestHelper.loadSettings("commserver/user-settings.xml"));
    u.setSettingTypedValue("im/im-account", imEnabled);

    AcdContext acdContext = createMock(AcdContext.class);
    StandardUserDetailsService uds = new StandardUserDetailsService();
    uds.setCoreContext(ctx);
    uds.setAcdContext(acdContext);

    ctx.loadUserByUserNameOrAlias(USER_IM_ID);
    expectLastCall().andReturn(null);

    ctx.loadUserByConfiguredImId(USER_IM_ID);
    expectLastCall().andReturn(u);

    acdContext.getUsersWithAgents();
    expectLastCall().andReturn(Collections.emptyList());

    replay(ctx, acdContext);
    return uds;
  }
  private OpenAcdAgent createOpenAcdAgent(OpenAcdAgentRestInfoFull agentRestInfo)
      throws ResourceException {
    OpenAcdAgent agent = new OpenAcdAgent();
    OpenAcdAgent duplicateAgent = null;
    User user;

    // set associated user
    user = m_coreContext.getUser(agentRestInfo.getUserId());

    // check if user is already assigned as agent
    duplicateAgent = m_openAcdContext.getAgentByUser(user);
    if (duplicateAgent != null) {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "User " + user.getId() + " already assigned as agent.");
    }

    agent.setUser(user);

    updateAgent(agent, agentRestInfo);

    return agent;
  }
Beispiel #16
0
  public void testGenerateEmpty() throws Exception {
    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User testUser = new User();
    testUser.setPermissionManager(pm);

    CoreContext coreContext = createMock(CoreContext.class);
    coreContext.getDomainName();
    expectLastCall().andReturn("host.company.com");
    coreContext.loadUsersByPage(null, null, null, 0, DaoUtils.PAGE_SIZE, "id", true);
    expectLastCall().andReturn(Collections.EMPTY_LIST);
    coreContext.newUser();
    expectLastCall().andReturn(testUser).anyTimes();

    CallGroupContext callGroupContext = createMock(CallGroupContext.class);
    callGroupContext.getCallGroups();
    expectLastCall().andReturn(Collections.EMPTY_LIST);

    replay(coreContext, callGroupContext);

    Permissions permissions = new Permissions();
    permissions.setCoreContext(coreContext);
    permissions.setCallGroupContext(callGroupContext);

    List<Map<String, String>> items = permissions.generate();
    assertEquals(SPEC_COUNT * PERM_COUNT, items.size());
    // 5 permissions per special user

    for (SpecialUserType su : SpecialUserType.values()) {
      int i = su.ordinal();

      String name = "sip:" + su.getUserName() + "@host.company.com";
      assertEquals(name, items.get(i * PERM_COUNT).get("identity"));
      assertEquals(name, items.get((i + 1) * PERM_COUNT - 1).get("identity"));
    }
    verify(coreContext, callGroupContext);
  }
  public void testLoadUserByUsername() {
    User u =
        new User() {
          @Override
          public boolean hasPermission(PermissionName permission) {
            return true;
          }
        };
    u.setUserName(USER_NAME);
    u.setUniqueId();

    CoreContext coreContext = createMock(CoreContext.class);
    AcdContext acdContext = createMock(AcdContext.class);
    StandardUserDetailsService uds = new StandardUserDetailsService();
    uds.setCoreContext(coreContext);
    uds.setAcdContext(acdContext);

    coreContext.loadUserByUserNameOrAlias(USER_NAME);
    expectLastCall().andReturn(u);

    acdContext.getUsersWithAgents();
    expectLastCall().andReturn(Collections.emptyList());
    replay(coreContext, acdContext);

    // load the user details
    UserDetails details = uds.loadUserByUsername(USER_NAME);
    assertEquals(USER_NAME, details.getUsername());
    GrantedAuthority[] authorities = details.getAuthorities();

    assertTrue(contains(authorities, UserRole.Admin.toAuth()));
    assertTrue(contains(authorities, UserRole.User.toAuth()));
    assertFalse(contains(authorities, UserRole.AcdAgent.toAuth()));
    assertFalse(contains(authorities, UserRole.AcdSupervisor.toAuth()));
    assertTrue(contains(authorities, UserRole.AttendantAdmin.toAuth()));

    verify(coreContext, acdContext);
  }
Beispiel #18
0
 public CdrsStatementCreator(
     Date from, Date to, CdrSearch search, User user, TimeZone tz, int limit, int offset) {
   m_calendar = Calendar.getInstance(tz);
   long fromMillis = from != null ? from.getTime() : 0;
   m_from = new Timestamp(fromMillis);
   long toMillis = to != null ? to.getTime() : System.currentTimeMillis();
   m_to = new Timestamp(toMillis);
   m_search = search;
   m_limit = limit;
   m_offset = offset;
   if (user != null) {
     m_forUser = new CdrSearch();
     m_forUser.setMode(CdrSearch.Mode.ANY);
     m_forUser.setTerm(user.getUserName());
   }
 }
 public MailboxPreferences(User user) {
   m_emailAddress = user.getEmailAddress();
   m_alternateEmailAddress = user.getAlternateEmailAddress();
   m_activeGreeting = ActiveGreeting.fromId((user.getSettingValue(ACTIVE_GREETING)));
   m_busyPrompt = user.getSettingValue(BUSY_PROMPT);
   m_voicemailTui = VoicemailTuiType.fromValue(user.getSettingValue(VOICEMAIL_TUI));
   m_externalMwi = user.getSettingValue(EXTERNAL_MWI);
   m_attachVoicemailToEmail =
       AttachType.fromValue(user.getSettingValue(PRIMARY_EMAIL_NOTIFICATION));
   m_emailFormat = MailFormat.valueOf(user.getSettingValue(PRIMARY_EMAIL_FORMAT));
   m_alternateEmailFormat = MailFormat.valueOf(user.getSettingValue(ALT_EMAIL_FORMAT));
   m_voicemailToAlternateEmailNotification =
       AttachType.fromValue(user.getSettingValue(ALT_EMAIL_NOTIFICATION));
   m_imapHost = user.getSettingValue(IMAP_HOST);
   m_imapPort = user.getSettingValue(IMAP_PORT);
   m_imapTLS = (Boolean) user.getSettingTypedValue(IMAP_TLS);
   m_imapPassword = user.getSettingValue(IMAP_PASSWORD);
   m_imapAccount = user.getSettingValue(IMAP_ACCOUNT);
   m_includeAudioAttachment = (Boolean) user.getSettingTypedValue(PRIMARY_EMAIL_ATTACH_AUDIO);
   m_includeAudioAttachmentAlternateEmail =
       (Boolean) user.getSettingTypedValue(ALT_EMAIL_ATTACH_AUDIO);
 }
 public void updateUser(User user) {
   user.setEmailAddress(m_emailAddress);
   user.setAlternateEmailAddress(m_alternateEmailAddress);
   user.setSettingValue(ACTIVE_GREETING, m_activeGreeting.getId());
   user.setSettingValue(BUSY_PROMPT, m_busyPrompt);
   user.setSettingValue(VOICEMAIL_TUI, m_voicemailTui.getValue());
   user.setSettingValue(EXTERNAL_MWI, m_externalMwi);
   user.setSettingValue(PRIMARY_EMAIL_NOTIFICATION, m_attachVoicemailToEmail.getValue());
   user.setSettingValue(PRIMARY_EMAIL_FORMAT, m_emailFormat.name());
   user.setSettingValue(ALT_EMAIL_FORMAT, m_alternateEmailFormat.name());
   user.setSettingValue(
       ALT_EMAIL_NOTIFICATION, m_voicemailToAlternateEmailNotification.getValue());
   user.setSettingValue(IMAP_HOST, m_imapHost);
   user.setSettingValue(IMAP_PORT, m_imapPort);
   user.setSettingTypedValue(IMAP_TLS, m_imapTLS);
   user.setSettingValue(IMAP_PASSWORD, m_imapPassword);
   user.setSettingValue(IMAP_ACCOUNT, m_imapAccount);
   user.setSettingTypedValue(PRIMARY_EMAIL_ATTACH_AUDIO, m_includeAudioAttachment);
   user.setSettingTypedValue(ALT_EMAIL_ATTACH_AUDIO, m_includeAudioAttachmentAlternateEmail);
 }
Beispiel #21
0
 protected void addUser(
     List<Map<String, String>> items, User user, String domainName, String realm) {
   String uri = user.getUri(domainName);
   String sipPasswordHash = user.getSipPasswordHash(realm);
   addCredentialsItem(items, uri, user.getUserName(), sipPasswordHash, user.getPintoken(), realm);
 }
 public File getUserAudioDirectory(User user) {
   File userAudioDirectory =
       new File(m_audioDirectory + System.getProperty("file.separator") + user.getName());
   ensureDirectoryExists(userAudioDirectory.getPath());
   return userAudioDirectory;
 }