Package org.ametys.plugins.zimbra
Class ZimbraConnector
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.messagingconnector.AbstractMessagingConnector
-
- org.ametys.plugins.zimbra.ZimbraConnector
-
- All Implemented Interfaces:
MessagingConnector
,LogEnabled
,Disposable
,Initializable
,Component
,Serviceable
public class ZimbraConnector extends AbstractMessagingConnector implements Disposable
The connector used by the messaging connector plugin when the zimbra mail server is used. Implements the methods of the MessagingConnector interface in order to get the informations from the mail server
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ametys.plugins.messagingconnector.MessagingConnector
MessagingConnector.AttendeeInformation, MessagingConnector.FreeBusyStatus, MessagingConnector.ResponseType
-
-
Field Summary
Fields Modifier and Type Field Description protected RequestConfig
_connectionConfig
The shared configuration for request (for timeout purposes)protected ConnectionKeepAliveStrategy
_connectionKeepAliveStrategy
The keep-alive stragegy to optimize http clientsprotected PoolingHttpClientConnectionManager
_connectionManager
Request to the remote app will be ppoled for perfs purposesprotected String
_domainPreauthSecretKey
Preauth secret keyprotected static int
_DROP_KEPTALIVE_CONNECTION_AFTER
The number of seconds after what kept alive connections are droptprotected JSONUtils
_jsonUtils
The JSON Utilsprotected UserManager
_usersManager
The user managerprotected String
_zimbraUrl
Url to zimbrastatic String
TOKEN_CACHE
token cache id-
Fields inherited from class org.ametys.plugins.messagingconnector.AbstractMessagingConnector
_cacheManager, _cryptoHelper, _currentUserProvider, _userPopulationDAO, _userPref
-
Fields inherited from interface org.ametys.plugins.messagingconnector.MessagingConnector
ROLE
-
-
Constructor Summary
Constructors Constructor Description ZimbraConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
_doPreauthRequest(UserIdentity userIdentity)
Zimbra preauth request to log the current user into zimbra and retrieve the ZM_AUTH_TOKENprotected String
_getComputedPreauth(String zimbraUser, String timestamp, String secretKey)
Compute the preauth key.protected CloseableHttpClient
_getHttpClient()
Get a new pooled http client.void
dispose()
void
initialize()
protected List<EmailMessage>
internalGetEmails(UserIdentity userIdentity, int maxEmails)
Get emails (no caching)protected int
internalGetEmailsCount(UserIdentity userIdentity)
Get emails count (no caching)protected List<CalendarEvent>
internalGetEvents(UserIdentity userIdentity, int maxDays, int maxEvents)
Get upcoming events (no caching)protected int
internalGetEventsCount(UserIdentity userIdentity, int maxDays)
Get upcoming events count (no caching)void
redirect(Redirector redirector, String targetApp)
Preauth user and redirect to the zimbra applicationvoid
service(ServiceManager smanager)
-
Methods inherited from class org.ametys.plugins.messagingconnector.AbstractMessagingConnector
createEvent, deleteEvent, getAllowedPopulationIds, getAttendees, getEvents, getEventsCount, getFreeBusy, getUnreadEmailCount, getUnreadEmails, getUserCryptedPassword, getUserPassword, internalCreateEvent, internalDeleteEvent, internalGetAttendees, internalGetFreeBusy, internalIsEventExist, internalSetAttendees, internalUpdateEvent, isAllowed, isEventExist, isUserExist, setAttendees, setUserPassword, supportInvitation, supportUserCredential, updateEvent, userCredentialNeeded
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
TOKEN_CACHE
public static final String TOKEN_CACHE
token cache id
-
_DROP_KEPTALIVE_CONNECTION_AFTER
protected static final int _DROP_KEPTALIVE_CONNECTION_AFTER
The number of seconds after what kept alive connections are dropt- See Also:
- Constant Field Values
-
_usersManager
protected UserManager _usersManager
The user manager
-
_jsonUtils
protected JSONUtils _jsonUtils
The JSON Utils
-
_zimbraUrl
protected String _zimbraUrl
Url to zimbra
-
_domainPreauthSecretKey
protected String _domainPreauthSecretKey
Preauth secret key
-
_connectionManager
protected PoolingHttpClientConnectionManager _connectionManager
Request to the remote app will be ppoled for perfs purposes
-
_connectionKeepAliveStrategy
protected ConnectionKeepAliveStrategy _connectionKeepAliveStrategy
The keep-alive stragegy to optimize http clients
-
_connectionConfig
protected RequestConfig _connectionConfig
The shared configuration for request (for timeout purposes)
-
-
Constructor Detail
-
ZimbraConnector
public ZimbraConnector()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractMessagingConnector
- Throws:
ServiceException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAbstractMessagingConnector
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
_getHttpClient
protected CloseableHttpClient _getHttpClient()
Get a new pooled http client. Do not forget to close it.- Returns:
- The client
-
redirect
public void redirect(Redirector redirector, String targetApp) throws ProcessingException, IOException
Preauth user and redirect to the zimbra application- Parameters:
redirector
- The redirectortargetApp
- The zimbra application (ex: mail)- Throws:
ProcessingException
- if failed to redirectIOException
- if failed to redirect
-
_doPreauthRequest
protected String _doPreauthRequest(UserIdentity userIdentity)
Zimbra preauth request to log the current user into zimbra and retrieve the ZM_AUTH_TOKEN- Parameters:
userIdentity
- The user for which the preauth request will be done.- Returns:
- The Zimbra ZM_AUTH_TOKEN which can be used in future request made through the Zimbra REST API or
null
if user is null or has no email. - Throws:
MessagingConnectorException
- if failed to get zimbra token for user
-
_getComputedPreauth
protected String _getComputedPreauth(String zimbraUser, String timestamp, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
Compute the preauth key.- Parameters:
zimbraUser
- The Zimbra Usertimestamp
- The timestampsecretKey
- The secret key- Returns:
- The computed preauth key
- Throws:
NoSuchAlgorithmException
- if no Provider supports a MacSpi implementation for the specified algorithm (HmacSHA1).InvalidKeyException
- if the given key is inappropriate for initializing the MACUnsupportedEncodingException
- If the named charset (UTF-8) is not supported
-
internalGetEvents
protected List<CalendarEvent> internalGetEvents(UserIdentity userIdentity, int maxDays, int maxEvents) throws MessagingConnectorException
Description copied from class:AbstractMessagingConnector
Get upcoming events (no caching)- Specified by:
internalGetEvents
in classAbstractMessagingConnector
- Parameters:
userIdentity
- The user identitymaxDays
- The maximum number of days to search formaxEvents
- The maximum number of events to retrieve- Returns:
- The calendar events
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetEventsCount
protected int internalGetEventsCount(UserIdentity userIdentity, int maxDays) throws MessagingConnectorException
Description copied from class:AbstractMessagingConnector
Get upcoming events count (no caching)- Specified by:
internalGetEventsCount
in classAbstractMessagingConnector
- Parameters:
userIdentity
- The user identitymaxDays
- The maximum number of days to search for- Returns:
- The number of calendar events
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetEmails
protected List<EmailMessage> internalGetEmails(UserIdentity userIdentity, int maxEmails) throws MessagingConnectorException
Description copied from class:AbstractMessagingConnector
Get emails (no caching)- Specified by:
internalGetEmails
in classAbstractMessagingConnector
- Parameters:
userIdentity
- The user identitymaxEmails
- The maximum number of emails to retrieve- Returns:
- The emails
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetEmailsCount
protected int internalGetEmailsCount(UserIdentity userIdentity) throws MessagingConnectorException
Description copied from class:AbstractMessagingConnector
Get emails count (no caching)- Specified by:
internalGetEmailsCount
in classAbstractMessagingConnector
- Parameters:
userIdentity
- The user identity- Returns:
- The emails count
- Throws:
MessagingConnectorException
- if failed to get events from server
-
-