* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.onap.portalapp.portal.domain.EPRole;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.onap.portalapp.portal.domain.EPRole;
private static final String decodeValueOfForwardSlash = "2f";
private static final String decodeValueOfHyphen = "2d";
private static final String decodeValueOfAsterisk = "2a";
private static final String decodeValueOfForwardSlash = "2f";
private static final String decodeValueOfHyphen = "2d";
private static final String decodeValueOfAsterisk = "2a";
* @param ePRoleFunctionService
* role function service
* @throws DecoderException
*/
@SuppressWarnings("rawtypes")
public static void setUserSession(HttpServletRequest request, EPUser user, Set applicationMenuData,
* @param ePRoleFunctionService
* role function service
* @throws DecoderException
*/
@SuppressWarnings("rawtypes")
public static void setUserSession(HttpServletRequest request, EPUser user, Set applicationMenuData,
HttpSession session = request.getSession(true);
// clear the current user session to avoid any conflicts
HttpSession session = request.getSession(true);
// clear the current user session to avoid any conflicts
session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_NAME), user.getFullName());
ServletContext context = session.getServletContext();
session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_NAME), user.getFullName());
ServletContext context = session.getServletContext();
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "setUserSession failed to get licenseVerification attribute",
e);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "setUserSession failed to get licenseVerification attribute",
e);
private static void setAllRoleFunctions(List<RoleFunction> allRoleFunctions, HttpSession session) throws RoleFunctionException {
if (allRoleFunctions == null)
return;
private static void setAllRoleFunctions(List<RoleFunction> allRoleFunctions, HttpSession session) throws RoleFunctionException {
if (allRoleFunctions == null)
return;
HttpSession session = AppUtils.getSession(request);
roles = (HashMap) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME));
HttpSession session = AppUtils.getSession(request);
roles = (HashMap) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME));
@SuppressWarnings({ "rawtypes", "unchecked" })
private static HashMap getAllUserRoles(EPUser user) {
HashMap roles = new HashMap();
@SuppressWarnings({ "rawtypes", "unchecked" })
private static HashMap getAllUserRoles(EPUser user) {
HashMap roles = new HashMap();
// Additionally; the account admin role is overloaded between onap
// portal and partners; lets also include that
// Additionally; the account admin role is overloaded between onap
// portal and partners; lets also include that
- Iterator<EPUserApp> appRolesIterator = user.getEPUserApps().iterator();
- while (appRolesIterator.hasNext()) {
- EPRole role = (EPRole) appRolesIterator.next().getRole();
+ for (EPUserApp epUserApp : user.getEPUserApps()) {
+ EPRole role = epUserApp.getRole();
if (role.getActive() && role.getId().equals(ACCOUNT_ADMIN_ROLE_ID)) {
roles.put(role.getId(), role);
if (role.getActive() && role.getId().equals(ACCOUNT_ADMIN_ROLE_ID)) {
roles.put(role.getId(), role);
private static void addChildRoles(EPRole role, HashMap roles) {
Set childRoles = role.getChildRoles();
private static void addChildRoles(EPRole role, HashMap roles) {
Set childRoles = role.getChildRoles();
- if (childRoles != null && childRoles.size() > 0) {
- Iterator j = childRoles.iterator();
- while (j.hasNext()) {
- EPRole childRole = (EPRole) j.next();
+ if (childRoles != null && !childRoles.isEmpty()) {
+ for (Object o : childRoles) {
+ EPRole childRole = (EPRole) o;
if (childRole.getActive()) {
roles.put(childRole.getId(), childRole);
if (childRole.getActive()) {
roles.put(childRole.getId(), childRole);
logger.debug(EELFLoggerDelegate.debugLogger,
"One header is " + headerName + " : " + request.getHeader(headerName));
if (headerName.equalsIgnoreCase(SystemProperties.ECOMP_REQUEST_ID)) {
logger.debug(EELFLoggerDelegate.debugLogger,
"One header is " + headerName + " : " + request.getHeader(headerName));
if (headerName.equalsIgnoreCase(SystemProperties.ECOMP_REQUEST_ID)) {
public static Boolean matchRoleFunctions(String portalApiPath, Set<? extends String> roleFunctions) {
String[] path = portalApiPath.split("/");
public static Boolean matchRoleFunctions(String portalApiPath, Set<? extends String> roleFunctions) {
String[] path = portalApiPath.split("/");
if (path.length > 1) {
roleFunList = roleFunctions.stream().filter(item -> item.startsWith(path[0])).collect(Collectors.toList());
if (roleFunList.size() >= 1) {
if (path.length > 1) {
roleFunList = roleFunctions.stream().filter(item -> item.startsWith(path[0])).collect(Collectors.toList());
if (roleFunList.size() >= 1) {
if (!roleFunctionArray[i].equals("*")) {
Pattern p = Pattern.compile(Pattern.quote(path[i]), Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(roleFunctionArray[i]);
b = m.matches();
if (!roleFunctionArray[i].equals("*")) {
Pattern p = Pattern.compile(Pattern.quote(path[i]), Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(roleFunctionArray[i]);
b = m.matches();