|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RequestValidator | Line # 34 | 17 | 0% | 14 | 1 | 96.6% |
0.9655172
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (19) | |||
| Result | |||
|
0.6896552
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullServiceParams
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullServiceParams
|
1 PASS | |
|
0.6896552
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationNoCred
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationNoCred
|
1 PASS | |
|
0.6896552
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestFullServiceParams
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestFullServiceParams
|
1 PASS | |
|
0.6896552
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationAdminNoCred
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationAdminNoCred
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testFileDownload
net.sf.arestc.core.OverallDesignTest.testFileDownload
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNotNullServiceParams
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNotNullServiceParams
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationUserCred
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationUserCred
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testRepositoryMultiPost
net.sf.arestc.core.OverallDesignTest.testRepositoryMultiPost
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testFileUpload
net.sf.arestc.core.OverallDesignTest.testFileUpload
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testRepositoryCreate
net.sf.arestc.core.OverallDesignTest.testRepositoryCreate
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestFullParams
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestFullParams
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.OverallDesignTest.testRepositoryDelete
net.sf.arestc.core.OverallDesignTest.testRepositoryDelete
|
1 PASS | |
|
0.6551724
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationAdminAdminCred
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationAdminAdminCred
|
1 PASS | |
|
0.62068963
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationUserNoCred
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestAuthenticationUserNoCred
|
1 PASS | |
|
0.37931034
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
|
1 PASS | |
|
0.37931034
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
|
1 PASS | |
|
0.20689656
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullService
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullService
|
1 PASS | |
|
0.20689656
|
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullParameters
net.sf.arestc.core.validations.RequestValidatorTest.testValidateRequestNullParameters
|
1 PASS | |
| 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 |
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 |
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 | } | |
|
||||||||||||