Search in sources :

Example 1 with LdapAccount

use of com.zimbra.cs.account.ldap.entry.LdapAccount in project zm-mailbox by Zimbra.

the class LdapProvisioning method makeAccount.

private Account makeAccount(String dn, ZAttributes attrs, MakeObjectOpt makeObjOpt) throws ServiceException {
    String userType = attrs.getAttrString(Provisioning.A_zimbraAccountCalendarUserType);
    boolean isAccount = (userType == null) || userType.equals(AccountCalendarUserType.USER.toString());
    String emailAddress = attrs.getAttrString(Provisioning.A_zimbraMailDeliveryAddress);
    if (emailAddress == null)
        emailAddress = mDIT.dnToEmail(dn, attrs);
    Account acct = (isAccount) ? new LdapAccount(dn, emailAddress, attrs, null, this) : new LdapCalendarResource(dn, emailAddress, attrs, null, this);
    setAccountDefaults(acct, makeObjOpt);
    return acct;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) LdapCalendarResource(com.zimbra.cs.account.ldap.entry.LdapCalendarResource) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount)

Example 2 with LdapAccount

use of com.zimbra.cs.account.ldap.entry.LdapAccount in project zm-mailbox by Zimbra.

the class TestContactGroup method returnMembersAsDlist.

@Test
public void returnMembersAsDlist() throws Exception {
    Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    //TODO
    OperationContext octxt = null;
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_fileAs, ContactConstants.FA_FIRST_LAST);
    fields.put(ContactConstants.A_firstName, "test");
    fields.put(ContactConstants.A_email, "test1@zimbra.com");
    fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
    Contact contact = mbox.createContact(octxt, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    Account galMember = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user2"));
    LdapAccount ldapAccount = (LdapAccount) galMember;
    String dn = ldapAccount.getDN();
    String galEntryEmail = galMember.getName();
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, "" + contact.getId()), new MemberData(Member.Type.GAL_REF, dn), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
    contactGroup.derefAllMembers(mbox, octxt);
    for (Member member : contactGroup.getDerefedMembers()) {
        String memberKey = member.getDerefedKey();
        System.out.println(memberKey);
    }
    String dlist = contactGroup.migrateToDlist(mbox, octxt);
    // should be in member order
    assertEquals("test1@zimbra.com, test2@zimbra.com, " + galEntryEmail + ", aaa@test.com, zzz@test.com", dlist);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 3 with LdapAccount

use of com.zimbra.cs.account.ldap.entry.LdapAccount in project zm-mailbox by Zimbra.

the class TestLdapProvDynamicGroup method memberAttrViaSlapdOverlay.

/*
     * Test member attr, which is populated by OpenLDAP dyngroup overlay
     */
@Test
public void memberAttrViaSlapdOverlay() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DYNAMIC_GROUP_OVERLAY);
    Group group = createDynamicGroup(genGroupNameLocalPart());
    Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName() });
    group = prov.getGroup(DistributionListBy.id, group.getId());
    String[] memberDNs = group.getMultiAttr(Provisioning.A_member);
    Set<String> expected = Sets.newHashSet(((LdapAccount) acct1).getDN(), ((LdapAccount) acct2).getDN(), // LdapProvisioning.DYNAMIC_GROUP_STATIC_UNIT_NAME
    "cn=external," + ((LdapDynamicGroup) group).getDN());
    Verify.verifyEquals(expected, memberDNs);
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) Test(org.junit.Test)

Example 4 with LdapAccount

use of com.zimbra.cs.account.ldap.entry.LdapAccount in project zm-mailbox by Zimbra.

the class TestContactGroup method derefGal.

@Test
public void derefGal() throws Exception {
    Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    //TODO
    OperationContext octxt = null;
    Account galMember = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user2"));
    LdapAccount ldapAccount = (LdapAccount) galMember;
    String dn = ldapAccount.getDN();
    String email = galMember.getName();
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.GAL_REF, dn), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
    contactGroup.derefAllMembers(mbox, octxt);
    boolean gotGalRefMember = false;
    String prevMemberKey = null;
    for (Member member : contactGroup.getDerefedMembers()) {
        String memberKey = member.getDerefedKey();
        if (prevMemberKey != null) {
            assertTrue(prevMemberKey.compareTo(memberKey) < 0);
        }
        prevMemberKey = memberKey;
        Member.Type type = member.getType();
        if (type == Member.Type.GAL_REF) {
            assertEquals(email, memberKey);
            gotGalRefMember = true;
        }
    // System.out.println(memberKey);
    }
    List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
    assertEquals(3, emailAddrs.size());
    assertTrue(emailAddrs.contains(email));
    assertTrue(emailAddrs.contains("aaa@test.com"));
    assertTrue(emailAddrs.contains("zzz@test.com"));
    assertTrue(gotGalRefMember);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)4 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)4 Test (org.junit.Test)3 ZMailbox (com.zimbra.client.ZMailbox)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)2 ContactRefMember (com.zimbra.cs.mailbox.ContactGroup.ContactRefMember)2 GalRefMember (com.zimbra.cs.mailbox.ContactGroup.GalRefMember)2 InlineMember (com.zimbra.cs.mailbox.ContactGroup.InlineMember)2 Member (com.zimbra.cs.mailbox.ContactGroup.Member)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1 Group (com.zimbra.cs.account.Group)1 LdapCalendarResource (com.zimbra.cs.account.ldap.entry.LdapCalendarResource)1 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)1 Contact (com.zimbra.cs.mailbox.Contact)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 HashMap (java.util.HashMap)1