2013-07-27 18:33:20 +02:00
package com.sismics.docs.rest.resource ;
2017-11-17 23:17:05 +01:00
import com.google.common.base.Strings ;
2016-05-28 23:09:52 +02:00
import com.sismics.docs.core.constant.ConfigType ;
2017-11-18 19:34:13 +01:00
import com.sismics.docs.core.constant.Constants ;
2018-03-29 17:59:47 +02:00
import com.sismics.docs.core.dao.ConfigDao ;
import com.sismics.docs.core.dao.DocumentDao ;
import com.sismics.docs.core.dao.FileDao ;
import com.sismics.docs.core.dao.UserDao ;
2016-08-26 21:22:27 +02:00
import com.sismics.docs.core.event.RebuildIndexAsyncEvent ;
2018-02-27 14:58:37 +01:00
import com.sismics.docs.core.model.context.AppContext ;
2017-11-18 19:34:13 +01:00
import com.sismics.docs.core.model.jpa.Config ;
2013-08-18 00:53:01 +02:00
import com.sismics.docs.core.model.jpa.File ;
2018-02-27 17:11:04 +01:00
import com.sismics.docs.core.service.InboxService ;
2013-07-27 18:33:20 +02:00
import com.sismics.docs.core.util.ConfigUtil ;
2013-08-18 00:53:01 +02:00
import com.sismics.docs.core.util.DirectoryUtil ;
2020-08-28 18:09:54 +02:00
import com.sismics.docs.core.util.authentication.LdapAuthenticationHandler ;
2013-07-27 18:33:20 +02:00
import com.sismics.docs.core.util.jpa.PaginatedList ;
import com.sismics.docs.core.util.jpa.PaginatedLists ;
import com.sismics.docs.rest.constant.BaseFunction ;
2018-02-22 12:57:33 +01:00
import com.sismics.rest.exception.ClientException ;
2013-07-27 18:33:20 +02:00
import com.sismics.rest.exception.ForbiddenClientException ;
import com.sismics.rest.exception.ServerException ;
2017-11-17 23:17:05 +01:00
import com.sismics.rest.util.ValidationUtil ;
2018-02-27 17:11:04 +01:00
import com.sismics.util.JsonUtil ;
2015-12-01 00:32:57 +01:00
import com.sismics.util.context.ThreadLocalContext ;
2013-07-27 18:33:20 +02:00
import com.sismics.util.log4j.LogCriteria ;
import com.sismics.util.log4j.LogEntry ;
import com.sismics.util.log4j.MemoryAppender ;
2023-03-19 14:28:22 +01:00
import org.apache.commons.lang3.StringUtils ;
2017-11-17 23:17:05 +01:00
import org.apache.log4j.Appender ;
import org.apache.log4j.Level ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import javax.json.Json ;
import javax.json.JsonArrayBuilder ;
import javax.json.JsonObjectBuilder ;
import javax.persistence.EntityManager ;
import javax.persistence.Query ;
import javax.ws.rs.* ;
import javax.ws.rs.core.Response ;
import java.io.IOException ;
import java.nio.file.DirectoryStream ;
import java.nio.file.Files ;
2018-02-22 12:57:33 +01:00
import java.text.MessageFormat ;
2017-11-17 23:17:05 +01:00
import java.util.* ;
2013-07-27 18:33:20 +02:00
/ * *
* General app REST resource .
*
* @author jtremeaux
* /
@Path ( " /app " )
public class AppResource extends BaseResource {
2015-12-01 00:32:57 +01:00
/ * *
* Logger .
* /
private static final Logger log = LoggerFactory . getLogger ( AppResource . class ) ;
2013-07-27 18:33:20 +02:00
/ * *
2016-05-12 01:26:02 +02:00
* Returns informations about the application .
*
* @api { get } / app Get application informations
* @apiName GetApp
* @apiGroup App
* @apiSuccess { String } current_version API current version
* @apiSuccess { String } min_version API minimum version
2016-05-28 23:09:52 +02:00
* @apiSuccess { Boolean } guest_login True if guest login is enabled
2018-04-22 11:12:09 +02:00
* @apiSuccess { String } default_language Default platform language
* @apiSuccess { Number } queued_tasks Number of queued tasks waiting to be processed
2016-05-12 01:26:02 +02:00
* @apiSuccess { String } total_memory Allocated JVM memory ( in bytes )
* @apiSuccess { String } free_memory Free JVM memory ( in bytes )
2017-11-21 09:49:33 +01:00
* @apiSuccess { String } document_count Number of documents
2017-11-20 21:21:50 +01:00
* @apiSuccess { String } active_user_count Number of active users
2017-11-20 20:34:29 +01:00
* @apiSuccess { String } global_storage_current Global storage currently used ( in bytes )
* @apiSuccess { String } global_storage_quota Maximum global storage ( in bytes )
2016-05-28 23:09:52 +02:00
* @apiPermission none
2016-05-12 01:26:02 +02:00
* @apiVersion 1 . 5 . 0
*
2013-07-27 18:33:20 +02:00
* @return Response
* /
@GET
2015-09-07 21:51:13 +02:00
public Response info ( ) {
2013-07-27 18:33:20 +02:00
ResourceBundle configBundle = ConfigUtil . getConfigBundle ( ) ;
String currentVersion = configBundle . getString ( " api.current_version " ) ;
String minVersion = configBundle . getString ( " api.min_version " ) ;
2016-05-28 23:09:52 +02:00
Boolean guestLogin = ConfigUtil . getConfigBooleanValue ( ConfigType . GUEST_LOGIN ) ;
2018-02-22 12:57:33 +01:00
String defaultLanguage = ConfigUtil . getConfigStringValue ( ConfigType . DEFAULT_LANGUAGE ) ;
2017-11-20 20:34:29 +01:00
UserDao userDao = new UserDao ( ) ;
2017-11-21 09:49:33 +01:00
DocumentDao documentDao = new DocumentDao ( ) ;
2017-11-20 20:34:29 +01:00
String globalQuotaStr = System . getenv ( Constants . GLOBAL_QUOTA_ENV ) ;
long globalQuota = 0 ;
if ( ! Strings . isNullOrEmpty ( globalQuotaStr ) ) {
globalQuota = Long . valueOf ( globalQuotaStr ) ;
}
2013-07-27 18:33:20 +02:00
2015-09-07 21:51:13 +02:00
JsonObjectBuilder response = Json . createObjectBuilder ( )
. add ( " current_version " , currentVersion . replace ( " -SNAPSHOT " , " " ) )
. add ( " min_version " , minVersion )
2016-05-28 23:09:52 +02:00
. add ( " guest_login " , guestLogin )
2018-02-22 12:57:33 +01:00
. add ( " default_language " , defaultLanguage )
2018-04-22 11:12:09 +02:00
. add ( " queued_tasks " , AppContext . getInstance ( ) . getQueuedTaskCount ( ) )
2015-09-07 21:51:13 +02:00
. add ( " total_memory " , Runtime . getRuntime ( ) . totalMemory ( ) )
2017-11-20 20:34:29 +01:00
. add ( " free_memory " , Runtime . getRuntime ( ) . freeMemory ( ) )
2017-11-21 09:49:33 +01:00
. add ( " document_count " , documentDao . getDocumentCount ( ) )
2017-11-20 21:21:50 +01:00
. add ( " active_user_count " , userDao . getActiveUserCount ( ) )
2017-11-20 20:34:29 +01:00
. add ( " global_storage_current " , userDao . getGlobalStorageCurrent ( ) ) ;
if ( globalQuota > 0 ) {
response . add ( " global_storage_quota " , globalQuota ) ;
}
2015-09-07 21:51:13 +02:00
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
2013-07-27 18:33:20 +02:00
}
2016-05-28 23:09:52 +02:00
/ * *
* Enable / disable guest login .
*
* @api { post } / app / guest_login Enable / disable guest login
* @apiName PostAppGuestLogin
* @apiGroup App
* @apiParam { Boolean } enabled If true , enable guest login
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @param enabled If true , enable guest login
* @return Response
* /
@POST
@Path ( " guest_login " )
public Response guestLogin ( @FormParam ( " enabled " ) Boolean enabled ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ConfigDao configDao = new ConfigDao ( ) ;
configDao . update ( ConfigType . GUEST_LOGIN , enabled . toString ( ) ) ;
return Response . ok ( ) . build ( ) ;
}
2017-11-18 19:34:13 +01:00
2018-02-22 12:57:33 +01:00
/ * *
* General application configuration .
*
* @api { post } / app / config General application configuration
* @apiName PostAppConfig
* @apiGroup App
* @apiParam { String } default_language Default language
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @param defaultLanguage Default language
* @return Response
* /
@POST
@Path ( " config " )
public Response config ( @FormParam ( " default_language " ) String defaultLanguage ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ValidationUtil . validateRequired ( defaultLanguage , " default_language " ) ;
if ( ! Constants . SUPPORTED_LANGUAGES . contains ( defaultLanguage ) ) {
throw new ClientException ( " ValidationError " , MessageFormat . format ( " {0} is not a supported language " , defaultLanguage ) ) ;
}
ConfigDao configDao = new ConfigDao ( ) ;
configDao . update ( ConfigType . DEFAULT_LANGUAGE , defaultLanguage ) ;
return Response . ok ( ) . build ( ) ;
}
2017-11-18 19:34:13 +01:00
/ * *
* Get the SMTP server configuration .
*
* @api { get } / app / config_smtp Get the SMTP server configuration
* @apiName GetAppConfigSmtp
* @apiGroup App
* @apiSuccess { String } hostname SMTP hostname
2018-02-27 14:58:37 +01:00
* @apiSuccess { String } port SMTP port
* @apiSuccess { String } username SMTP username
* @apiSuccess { String } password SMTP password
* @apiSuccess { String } from From address
2017-11-18 19:34:13 +01:00
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @return Response
* /
@GET
@Path ( " config_smtp " )
public Response getConfigSmtp ( ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ConfigDao configDao = new ConfigDao ( ) ;
Config hostnameConfig = configDao . getById ( ConfigType . SMTP_HOSTNAME ) ;
Config portConfig = configDao . getById ( ConfigType . SMTP_PORT ) ;
Config usernameConfig = configDao . getById ( ConfigType . SMTP_USERNAME ) ;
Config passwordConfig = configDao . getById ( ConfigType . SMTP_PASSWORD ) ;
Config fromConfig = configDao . getById ( ConfigType . SMTP_FROM ) ;
JsonObjectBuilder response = Json . createObjectBuilder ( ) ;
2022-02-20 15:48:37 +01:00
if ( Strings . isNullOrEmpty ( System . getenv ( Constants . SMTP_HOSTNAME_ENV ) ) ) {
2017-11-18 19:34:13 +01:00
if ( hostnameConfig = = null ) {
response . addNull ( " hostname " ) ;
} else {
response . add ( " hostname " , hostnameConfig . getValue ( ) ) ;
}
}
2022-02-20 15:48:37 +01:00
if ( Strings . isNullOrEmpty ( System . getenv ( Constants . SMTP_PORT_ENV ) ) ) {
2017-11-18 19:34:13 +01:00
if ( portConfig = = null ) {
response . addNull ( " port " ) ;
} else {
response . add ( " port " , Integer . valueOf ( portConfig . getValue ( ) ) ) ;
}
}
2022-02-20 15:48:37 +01:00
if ( Strings . isNullOrEmpty ( System . getenv ( Constants . SMTP_USERNAME_ENV ) ) ) {
2017-11-18 19:34:13 +01:00
if ( usernameConfig = = null ) {
response . addNull ( " username " ) ;
} else {
response . add ( " username " , usernameConfig . getValue ( ) ) ;
}
}
2022-02-20 15:48:37 +01:00
if ( Strings . isNullOrEmpty ( System . getenv ( Constants . SMTP_PASSWORD_ENV ) ) ) {
2017-11-18 19:34:13 +01:00
if ( passwordConfig = = null ) {
response . addNull ( " password " ) ;
} else {
response . add ( " password " , passwordConfig . getValue ( ) ) ;
}
}
if ( fromConfig = = null ) {
response . addNull ( " from " ) ;
} else {
response . add ( " from " , fromConfig . getValue ( ) ) ;
}
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
}
2013-07-27 18:33:20 +02:00
2017-11-17 17:01:08 +01:00
/ * *
* Configure the SMTP server .
*
* @api { post } / app / config_smtp Configure the SMTP server
* @apiName PostAppConfigSmtp
* @apiGroup App
* @apiParam { String } hostname SMTP hostname
* @apiParam { Integer } port SMTP port
* @apiParam { String } username SMTP username
* @apiParam { String } password SMTP password
2017-11-18 19:34:13 +01:00
* @apiParam { String } from From address
2017-11-17 17:01:08 +01:00
* @apiError ( client ) ForbiddenError Access denied
2017-11-17 23:17:05 +01:00
* @apiError ( client ) ValidationError Validation error
2017-11-17 17:01:08 +01:00
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @param hostname SMTP hostname
* @param portStr SMTP port
* @param username SMTP username
* @param password SMTP password
2017-11-18 19:34:13 +01:00
* @param from From address
2017-11-17 17:01:08 +01:00
* @return Response
* /
@POST
@Path ( " config_smtp " )
public Response configSmtp ( @FormParam ( " hostname " ) String hostname ,
@FormParam ( " port " ) String portStr ,
@FormParam ( " username " ) String username ,
2017-11-18 19:34:13 +01:00
@FormParam ( " password " ) String password ,
@FormParam ( " from " ) String from ) {
2017-11-17 17:01:08 +01:00
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
2017-11-17 23:17:05 +01:00
if ( ! Strings . isNullOrEmpty ( portStr ) ) {
ValidationUtil . validateInteger ( portStr , " port " ) ;
}
2017-11-17 17:01:08 +01:00
2017-11-17 23:17:05 +01:00
// Just update the changed configuration
2017-11-17 17:01:08 +01:00
ConfigDao configDao = new ConfigDao ( ) ;
2017-11-17 23:17:05 +01:00
if ( ! Strings . isNullOrEmpty ( hostname ) ) {
configDao . update ( ConfigType . SMTP_HOSTNAME , hostname ) ;
}
if ( ! Strings . isNullOrEmpty ( portStr ) ) {
configDao . update ( ConfigType . SMTP_PORT , portStr ) ;
}
if ( ! Strings . isNullOrEmpty ( username ) ) {
2017-11-17 17:01:08 +01:00
configDao . update ( ConfigType . SMTP_USERNAME , username ) ;
}
2017-11-17 23:17:05 +01:00
if ( ! Strings . isNullOrEmpty ( password ) ) {
2017-11-17 17:01:08 +01:00
configDao . update ( ConfigType . SMTP_PASSWORD , password ) ;
}
2017-11-18 19:34:13 +01:00
if ( ! Strings . isNullOrEmpty ( from ) ) {
configDao . update ( ConfigType . SMTP_FROM , from ) ;
}
2017-11-17 17:01:08 +01:00
return Response . ok ( ) . build ( ) ;
}
2018-02-27 14:58:37 +01:00
/ * *
* Get the inbox configuration .
*
* @api { get } / app / config_inbox Get the inbox scanning configuration
* @apiName GetAppConfigInbox
* @apiGroup App
* @apiSuccess { Boolean } enabled True if the inbox scanning is enabled
* @apiSuccess { String } hostname IMAP hostname
* @apiSuccess { String } port IMAP port
* @apiSuccess { String } username IMAP username
* @apiSuccess { String } password IMAP password
2020-11-22 13:39:39 +01:00
* @apiSuccess { String } folder IMAP folder
2018-02-27 14:58:37 +01:00
* @apiSuccess { String } tag Tag for created documents
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @return Response
* /
@GET
@Path ( " config_inbox " )
public Response getConfigInbox ( ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ConfigDao configDao = new ConfigDao ( ) ;
Boolean enabled = ConfigUtil . getConfigBooleanValue ( ConfigType . INBOX_ENABLED ) ;
2020-05-14 13:59:11 +02:00
Boolean autoTags = ConfigUtil . getConfigBooleanValue ( ConfigType . INBOX_AUTOMATIC_TAGS ) ;
Boolean deleteImported = ConfigUtil . getConfigBooleanValue ( ConfigType . INBOX_DELETE_IMPORTED ) ;
2018-02-27 14:58:37 +01:00
Config hostnameConfig = configDao . getById ( ConfigType . INBOX_HOSTNAME ) ;
Config portConfig = configDao . getById ( ConfigType . INBOX_PORT ) ;
Config usernameConfig = configDao . getById ( ConfigType . INBOX_USERNAME ) ;
Config passwordConfig = configDao . getById ( ConfigType . INBOX_PASSWORD ) ;
2020-11-22 13:39:39 +01:00
Config folderConfig = configDao . getById ( ConfigType . INBOX_FOLDER ) ;
2018-02-27 14:58:37 +01:00
Config tagConfig = configDao . getById ( ConfigType . INBOX_TAG ) ;
JsonObjectBuilder response = Json . createObjectBuilder ( ) ;
response . add ( " enabled " , enabled ) ;
2020-05-14 13:59:11 +02:00
response . add ( " autoTagsEnabled " , autoTags ) ;
response . add ( " deleteImported " , deleteImported ) ;
2018-02-27 14:58:37 +01:00
if ( hostnameConfig = = null ) {
response . addNull ( " hostname " ) ;
} else {
response . add ( " hostname " , hostnameConfig . getValue ( ) ) ;
}
if ( portConfig = = null ) {
response . addNull ( " port " ) ;
} else {
response . add ( " port " , Integer . valueOf ( portConfig . getValue ( ) ) ) ;
}
if ( usernameConfig = = null ) {
response . addNull ( " username " ) ;
} else {
response . add ( " username " , usernameConfig . getValue ( ) ) ;
}
if ( passwordConfig = = null ) {
response . addNull ( " password " ) ;
} else {
response . add ( " password " , passwordConfig . getValue ( ) ) ;
}
2020-11-22 13:39:39 +01:00
if ( folderConfig = = null ) {
response . addNull ( " folder " ) ;
} else {
response . add ( " folder " , folderConfig . getValue ( ) ) ;
}
2018-02-27 14:58:37 +01:00
if ( tagConfig = = null ) {
response . addNull ( " tag " ) ;
} else {
response . add ( " tag " , tagConfig . getValue ( ) ) ;
}
2018-02-27 17:11:04 +01:00
// Informations about the last synchronization
InboxService inboxService = AppContext . getInstance ( ) . getInboxService ( ) ;
JsonObjectBuilder lastSync = Json . createObjectBuilder ( ) ;
if ( inboxService . getLastSyncDate ( ) = = null ) {
lastSync . addNull ( " date " ) ;
} else {
lastSync . add ( " date " , inboxService . getLastSyncDate ( ) . getTime ( ) ) ;
}
lastSync . add ( " error " , JsonUtil . nullable ( inboxService . getLastSyncError ( ) ) ) ;
lastSync . add ( " count " , inboxService . getLastSyncMessageCount ( ) ) ;
response . add ( " last_sync " , lastSync ) ;
2018-02-27 14:58:37 +01:00
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
}
/ * *
* Configure the inbox .
*
* @api { post } / app / config_inbox Configure the inbox scanning
* @apiName PostAppConfigInbox
* @apiGroup App
* @apiParam { Boolean } enabled True if the inbox scanning is enabled
2022-04-17 13:23:22 +02:00
* @apiParam { Boolean } autoTagsEnabled If true automatically add tags to document ( prefixed by # )
* @apiParam { Boolean } deleteImported If true delete message from mailbox after import
2018-02-27 14:58:37 +01:00
* @apiParam { String } hostname IMAP hostname
* @apiParam { Integer } port IMAP port
* @apiParam { String } username IMAP username
* @apiParam { String } password IMAP password
2020-11-22 13:39:39 +01:00
* @apiParam { String } folder IMAP folder
2018-02-27 14:58:37 +01:00
* @apiParam { String } tag Tag for created documents
* @apiError ( client ) ForbiddenError Access denied
* @apiError ( client ) ValidationError Validation error
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @param enabled True if the inbox scanning is enabled
* @param hostname IMAP hostname
* @param portStr IMAP port
* @param username IMAP username
* @param password IMAP password
2020-11-22 13:39:39 +01:00
* @param folder IMAP folder
2018-02-27 14:58:37 +01:00
* @param tag Tag for created documents
* @return Response
* /
@POST
@Path ( " config_inbox " )
public Response configInbox ( @FormParam ( " enabled " ) Boolean enabled ,
2020-05-14 13:59:11 +02:00
@FormParam ( " autoTagsEnabled " ) Boolean autoTagsEnabled ,
@FormParam ( " deleteImported " ) Boolean deleteImported ,
2018-02-27 14:58:37 +01:00
@FormParam ( " hostname " ) String hostname ,
@FormParam ( " port " ) String portStr ,
@FormParam ( " username " ) String username ,
@FormParam ( " password " ) String password ,
2020-11-22 13:39:39 +01:00
@FormParam ( " folder " ) String folder ,
2018-02-27 14:58:37 +01:00
@FormParam ( " tag " ) String tag ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ValidationUtil . validateRequired ( enabled , " enabled " ) ;
2022-04-17 13:23:22 +02:00
ValidationUtil . validateRequired ( autoTagsEnabled , " autoTagsEnabled " ) ;
ValidationUtil . validateRequired ( deleteImported , " deleteImported " ) ;
2018-02-27 14:58:37 +01:00
if ( ! Strings . isNullOrEmpty ( portStr ) ) {
ValidationUtil . validateInteger ( portStr , " port " ) ;
}
// Just update the changed configuration
ConfigDao configDao = new ConfigDao ( ) ;
configDao . update ( ConfigType . INBOX_ENABLED , enabled . toString ( ) ) ;
2020-05-14 13:59:11 +02:00
configDao . update ( ConfigType . INBOX_AUTOMATIC_TAGS , autoTagsEnabled . toString ( ) ) ;
configDao . update ( ConfigType . INBOX_DELETE_IMPORTED , deleteImported . toString ( ) ) ;
2018-02-27 14:58:37 +01:00
if ( ! Strings . isNullOrEmpty ( hostname ) ) {
configDao . update ( ConfigType . INBOX_HOSTNAME , hostname ) ;
}
if ( ! Strings . isNullOrEmpty ( portStr ) ) {
configDao . update ( ConfigType . INBOX_PORT , portStr ) ;
}
if ( ! Strings . isNullOrEmpty ( username ) ) {
configDao . update ( ConfigType . INBOX_USERNAME , username ) ;
}
if ( ! Strings . isNullOrEmpty ( password ) ) {
configDao . update ( ConfigType . INBOX_PASSWORD , password ) ;
}
2020-11-22 13:39:39 +01:00
if ( ! Strings . isNullOrEmpty ( folder ) ) {
configDao . update ( ConfigType . INBOX_FOLDER , folder ) ;
}
2018-02-27 14:58:37 +01:00
if ( ! Strings . isNullOrEmpty ( tag ) ) {
configDao . update ( ConfigType . INBOX_TAG , tag ) ;
}
return Response . ok ( ) . build ( ) ;
}
/ * *
* Test the inbox .
*
* @api { post } / app / test_inbox Test the inbox scanning
* @apiName PostAppTestInbox
* @apiGroup App
* @apiSuccess { Number } Number of unread emails in the inbox
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
* @return Response
* /
@POST
@Path ( " test_inbox " )
public Response testInbox ( ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
return Response . ok ( ) . entity ( Json . createObjectBuilder ( )
. add ( " count " , AppContext . getInstance ( ) . getInboxService ( ) . testInbox ( ) )
. build ( ) ) . build ( ) ;
}
2013-07-27 18:33:20 +02:00
/ * *
* Retrieve the application logs .
2016-05-12 01:26:02 +02:00
*
* @api { get } / app / log Get application logs
* @apiName GetAppLog
* @apiGroup App
* @apiParam { String = " FATAL " , " ERROR " , " WARN " , " INFO " , " DEBUG " } level Minimum log level
* @apiParam { String } tag Filter on this logger tag
* @apiParam { String } message Filter on this message
* @apiParam { Number } limit Total number of logs to return
* @apiParam { Number } offset Start at this index
* @apiSuccess { String } total Total number of logs
* @apiSuccess { Object [ ] } logs List of logs
* @apiSuccess { String } logs . date Date
* @apiSuccess { String } logs . level Level
* @apiSuccess { String } logs . tag Tag
* @apiSuccess { String } logs . message Message
* @apiError ( client ) ForbiddenError Access denied
* @apiError ( server ) ServerError MEMORY appender not configured
2022-02-02 21:17:58 +01:00
* @apiPermission admin
2016-05-12 01:26:02 +02:00
* @apiVersion 1 . 5 . 0
*
2016-03-13 23:13:12 +01:00
* @param minLevel Filter on logging level
2013-07-27 18:33:20 +02:00
* @param tag Filter on logger name / tag
* @param message Filter on message
* @param limit Page limit
* @param offset Page offset
2013-08-13 20:20:28 +02:00
* @return Response
2013-07-27 18:33:20 +02:00
* /
@GET
@Path ( " log " )
public Response log (
2016-03-13 23:13:12 +01:00
@QueryParam ( " level " ) String minLevel ,
2013-07-27 18:33:20 +02:00
@QueryParam ( " tag " ) String tag ,
@QueryParam ( " message " ) String message ,
@QueryParam ( " limit " ) Integer limit ,
2015-09-07 21:51:13 +02:00
@QueryParam ( " offset " ) Integer offset ) {
2013-07-27 18:33:20 +02:00
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
2022-02-02 21:17:58 +01:00
checkBaseFunction ( BaseFunction . ADMIN ) ;
2016-05-12 01:26:02 +02:00
2013-07-27 18:33:20 +02:00
// Get the memory appender
2015-12-01 00:32:57 +01:00
org . apache . log4j . Logger logger = org . apache . log4j . Logger . getRootLogger ( ) ;
2013-07-27 18:33:20 +02:00
Appender appender = logger . getAppender ( " MEMORY " ) ;
2018-04-09 13:02:39 +02:00
if ( ! ( appender instanceof MemoryAppender ) ) {
2013-07-27 18:33:20 +02:00
throw new ServerException ( " ServerError " , " MEMORY appender not configured " ) ;
}
MemoryAppender memoryAppender = ( MemoryAppender ) appender ;
// Find the logs
2016-03-13 23:13:12 +01:00
LogCriteria logCriteria = new LogCriteria ( )
. setMinLevel ( Level . toLevel ( StringUtils . stripToNull ( minLevel ) ) )
. setTag ( StringUtils . stripToNull ( tag ) )
. setMessage ( StringUtils . stripToNull ( message ) ) ;
2013-07-27 18:33:20 +02:00
PaginatedList < LogEntry > paginatedList = PaginatedLists . create ( limit , offset ) ;
memoryAppender . find ( logCriteria , paginatedList ) ;
2015-09-07 21:51:13 +02:00
JsonArrayBuilder logs = Json . createArrayBuilder ( ) ;
2013-07-27 18:33:20 +02:00
for ( LogEntry logEntry : paginatedList . getResultList ( ) ) {
2015-09-07 21:51:13 +02:00
logs . add ( Json . createObjectBuilder ( )
. add ( " date " , logEntry . getTimestamp ( ) )
2016-03-13 23:13:12 +01:00
. add ( " level " , logEntry . getLevel ( ) . toString ( ) )
2015-09-07 21:51:13 +02:00
. add ( " tag " , logEntry . getTag ( ) )
. add ( " message " , logEntry . getMessage ( ) ) ) ;
2013-07-27 18:33:20 +02:00
}
2015-09-07 21:51:13 +02:00
JsonObjectBuilder response = Json . createObjectBuilder ( )
. add ( " total " , paginatedList . getResultCount ( ) )
. add ( " logs " , logs ) ;
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
2013-07-27 18:33:20 +02:00
}
2013-08-17 00:36:36 +02:00
2013-08-17 14:16:55 +02:00
/ * *
2018-04-09 13:02:39 +02:00
* Destroy and rebuild the search index .
2016-05-12 01:26:02 +02:00
*
* @api { post } / app / batch / reindex Rebuild the search index
* @apiName PostAppBatchReindex
* @apiGroup App
* @apiSuccess { String } status Status OK
* @apiError ( client ) ForbiddenError Access denied
* @apiError ( server ) IndexingError Error rebuilding the index
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
2013-08-17 14:16:55 +02:00
* @return Response
* /
@POST
@Path ( " batch/reindex " )
2015-09-07 21:51:13 +02:00
public Response batchReindex ( ) {
2013-08-17 14:16:55 +02:00
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
2016-08-26 21:22:27 +02:00
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent ( ) ;
ThreadLocalContext . get ( ) . addAsyncEvent ( rebuildIndexAsyncEvent ) ;
2015-09-07 21:51:13 +02:00
// Always return OK
JsonObjectBuilder response = Json . createObjectBuilder ( )
. add ( " status " , " ok " ) ;
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
2013-08-18 00:53:01 +02:00
}
/ * *
2013-08-20 21:51:07 +02:00
* Clean storage .
2016-05-12 01:26:02 +02:00
*
* @api { post } / app / batch / clean_storage Clean the file and DB storage
* @apiName PostAppBatchCleanStorage
* @apiGroup App
* @apiSuccess { String } status Status OK
* @apiError ( client ) ForbiddenError Access denied
* @apiError ( server ) FileError Error deleting orphan files
* @apiPermission admin
* @apiVersion 1 . 5 . 0
*
2013-08-18 00:53:01 +02:00
* @return Response
* /
@POST
@Path ( " batch/clean_storage " )
2015-09-07 21:51:13 +02:00
public Response batchCleanStorage ( ) {
2013-08-18 00:53:01 +02:00
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
// Get all files
FileDao fileDao = new FileDao ( ) ;
2018-10-29 18:32:39 +01:00
List < File > fileList = fileDao . findAll ( 0 , Integer . MAX_VALUE ) ;
2013-08-18 00:53:01 +02:00
Map < String , File > fileMap = new HashMap < > ( ) ;
for ( File file : fileList ) {
fileMap . put ( file . getId ( ) , file ) ;
}
2015-12-01 00:32:57 +01:00
log . info ( " Checking {} files " , fileMap . size ( ) ) ;
2013-08-18 00:53:01 +02:00
// Check if each stored file is valid
2015-11-29 19:42:49 +01:00
try ( DirectoryStream < java . nio . file . Path > storedFileList = Files . newDirectoryStream ( DirectoryUtil . getStorageDirectory ( ) ) ) {
for ( java . nio . file . Path storedFile : storedFileList ) {
String fileName = storedFile . getFileName ( ) . toString ( ) ;
String [ ] fileNameArray = fileName . split ( " _ " ) ;
if ( ! fileMap . containsKey ( fileNameArray [ 0 ] ) ) {
2015-12-01 00:32:57 +01:00
log . info ( " Deleting orphan files at this location: {} " , storedFile ) ;
2015-11-29 19:42:49 +01:00
Files . delete ( storedFile ) ;
}
2013-08-18 00:53:01 +02:00
}
2015-11-29 19:42:49 +01:00
} catch ( IOException e ) {
throw new ServerException ( " FileError " , " Error deleting orphan files " , e ) ;
2013-08-18 00:53:01 +02:00
}
2015-12-01 00:32:57 +01:00
// Hard delete orphan audit logs
EntityManager em = ThreadLocalContext . get ( ) . getEntityManager ( ) ;
StringBuilder sb = new StringBuilder ( " delete from T_AUDIT_LOG al where al.LOG_ID_C in (select al.LOG_ID_C from T_AUDIT_LOG al " ) ;
sb . append ( " left join T_DOCUMENT d on d.DOC_ID_C = al.LOG_IDENTITY_C and d.DOC_DELETEDATE_D is null " ) ;
sb . append ( " left join T_ACL a on a.ACL_ID_C = al.LOG_IDENTITY_C and a.ACL_DELETEDATE_D is null " ) ;
sb . append ( " left join T_COMMENT c on c.COM_ID_C = al.LOG_IDENTITY_C and c.COM_DELETEDATE_D is null " ) ;
sb . append ( " left join T_FILE f on f.FIL_ID_C = al.LOG_IDENTITY_C and f.FIL_DELETEDATE_D is null " ) ;
sb . append ( " left join T_TAG t on t.TAG_ID_C = al.LOG_IDENTITY_C and t.TAG_DELETEDATE_D is null " ) ;
sb . append ( " left join T_USER u on u.USE_ID_C = al.LOG_IDENTITY_C and u.USE_DELETEDATE_D is null " ) ;
2016-05-09 19:11:44 +02:00
sb . append ( " left join T_GROUP g on g.GRP_ID_C = al.LOG_IDENTITY_C and g.GRP_DELETEDATE_D is null " ) ;
sb . append ( " where d.DOC_ID_C is null and a.ACL_ID_C is null and c.COM_ID_C is null and f.FIL_ID_C is null and t.TAG_ID_C is null and u.USE_ID_C is null and g.GRP_ID_C is null) " ) ;
2015-12-01 00:32:57 +01:00
Query q = em . createNativeQuery ( sb . toString ( ) ) ;
log . info ( " Deleting {} orphan audit logs " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan ACLs
sb = new StringBuilder ( " update T_ACL a set ACL_DELETEDATE_D = :dateNow where a.ACL_ID_C in (select a.ACL_ID_C from T_ACL a " ) ;
2015-12-01 00:32:57 +01:00
sb . append ( " left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C " ) ;
sb . append ( " left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C " ) ;
2016-05-09 19:11:44 +02:00
sb . append ( " left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C " ) ;
2015-12-01 00:32:57 +01:00
sb . append ( " left join T_DOCUMENT d on d.DOC_ID_C = a.ACL_SOURCEID_C " ) ;
2016-05-09 19:11:44 +02:00
sb . append ( " left join T_TAG t on t.TAG_ID_C = a.ACL_SOURCEID_C " ) ;
sb . append ( " where s.SHA_ID_C is null and u.USE_ID_C is null and g.GRP_ID_C is null or d.DOC_ID_C is null and t.TAG_ID_C is null) " ) ;
2015-12-01 00:32:57 +01:00
q = em . createNativeQuery ( sb . toString ( ) ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
2015-12-01 00:32:57 +01:00
log . info ( " Deleting {} orphan ACLs " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan comments
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_COMMENT set COM_DELETEDATE_D = :dateNow where COM_ID_C in (select c.COM_ID_C from T_COMMENT c left join T_DOCUMENT d on d.DOC_ID_C = c.COM_IDDOC_C and d.DOC_DELETEDATE_D is null where d.DOC_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
2015-12-01 00:32:57 +01:00
log . info ( " Deleting {} orphan comments " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan document tag links
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_DOCUMENT_TAG set DOT_DELETEDATE_D = :dateNow where DOT_ID_C in (select dt.DOT_ID_C from T_DOCUMENT_TAG dt left join T_DOCUMENT d on dt.DOT_IDDOCUMENT_C = d.DOC_ID_C and d.DOC_DELETEDATE_D is null left join T_TAG t on t.TAG_ID_C = dt.DOT_IDTAG_C and t.TAG_DELETEDATE_D is null where d.DOC_ID_C is null or t.TAG_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
2015-12-01 00:32:57 +01:00
log . info ( " Deleting {} orphan document tag links " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan shares
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_SHARE set SHA_DELETEDATE_D = :dateNow where SHA_ID_C in (select s.SHA_ID_C from T_SHARE s left join T_ACL a on a.ACL_TARGETID_C = s.SHA_ID_C and a.ACL_DELETEDATE_D is null where a.ACL_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
2015-12-01 00:32:57 +01:00
log . info ( " Deleting {} orphan shares " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan tags
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_TAG set TAG_DELETEDATE_D = :dateNow where TAG_ID_C in (select t.TAG_ID_C from T_TAG t left join T_USER u on u.USE_ID_C = t.TAG_IDUSER_C and u.USE_DELETEDATE_D is null where u.USE_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
2015-12-01 00:32:57 +01:00
log . info ( " Deleting {} orphan tags " , q . executeUpdate ( ) ) ;
2015-12-01 01:16:57 +01:00
// Soft delete orphan documents
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_DOCUMENT set DOC_DELETEDATE_D = :dateNow where DOC_ID_C in (select d.DOC_ID_C from T_DOCUMENT d left join T_USER u on u.USE_ID_C = d.DOC_IDUSER_C and u.USE_DELETEDATE_D is null where u.USE_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
log . info ( " Deleting {} orphan documents " , q . executeUpdate ( ) ) ;
// Soft delete orphan files
2023-03-12 13:35:35 +01:00
q = em . createNativeQuery ( " update T_FILE set FIL_DELETEDATE_D = :dateNow where FIL_ID_C in (select f.FIL_ID_C from T_FILE f left join T_USER u on u.USE_ID_C = f.FIL_IDUSER_C and u.USE_DELETEDATE_D is null where u.USE_ID_C is null) " ) ;
2015-12-01 01:16:57 +01:00
q . setParameter ( " dateNow " , new Date ( ) ) ;
log . info ( " Deleting {} orphan files " , q . executeUpdate ( ) ) ;
2015-12-01 00:32:57 +01:00
// Hard delete softly deleted data
2023-03-12 13:35:35 +01:00
log . info ( " Deleting {} soft deleted document tag links " , em . createQuery ( " delete DocumentTag where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted ACLs " , em . createQuery ( " delete Acl where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted shares " , em . createQuery ( " delete Share where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted tags " , em . createQuery ( " delete Tag where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted comments " , em . createQuery ( " delete Comment where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted files " , em . createQuery ( " delete File where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted documents " , em . createQuery ( " delete Document where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted users " , em . createQuery ( " delete User where deleteDate is not null " ) . executeUpdate ( ) ) ;
log . info ( " Deleting {} soft deleted groups " , em . createQuery ( " delete Group where deleteDate is not null " ) . executeUpdate ( ) ) ;
2015-12-01 00:32:57 +01:00
2015-09-07 21:51:13 +02:00
// Always return OK
JsonObjectBuilder response = Json . createObjectBuilder ( )
. add ( " status " , " ok " ) ;
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
2013-08-17 14:16:55 +02:00
}
2020-08-28 18:09:54 +02:00
/ * *
* Get the LDAP authentication configuration .
*
* @api { get } / app / config_ldap Get the LDAP authentication configuration
* @apiName GetAppConfigLdap
* @apiGroup App
* @apiSuccess { Boolean } enabled LDAP authentication enabled
* @apiSuccess { String } host LDAP server host
* @apiSuccess { Integer } port LDAP server port
* @apiSuccess { String } admin_dn Admin DN
* @apiSuccess { String } admin_password Admin password
* @apiSuccess { String } base_dn Base DN
* @apiSuccess { String } filter LDAP filter
* @apiSuccess { String } default_email LDAP default email
* @apiSuccess { Integer } default_storage LDAP default storage
* @apiError ( client ) ForbiddenError Access denied
* @apiPermission admin
* @apiVersion 1 . 9 . 0
*
* @return Response
* /
@GET
@Path ( " config_ldap " )
public Response getConfigLdap ( ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ConfigDao configDao = new ConfigDao ( ) ;
Config enabled = configDao . getById ( ConfigType . LDAP_ENABLED ) ;
JsonObjectBuilder response = Json . createObjectBuilder ( ) ;
if ( enabled ! = null & & Boolean . parseBoolean ( enabled . getValue ( ) ) ) {
// LDAP enabled
response . add ( " enabled " , true )
. add ( " host " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_HOST ) )
. add ( " port " , ConfigUtil . getConfigIntegerValue ( ConfigType . LDAP_PORT ) )
2023-03-21 21:56:14 +01:00
. add ( " usessl " , ConfigUtil . getConfigBooleanValue ( ConfigType . LDAP_USESSL ) )
2020-08-28 18:09:54 +02:00
. add ( " admin_dn " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_ADMIN_DN ) )
. add ( " admin_password " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_ADMIN_PASSWORD ) )
. add ( " base_dn " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_BASE_DN ) )
. add ( " filter " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_FILTER ) )
. add ( " default_email " , ConfigUtil . getConfigStringValue ( ConfigType . LDAP_DEFAULT_EMAIL ) )
. add ( " default_storage " , ConfigUtil . getConfigLongValue ( ConfigType . LDAP_DEFAULT_STORAGE ) ) ;
} else {
// LDAP disabled
response . add ( " enabled " , false ) ;
}
return Response . ok ( ) . entity ( response . build ( ) ) . build ( ) ;
}
/ * *
* Configure the LDAP authentication .
*
* @api { post } / app / config_ldap Configure the LDAP authentication
* @apiName PostAppConfigLdap
* @apiGroup App
* @apiParam { Boolean } enabled LDAP authentication enabled
* @apiParam { String } host LDAP server host
* @apiParam { Integer } port LDAP server port
2023-03-21 21:56:14 +01:00
* @apiParam { Boolean } use SSL ( ldaps )
2020-08-28 18:09:54 +02:00
* @apiParam { String } admin_dn Admin DN
* @apiParam { String } admin_password Admin password
* @apiParam { String } base_dn Base DN
* @apiParam { String } filter LDAP filter
* @apiParam { String } default_email LDAP default email
* @apiParam { Integer } default_storage LDAP default storage
* @apiError ( client ) ForbiddenError Access denied
* @apiError ( client ) ValidationError Validation error
* @apiPermission admin
* @apiVersion 1 . 9 . 0
*
* @param enabled LDAP authentication enabled
* @param host LDAP server host
* @param portStr LDAP server port
2023-03-21 21:56:14 +01:00
* @param usessl LDAP use SSL ( ldaps )
2020-08-28 18:09:54 +02:00
* @param adminDn Admin DN
* @param adminPassword Admin password
* @param baseDn Base DN
* @param filter LDAP filter
* @param defaultEmail LDAP default email
* @param defaultStorageStr LDAP default storage
* @return Response
* /
@POST
@Path ( " config_ldap " )
public Response configLdap ( @FormParam ( " enabled " ) Boolean enabled ,
@FormParam ( " host " ) String host ,
@FormParam ( " port " ) String portStr ,
2023-03-21 21:56:14 +01:00
@FormParam ( " usessl " ) Boolean usessl ,
2020-08-28 18:09:54 +02:00
@FormParam ( " admin_dn " ) String adminDn ,
@FormParam ( " admin_password " ) String adminPassword ,
@FormParam ( " base_dn " ) String baseDn ,
@FormParam ( " filter " ) String filter ,
@FormParam ( " default_email " ) String defaultEmail ,
@FormParam ( " default_storage " ) String defaultStorageStr ) {
if ( ! authenticate ( ) ) {
throw new ForbiddenClientException ( ) ;
}
checkBaseFunction ( BaseFunction . ADMIN ) ;
ConfigDao configDao = new ConfigDao ( ) ;
if ( enabled ! = null & & enabled ) {
// LDAP enabled, validate everything
ValidationUtil . validateLength ( host , " host " , 1 , 250 ) ;
ValidationUtil . validateInteger ( portStr , " port " ) ;
ValidationUtil . validateLength ( adminDn , " admin_dn " , 1 , 250 ) ;
ValidationUtil . validateLength ( adminPassword , " admin_password " , 1 , 250 ) ;
ValidationUtil . validateLength ( baseDn , " base_dn " , 1 , 250 ) ;
ValidationUtil . validateLength ( filter , " filter " , 1 , 250 ) ;
if ( ! filter . contains ( " USERNAME " ) ) {
throw new ClientException ( " ValidationError " , " 'filter' must contains 'USERNAME' " ) ;
}
ValidationUtil . validateLength ( defaultEmail , " default_email " , 1 , 250 ) ;
ValidationUtil . validateLong ( defaultStorageStr , " default_storage " ) ;
configDao . update ( ConfigType . LDAP_ENABLED , Boolean . TRUE . toString ( ) ) ;
configDao . update ( ConfigType . LDAP_HOST , host ) ;
configDao . update ( ConfigType . LDAP_PORT , portStr ) ;
2023-03-21 21:56:14 +01:00
configDao . update ( ConfigType . LDAP_USESSL , usessl . toString ( ) ) ;
2020-08-28 18:09:54 +02:00
configDao . update ( ConfigType . LDAP_ADMIN_DN , adminDn ) ;
configDao . update ( ConfigType . LDAP_ADMIN_PASSWORD , adminPassword ) ;
configDao . update ( ConfigType . LDAP_BASE_DN , baseDn ) ;
configDao . update ( ConfigType . LDAP_FILTER , filter ) ;
configDao . update ( ConfigType . LDAP_DEFAULT_EMAIL , defaultEmail ) ;
configDao . update ( ConfigType . LDAP_DEFAULT_STORAGE , defaultStorageStr ) ;
} else {
// LDAP disabled
configDao . update ( ConfigType . LDAP_ENABLED , Boolean . FALSE . toString ( ) ) ;
}
// Reset the LDAP pool to reconnect with the new configuration
LdapAuthenticationHandler . reset ( ) ;
return Response . ok ( ) . build ( ) ;
}
2013-07-27 18:33:20 +02:00
}