Search in sources :

Example 26 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class JMSessionTest method messageID.

@Test
public void messageID() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    Domain domain = prov.createDomain("example.com", new HashMap<String, Object>());
    Account account = prov.createAccount("user1@example.com", "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]);
}
Also used : Account(com.zimbra.cs.account.Account) MimeMessage(javax.mail.internet.MimeMessage) Domain(com.zimbra.cs.account.Domain) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Test(org.junit.Test)

Example 27 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class JWTBasedAuthTest method testZimbraQoSFilterExtractUserId.

@Test
public void testZimbraQoSFilterExtractUserId() {
    HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
    Cookie[] cookies = new Cookie[1];
    String salt = "s1";
    Cookie cookie = new Cookie("ZM_JWT", salt);
    cookie.setHttpOnly(true);
    cookies[0] = cookie;
    try {
        Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
        String jwt = generateJWT(acct, salt);
        EasyMock.expect(req.getCookies()).andReturn(cookies);
        EasyMock.expectLastCall().times(2);
        EasyMock.expect(req.getHeader(Constants.AUTH_HEADER)).andReturn("Bearer " + jwt);
        int port = 7071;
        EasyMock.expect(req.getLocalPort()).andReturn(port);
        EasyMock.replay(req);
        String accountId = ZimbraQoSFilter.extractUserId(req);
        Assert.assertEquals(acct.getId(), accountId);
    } catch (ServiceException | AuthTokenException e) {
        e.printStackTrace();
        Assert.fail("testZimbraQoSFilterExtractUserId failed");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) Test(org.junit.Test)

Example 28 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class JWTBasedAuthTest method testGetJWToken.

@Test
public void testGetJWToken() {
    Account acct;
    try {
        acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
        String salt = "s1";
        String salts = "s2|s3|s1";
        AuthTokenKey atkey = AuthTokenUtil.getCurrentKey();
        byte[] jwtKey = Bytes.concat(atkey.getKey(), salt.getBytes());
        long issuedAt = System.currentTimeMillis();
        long expires = issuedAt + 3600000;
        AuthTokenProperties properties = new AuthTokenProperties(acct, true, null, expires, AuthMech.zimbra, Usage.AUTH);
        String jwt = JWTUtil.generateJWT(jwtKey, salt, issuedAt, properties, atkey.getVersion());
        AuthToken at = ZimbraJWToken.getJWToken(jwt, salts);
        Assert.assertEquals(acct.getId(), at.getAccountId());
        Assert.assertEquals(Usage.AUTH, at.getUsage());
        Assert.assertEquals(expires / 1000, at.getExpires() / 1000);
        Assert.assertEquals(AuthMech.zimbra, at.getAuthMech());
        Assert.assertEquals(false, at.isAdmin());
    } catch (ServiceException | AuthTokenException e) {
        e.printStackTrace();
        Assert.fail("testGenerateAndValidateJWT failed");
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) AuthTokenProperties(com.zimbra.cs.account.AuthTokenProperties) AuthTokenException(com.zimbra.cs.account.AuthTokenException) AuthToken(com.zimbra.cs.account.AuthToken) AuthTokenKey(com.zimbra.cs.account.AuthTokenKey) Test(org.junit.Test)

Example 29 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class JWTBasedAuthTest method testUserServletJWTFlowWithJWTQueryParam.

@Test
public void testUserServletJWTFlowWithJWTQueryParam() {
    try {
        Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
        UserServletContext context = mockServletConext(acct, true);
        UserServletUtil.getAccount(context);
        Assert.assertNotNull(context.authToken);
        Assert.assertEquals(acct.getId(), context.authToken.getAccountId());
    } catch (ServiceException | AuthTokenException | IOException | ServletException | UserServletException e1) {
        e1.printStackTrace();
        Assert.fail("testUserServletJWTFlow failed");
    }
}
Also used : ServletException(javax.servlet.ServletException) UserServletException(com.zimbra.cs.service.UserServletException) Account(com.zimbra.cs.account.Account) UserServletContext(com.zimbra.cs.service.UserServletContext) ServiceException(com.zimbra.common.service.ServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) UserServletException(com.zimbra.cs.service.UserServletException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class JWTBasedAuthTest method testAccountAndUsageJWT.

@Test
public void testAccountAndUsageJWT() {
    Account acct;
    try {
        acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
        AuthToken at = AuthProvider.getAuthToken(acct, Usage.TWO_FACTOR_AUTH, TokenType.JWT);
        validateJWT(at, acct.getId());
    } catch (ServiceException e) {
        Assert.fail("testAccountAndUsageJWT failed");
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) AuthToken(com.zimbra.cs.account.AuthToken) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)1444 Test (org.junit.Test)691 Mailbox (com.zimbra.cs.mailbox.Mailbox)468 OperationContext (com.zimbra.cs.mailbox.OperationContext)354 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)331 Message (com.zimbra.cs.mailbox.Message)315 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)294 Element (com.zimbra.common.soap.Element)280 ServiceException (com.zimbra.common.service.ServiceException)261 ItemId (com.zimbra.cs.service.util.ItemId)248 Provisioning (com.zimbra.cs.account.Provisioning)234 HashMap (java.util.HashMap)179 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)175 Domain (com.zimbra.cs.account.Domain)149 MimeMessage (javax.mail.internet.MimeMessage)125 GuestAccount (com.zimbra.cs.account.GuestAccount)107 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)100 SyntaxException (org.apache.jsieve.exception.SyntaxException)90 AccountServiceException (com.zimbra.cs.account.AccountServiceException)87 Header (javax.mail.Header)84