summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java
blob: e01abfbbe7b7173c54be8730d06bad582b2095d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.openecomp.portalsdk.core.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.openecomp.portalsdk.core.domain.UrlsAccessible;
import org.openecomp.portalsdk.core.web.support.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;

public class UrlAccessImpl implements UrlAccessService{

	 @Autowired
	 DataAccessService dataAccessService;
	


	@Override
	public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) {
		boolean isAccessible = false;
		Map<String, String> params = new HashMap<>();
		params.put("current_url", currentUrl);
		List list = dataAccessService.executeNamedQuery("restrictedUrls", params, null);
		
		// loop through the list of restricted URL's
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				/*
				 * Object[] restrictedUrl = (Object[])list.get(i);
				 * 
				 * String url = (String)restrictedUrl[0]; String functionCd =
				 * (String)restrictedUrl[1];
				 */
				UrlsAccessible urlFunctions = (UrlsAccessible) list.get(i);
				// String url = (String) urlFunctions.getUrl();
				String functionCd = (String) urlFunctions.getFunctionCd();
				if (UserUtils.isAccessible(request, functionCd)) {
					isAccessible = true;
				}
			}
			return isAccessible;
	     	}
		return true;
	}

}