Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
17   95   14   8.5
10   43   0.82   2
2     7  
1    
 
  RequestValidator       Line # 34 17 0% 14 1 96.6% 0.9655172
 
  (19)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6    *
7    * ARESTC is free software: you can redistribute it and/or modify it under the
8    * terms of the Lesser General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10    * version.
11    *
12    * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY
13    * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14    * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15    *
16    * You should have received a copy of the Lesser General Public License along
17    * with ARESTC. If not, see <http://www.gnu.org/licenses/>.
18    */
19    package net.sf.arestc.core.validations;
20   
21    import java.util.Map;
22   
23    import net.sf.arestc.core.services.RESTService;
24   
25    import org.apache.commons.configuration.ConfigurationException;
26    import org.apache.commons.httpclient.Credentials;
27   
28    // TODO: Auto-generated Javadoc
29    /**
30    * The Class RequestValidator.
31    *
32    * @author georgosn
33    */
 
34    public class RequestValidator {
35   
36    /**
37    * Validate request.
38    *
39    * @param parameters
40    * the parameters
41    * @param credentials
42    * the credentials
43    * @param service
44    * the service
45    * @return true, if successful
46    */
 
47  21 toggle public boolean isValidRequest(final Map<String, Object> parameters,
48    final Credentials credentials, final RESTService service) {
49  21 boolean ret = true;
50  21 if (null == service || null == parameters) {
51  2 ret = false;
52    } else {
53  19 try {
54  19 service.getServiceURL(parameters);
55  19 if (service.isAuthenticationRequired()) {
56  15 ret = validateCredentials(credentials, service);
57    }
58  19 if (ret
59    && !parameters.keySet().containsAll(
60    service.getUnionOfParameters())) {
61  2 ret = false;
62    }
63    } catch (final ConfigurationException e) {
64  0 ret = false;
65    }
66   
67    }
68  21 return ret;
69    }
70   
71    /**
72    * Validate credentials.
73    *
74    * @param credentials
75    * the credentials
76    * @param service
77    * the service
78    * @return true, if successful
79    */
 
80  15 toggle private boolean validateCredentials(final Credentials credentials,
81    final RESTService service) {
82  15 boolean ret = true;
83   
84  15 if (null == service.getAuthenticatingUser()
85    || !service.getAuthenticatingUser().equals("admin")
86    && null == credentials) {
87  1 ret = false;
88  14 } else if (null != service.getAuthenticatingUser()
89    && service.getAuthenticatingUser().equals("admin")
90    && null == service.getAdminCredentials()) {
91  2 ret = false;
92    }
93  15 return ret;
94    }
95    }