1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal.factory.template

File SecureMailTemplateManager.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
4
2
1
78
42
3
0.75
2
2
1.5

Classes

Class Line # Actions
SecureMailTemplateManager 45 4 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.mail.internal.factory.template;
21   
22    import java.util.Map;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27    import javax.mail.MessagingException;
28   
29    import org.xwiki.bridge.DocumentAccessBridge;
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.security.authorization.AuthorizationManager;
33    import org.xwiki.security.authorization.Right;
34   
35    /**
36    * Secure implementation that checks if the current user has vew permissions on the mail template document. To be used
37    * by scripts.
38    *
39    * @version $Id: 0b126af7ee6e402647a7236821c1d710b1720d1c $
40    * @since 6.1RC1
41    */
42    @Component
43    @Named("secure")
44    @Singleton
 
45    public class SecureMailTemplateManager implements MailTemplateManager
46    {
47    @Inject
48    private MailTemplateManager templateManager;
49   
50    @Inject
51    private AuthorizationManager authorizationManager;
52   
53    @Inject
54    private DocumentAccessBridge documentBridge;
55   
 
56  7 toggle @Override
57    public String evaluate(DocumentReference templateReference, String property, Map<String, Object> velocityVariables,
58    Object localeValue) throws MessagingException
59    {
60    // Verify that the current user has the view right on the Template document
61  7 if (!this.authorizationManager.hasAccess(
62    Right.VIEW, this.documentBridge.getCurrentUserReference(), templateReference))
63    {
64  1 throw new MessagingException(
65    String.format("Current user [%s] has no permission to view Mail Template Document [%s]",
66    this.documentBridge.getCurrentUserReference(), templateReference));
67    }
68   
69  6 return this.templateManager.evaluate(templateReference, property, velocityVariables, localeValue);
70    }
71   
 
72  1 toggle @Override
73    public String evaluate(DocumentReference documentReference, String property,
74    Map<String, Object> velocityVariables) throws MessagingException
75    {
76  1 return evaluate(documentReference, property, velocityVariables, null);
77    }
78    }