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;
}
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);
}
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;
}
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());
}
}
Aggregations