@BeforeClass public static void init() throws Exception { MailboxTestUtil.initServer(); Provisioning prov = Provisioning.getInstance(); prov.createAccount("*****@*****.**", "secret", new HashMap<String, Object>()); Provisioning.setInstance(prov); }
@BeforeClass public static void init() throws Exception { MailboxTestUtil .initServer(); // TODO: allow paths to be specified so we can run tests outside of // ZimbraServer MailboxManager.setInstance( new MailboxManager() { @Override protected Mailbox instantiateMailbox(MailboxData data) { // mock the behaviors we need to test in DesktopMailbox return new Mailbox(data) { @Override protected boolean needRedo(OperationContext octxt, RedoableOp recorder) { return false; } }; } // TODO: eventually move this into ZimbraOffline and implement all of the provisioning // needed for real DesktopMailbox // try { // return new DesktopMailbox(data) { // }; // } catch (ServiceException e) { // throw new RuntimeException(e); // } }); Provisioning prov = Provisioning.getInstance(); prov.createAccount("*****@*****.**", "secret", new HashMap<String, Object>()); }
private Account createAccount() throws Exception { Domain domain = getDomain(); Cos cos = getCos(); HashMap<String, Object> attrs = new HashMap<String, Object>(); attrs.put(Provisioning.A_zimbraCOSId, cos.getId()); Account acct = prov.createAccount(ACCT_EMAIL, PASSWORD, attrs); assertNotNull(acct); return acct; }
@Test public void messageID() throws Exception { Provisioning prov = Provisioning.getInstance(); Domain domain = prov.createDomain("example.com", new HashMap<String, Object>()); Account account = prov.createAccount("*****@*****.**", "test123", new HashMap<String, Object>()); MimeMessage mm = new MimeMessage(JMSession.getSmtpSession(account)); mm.saveChanges(); Assert.assertEquals( "message ID contains account domain", domain.getName() + '>', mm.getMessageID().split("@")[1]); }
public static Account createAccount(SearchResult entry, String defaultDomainName) throws ServiceException { Account acct = null; Provisioning prov = Provisioning.getInstance(); try { Attributes attributes = entry.getAttributes(); String givenName = attributes.get("givenName").get(0).toString(); String name = attributes.get("name").get(0).toString(); String sn = ""; try { sn = attributes.get("sn").get(0).toString(); } catch (NullPointerException npe) { } String userPrincipalName = attributes.get("userPrincipalName").get(0).toString(); String mail = ""; try { mail = attributes.get("mail").get(0).toString(); } catch (NullPointerException npe) { } String sAMAccountName = attributes.get("sAMAccountName").get(0).toString(); String parts[] = EmailUtil.getLocalPartAndDomain(userPrincipalName); if (parts == null) { return null; } // return if the user domain name is not our default domain name if (!defaultDomainName.equals(parts[1])) { ZimbraLog.account.info("[ADUser] User %s is not in our default domain", userPrincipalName); return null; } String mailAccount = parts[0]; String mailparts[] = EmailUtil.getLocalPartAndDomain(mail); if (mailparts != null) { mailAccount = mailparts[0]; } ZimbraLog.account.info( "[ADUser] Creating user: %s '%s' <%s@%s>", givenName, name, sAMAccountName, defaultDomainName); HashMap attrs = new HashMap(); attrs.put(Provisioning.A_givenName, givenName); if (!sn.equals("")) { attrs.put(Provisioning.A_sn, sn); } attrs.put(Provisioning.A_cn, name); attrs.put(Provisioning.A_displayName, name); attrs.put(Provisioning.A_zimbraMailStatus, Provisioning.MAIL_STATUS_ENABLED); acct = prov.createAccount(userPrincipalName, "AUTOPROVISIONED", attrs); if (!mailAccount.equals(sAMAccountName)) { ZimbraLog.account.info( "[ADUser] Creating alias <%s@%s> for user %s", mailAccount, defaultDomainName, sAMAccountName); prov.addAlias(acct, mail); } } catch (NamingException ex) { ZimbraLog.account.info("[ADUser] Unable to fetch attributes from AD for the user %s", ex); } return acct; }