javax.validation.Validator used to fix this vulnerability issue.
Issue-ID: OJSI-20
Change-Id: I2e8188d9dabf634fcaf41b8d42d0f7160cc0886d
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
import org.onap.portalapp.portal.service.AdminRolesService;
import org.onap.portalapp.portal.service.BasicAuthAccountService;
import org.onap.portalapp.util.EPUserUtils;
+import org.onap.portalapp.validation.DataValidator;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
private static final String ADMIN_ONLY_OPERATIONS = "Admin Only Operation! ";
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(BasicAuthAccountController.class);
+ private final DataValidator dataValidator = new DataValidator();
@Autowired
private BasicAuthAccountService basicAuthAccountService;
public PortalRestResponse<String> createBasicAuthAccount(HttpServletRequest request, HttpServletResponse response,
@RequestBody BasicAuthCredentials newBasicAuthAccount) throws Exception {
+
+
EPUser user = EPUserUtils.getUserSession(request);
if (!adminRolesService.isSuperAdmin(user)) {
return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, AUTHORIZATION_REQUIRED,
return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE,
"newBasicAuthAccount cannot be null or empty");
}
- long accountId = basicAuthAccountService.saveBasicAuthAccount(newBasicAuthAccount);
+
+ if(!dataValidator.isValid(newBasicAuthAccount)){
+ return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "createBasicAuthAccount() failed, new credential are not safe",
+ "");
+ }
+
+ long accountId;
+ try {
+ accountId = basicAuthAccountService.saveBasicAuthAccount(newBasicAuthAccount);
+ } catch (Exception e){
+ return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE, e.getMessage());
+ }
List<Long> endpointIdList = new ArrayList<>();
try {
import java.util.List;
+import javax.validation.Valid;
+import org.hibernate.validator.constraints.SafeHtml;
import org.onap.portalsdk.core.domain.support.DomainVo;
public class BasicAuthCredentials extends DomainVo {
private static final long serialVersionUID = 1L;
- public BasicAuthCredentials() {
-
- }
-
private Long id;
+ @SafeHtml
private String applicationName;
+ @SafeHtml
private String username;
+ @SafeHtml
private String password;
+ @SafeHtml
private String isActive;
+ @Valid
private List<EPEndpoint> endpoints;
public Long getId() {
*/
package org.onap.portalapp.portal.domain;
+import org.hibernate.validator.constraints.SafeHtml;
import org.onap.portalsdk.core.domain.support.DomainVo;
public class EPEndpoint extends DomainVo {
}
private Long id;
+ @SafeHtml
private String name;
public Long getId() {
import org.onap.portalapp.portal.domain.EPEndpointAccount;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.validation.DataValidator;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.service.DataAccessService;
@EPMetricsLog
public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MicroserviceServiceImpl.class);
-
+ private final DataValidator dataValidator = new DataValidator();
@Autowired
private DataAccessService dataAccessService;
@Override
public Long saveBasicAuthAccount(BasicAuthCredentials newCredential) throws Exception {
+
+ if(!dataValidator.isValid(newCredential)){
+ throw new Exception("saveBasicAuthAccount() failed, new credential are not safe");
+ }
if (newCredential.getPassword() != null)
newCredential.setPassword(encryptedPassword(newCredential.getPassword()));
try{
assertEquals(actualResponse, expectedResponse);
}
+ @Test
+ public void createBasicAuthAccountXSSTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+ basicAuthCredentials.setPassword("<script>alert(“XSS”);</script>");
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("createBasicAuthAccount() failed, new credential are not safe");
+ expectedResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+ long accountd = 1;
+
+ Mockito.when(basicAuthAccountService.saveBasicAuthAccount(basicAuthCredentials)).thenReturn(accountd);
+
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest,
+ mockedResponse, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
@Test
public void createBasicAuthAccountAdminTest() throws Exception {
BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
Mockito.doNothing().when(dataAccessService).saveDomainObject(basicAuthCredentials, null);
basicAuthAccountServiceImpl.saveBasicAuthAccount(basicAuthCredentials);
+ }
+
+ @Test(expected= Exception.class)
+ public void saveBasicAuthAccountValidTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials();
+ basicAuthCredentials.setPassword("<IMG SRC=\"jav\tascript:alert('XSS');\">");
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(basicAuthCredentials, null);
+ basicAuthAccountServiceImpl.saveBasicAuthAccount(basicAuthCredentials);
+
}
@Test