12/11/2018
Appeler les services FlowerDocs en tant qu’administrateur
Exemple d’utilisation des web-services FlowerDocs en tant qu’administrateur (dans un plugin par exemple), sans modifier l’authentification courante.
L’intérêt est double :
- Après appel au service, on a toujours accès au contexte utilisateur (non-admin)
- Le périmètre reste contenu - il n’y a pas de risque que d’autres actions soient effectuées involontairement en tant qu’administrateur par la suite
Pour celà, on utilise la méthode RunAsAdminExecutor.execute()
. Exemples ci-dessous :
@Autowired
private DocumentService documentService;
public void get(List<Id> componentIds, List<Document> results) throws FunctionalException, TechnicalException
{
Command command = new Command()
{
@Override
public void execute() throws FunctionalException, TechnicalException
{
results.addAll(documentService.get(componentIds));
}
};
executeAsAdmin(command);
}
public void update(List<Document> documentsToUpdate) throws FunctionalException, TechnicalException
{
Command command = new Command()
{
@Override
public void execute() throws FunctionalException, TechnicalException
{
documentService.update(documentsToUpdate);
}
};
executeAsAdmin(command);
}