Search in sources :

Example 1 with AuthenticatorFactory

use of com.zimbra.cs.mailclient.auth.AuthenticatorFactory in project zm-mailbox by Zimbra.

the class ImapConnection method getZimbraConnection.

public static ImapConnection getZimbraConnection(Server server, String userName, AuthToken authToken) throws ServiceException {
    Account acct = Provisioning.getInstance().get(AccountBy.adminName, userName);
    AuthenticatorFactory authFactory = new AuthenticatorFactory();
    authFactory.register(ZimbraAuthenticator.MECHANISM, ZimbraClientAuthenticator.class);
    ImapConfig config = new ImapConfig(server.getServiceHostname());
    config.setMechanism(ZimbraAuthenticator.MECHANISM);
    config.setAuthenticatorFactory(authFactory);
    config.setPort(server.getRemoteImapBindPort());
    config.setAuthenticationId(acct.getName());
    ImapConnection connection = new ImapConnection(config);
    try {
        connection.connect();
        connection.authenticate(authToken.getEncoded());
    } catch (IOException | LoginException | AuthTokenException e) {
        throw ServiceException.FAILURE("unable to create an IMAP connection as zimbra user", e);
    }
    return connection;
}
Also used : Account(com.zimbra.cs.account.Account) AuthTokenException(com.zimbra.cs.account.AuthTokenException) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) AuthenticatorFactory(com.zimbra.cs.mailclient.auth.AuthenticatorFactory)

Example 2 with AuthenticatorFactory

use of com.zimbra.cs.mailclient.auth.AuthenticatorFactory in project zm-mailbox by Zimbra.

the class MailClient method isPasswordRequired.

private boolean isPasswordRequired() {
    String mech = config.getMechanism();
    if (mech == null) {
        return true;
    }
    AuthenticatorFactory af = config.getAuthenticatorFactory();
    return af != null && af.isPasswordRequired(mech);
}
Also used : AuthenticatorFactory(com.zimbra.cs.mailclient.auth.AuthenticatorFactory)

Example 3 with AuthenticatorFactory

use of com.zimbra.cs.mailclient.auth.AuthenticatorFactory in project zm-mailbox by Zimbra.

the class ImapTestBase method getAdminConnection.

protected ImapConnection getAdminConnection() throws Exception {
    AuthenticatorFactory authFactory = new AuthenticatorFactory();
    authFactory.register(ZimbraAuthenticator.MECHANISM, ZimbraClientAuthenticator.class);
    ImapConfig config = new ImapConfig(imapServer.getServiceHostname());
    config.setMechanism(ZimbraAuthenticator.MECHANISM);
    config.setAuthenticatorFactory(authFactory);
    config.setPort(imapPort);
    config.setAuthenticationId(LC.zimbra_ldap_user.value());
    config.getLogger().setLevel(Log.Level.trace);
    ImapConnection conn = new ImapConnection(config);
    conn.connect();
    conn.authenticate(AuthProvider.getAdminAuthToken().getEncoded());
    return conn;
}
Also used : ImapConfig(com.zimbra.cs.mailclient.imap.ImapConfig) AuthenticatorFactory(com.zimbra.cs.mailclient.auth.AuthenticatorFactory) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection)

Example 4 with AuthenticatorFactory

use of com.zimbra.cs.mailclient.auth.AuthenticatorFactory in project zm-mailbox by Zimbra.

the class TestImapViaImapDaemon method testZimbraCommandsNonAdminUser.

@Test
public void testZimbraCommandsNonAdminUser() throws Exception {
    Account acct = TestUtil.getAccount(USER);
    AuthenticatorFactory authFactory = new AuthenticatorFactory();
    authFactory.register(ZimbraAuthenticator.MECHANISM, ZimbraClientAuthenticator.class);
    ImapConfig config = new ImapConfig(imapHostname);
    config.setMechanism(ZimbraAuthenticator.MECHANISM);
    config.setAuthenticatorFactory(authFactory);
    config.setPort(imapPort);
    config.setAuthenticationId(acct.getName());
    config.getLogger().setLevel(Log.Level.trace);
    ImapConnection conn = new ImapConnection(config);
    conn.connect();
    conn.authenticate(AuthProvider.getAuthToken(acct).getEncoded());
    try {
        conn.reloadLocalConfig();
        fail("should not be able to run X-ZIMBRA-RELOADLC command with a non-admin auth token");
    } catch (CommandFailedException cfe) {
        assertEquals("must be authenticated as admin with X-ZIMBRA auth mechanism", cfe.getError());
    }
    try {
        conn.flushCache("all");
        fail("should not be able to run X-ZIMBRA-FLUSHCACHE command with a non-admin auth token");
    } catch (CommandFailedException cfe) {
        assertEquals("must be authenticated as admin with X-ZIMBRA auth mechanism", cfe.getError());
    }
}
Also used : Account(com.zimbra.cs.account.Account) ImapConfig(com.zimbra.cs.mailclient.imap.ImapConfig) AuthenticatorFactory(com.zimbra.cs.mailclient.auth.AuthenticatorFactory) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Aggregations

AuthenticatorFactory (com.zimbra.cs.mailclient.auth.AuthenticatorFactory)4 Account (com.zimbra.cs.account.Account)2 ImapConfig (com.zimbra.cs.mailclient.imap.ImapConfig)2 ImapConnection (com.zimbra.cs.mailclient.imap.ImapConnection)2 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 IOException (java.io.IOException)1 LoginException (javax.security.auth.login.LoginException)1 Test (org.junit.Test)1