1 package org.openecomp.portalsdk.core.service;
3 import java.util.ArrayList;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpSession;
10 import org.openecomp.portalsdk.core.domain.RoleFunction;
11 import org.openecomp.portalsdk.core.domain.User;
12 import org.openecomp.portalsdk.core.exception.SessionExpiredException;
13 import org.openecomp.portalsdk.core.util.SystemProperties;
14 import org.openecomp.portalsdk.core.web.support.AppUtils;
15 import org.openecomp.portalsdk.core.web.support.UserUtils;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.transaction.annotation.Transactional;
20 public class UrlAccessCentalizedImpl implements UrlAccessService {
23 AppService appService;
26 RoleService roleService;
30 public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) {
32 boolean isAccessible = false;
33 User user = UserUtils.getUserSession(request);
36 HttpSession session = AppUtils.getSession(request);
38 if (session == null) {
39 throw new SessionExpiredException();
42 @SuppressWarnings("unchecked")
43 List<RoleFunction> allRoleFunctionsList = (List<RoleFunction>) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTION_LIST));
45 List<String> allUrls = new ArrayList<String>();
47 for (int i = 0; i < allRoleFunctionsList.size(); i++) {
48 if (allRoleFunctionsList.get(i).getCode() != null && ((String) allRoleFunctionsList.get(i).getCode()).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) {
49 String functionCd = ((String) allRoleFunctionsList.get(i).getCode()).substring(4).toUpperCase();
50 allUrls.add(functionCd);
54 @SuppressWarnings("unchecked")
55 Set<RoleFunction> roleFunction = UserUtils.getRoleFunctions(request);
56 List list = new ArrayList<>(roleFunction);
57 List<String> UserURLlist = new ArrayList<String>();
59 if (list != null && list.size() > 0) {
60 for (int i = 0; i < list.size(); i++) {
61 if (list.get(i) != null && ((String) list.get(i)).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) {
62 String functionCd = ((String) list.get(i)).substring(4).toUpperCase();
63 UserURLlist.add(functionCd);
68 if((!UserURLlist.contains(currentUrl) && !allUrls.contains(currentUrl)) || (UserURLlist.contains(currentUrl) && allUrls.contains(currentUrl)))