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 Modifier and Type Class Description private class
ZimbraConnector.ZimbraEvent
-
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 zimbra-
Fields inherited from class org.ametys.plugins.messagingconnector.AbstractMessagingConnector
_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 private String
_computeQueryString(User user, String targetApp)
protected String
_doPreauthRequest(User user)
Zimbra preauth request to log the current user into zimbra and retrieve the ZM_AUTH_TOKENprotected List<Map<String,Object>>
_extractCalendarProperties(Calendar calendar, int dayInterval, int maxEvents)
Extract interesting properties for the calendar.protected Map<String,Object>
_extractCalendarProperties(ZimbraConnector.ZimbraEvent zimbraEvent)
Extract interesting properties for the event.protected Calendar
_getCalendar(User user, String zmAuthToken, String dayInterval)
Retrieves a calendar through a query via the Zimbra REST API.protected String
_getComputedPreauth(String zimbraUser, String timestamp, String secretKey)
Compute the preauth key.protected Map<String,Object>
_getEmailInfo(User user, String zmAuthToken)
Retrieves some mail info through a query via the Zimbra REST API.protected CloseableHttpClient
_getHttpClient()
Get a new pooled http client.protected String
_sanitizeEventLocation(Location location)
Extract the interesting part of the raw event location.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
-
_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
-
_getEmailInfo
protected Map<String,Object> _getEmailInfo(User user, String zmAuthToken)
Retrieves some mail info through a query via the Zimbra REST API. Query used is : home/~/inbox?query=is:unread&fmt=json&auth=qp&zauthtoken=##TOKEN##- Parameters:
user
- The userzmAuthToken
- The auth token corresponding to a currenlty logged user in zimbra.- Returns:
- Map of info returned by the REST request
-
_getCalendar
protected Calendar _getCalendar(User user, String zmAuthToken, String dayInterval)
Retrieves a calendar through a query via the Zimbra REST API. Query used is : home/~/calendar?fmt=ics&end=p30d&auth=qp&zauthtoken=##TOKEN##- Parameters:
user
- The userzmAuthToken
- The auth token corresponding to a currenlty logged user in zimbra.dayInterval
- Interval of day to search for the next event- Returns:
- The Calendar
-
_extractCalendarProperties
protected List<Map<String,Object>> _extractCalendarProperties(Calendar calendar, int dayInterval, int maxEvents)
Extract interesting properties for the calendar. Retrieves the next events and return some info.- Parameters:
calendar
- The calendardayInterval
- Interval of day to search for the next eventmaxEvents
- The maximum number of events- Returns:
- map of info about the next events.
-
_extractCalendarProperties
protected Map<String,Object> _extractCalendarProperties(ZimbraConnector.ZimbraEvent zimbraEvent)
Extract interesting properties for the event.- Parameters:
zimbraEvent
- The event- Returns:
- map of interesting info about this event.
-
_sanitizeEventLocation
protected String _sanitizeEventLocation(Location location)
Extract the interesting part of the raw event location.- Parameters:
location
- The iCal4j location object.- Returns:
- A String representing the sanitized location.
-
_doPreauthRequest
protected String _doPreauthRequest(User user)
Zimbra preauth request to log the current user into zimbra and retrieve the ZM_AUTH_TOKEN- Parameters:
user
- 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
-
_computeQueryString
private String _computeQueryString(User user, String targetApp)
-
_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
-
-