private void initResourceContents(NavigationElement navigationElement) { try { SimpleIdentifier<String> textIdentifier = new SimpleIdentifier<String>(navigationElement.getLookup() + ".menu-name"); ServiceRequest<SimpleIdentifier<String>> textResourceRequest = new ServiceRequest<SimpleIdentifier<String>>(textIdentifier); ServiceResponse<TextResource> textResourceResponse = readTextResourceByLookupBroker.perform(textResourceRequest); if (textResourceResponse.isSuccess()) { navigationElement.setTextResourceVersion( textResourceResponse.getItem().getResourceVersion()); } SimpleIdentifier<String> imageIdentifier = new SimpleIdentifier<String>(navigationElement.getLookup() + ".menu-icon"); ServiceRequest<SimpleIdentifier<String>> imageResourceRequest = new ServiceRequest<SimpleIdentifier<String>>(imageIdentifier); ServiceResponse<ImageResource> imageResourceResponse = readImageResourceByLookupBroker.perform(imageResourceRequest); if (imageResourceResponse.isSuccess()) { navigationElement.setImageResourceVersion( imageResourceResponse.getItem().getResourceVersion()); } } catch (Exception e) { logger.error(e); } }
@Override public ServiceResponse<NavigationElementTree> perform(ServiceRequest<NamedValues> request) throws Exception { String lookup = (String) request.getData().get("lookup"); boolean lazyLoadResource = (Boolean) request.getData().get("lazyLoadResource"); List<NavigationElementTree> navigationElementTrees = new ArrayList<NavigationElementTree>(); if (ConfigContainer.isAppInstalled() && StringUtils.isNotBlank(lookup)) { String packageLookup = StringUtils.getPackageLookup(lookup); if (packageLookup == null) { logger.warn(MSG_WRONG_LOOKUP); } else { OPFContext context = OPFContext.getContext(); INavElementContainer navElementContainer = context.getNavElementContainer(); List<NavigationElement> navElementListByPackage = navElementContainer.getNavElementListByPackage(packageLookup); if (navElementListByPackage == null || navElementListByPackage.isEmpty()) { logger.warn(MSG_APPROPRIATE_NAVIGATION_ELEMENTS_WERE_FOUND); } else { NavigationElementTree navigationElementTree = null; NavigationElement parent = null; for (NavigationElement vo : navElementListByPackage) { if (vo.getLookup().equalsIgnoreCase(lookup)) { parent = vo; navigationElementTree = convert(parent); break; } } if (parent == null) { logger.warn(MSG_NO_SUCH_PARENT_NAVIGATION_WAS_FOUND); } else { buildTree(navigationElementTree, parent, navElementListByPackage, lazyLoadResource); navigationElementTrees = navigationElementTree.getChildren(); } } } } return new ServiceResponse<NavigationElementTree>( navigationElementTrees, "Return tree navigation elements.", true); }
private void buildTree( NavigationElementTree parentNavigationElementTree, NavigationElement parent, List<NavigationElement> navigationElementList, boolean lazyLoadResource) { List<NavigationElementTree> children = parentNavigationElementTree.getChildren(); for (NavigationElement navigationElement : navigationElementList) { if (parent.getLookup().endsWith(navigationElement.getPath())) { OpenFlamePrincipal principal = OPFContext.getContext().getPrincipal(); if (principal.checkUserPermission(navigationElement)) { if (!lazyLoadResource) { initResourceContents(navigationElement); } NavigationElementTree navigationElementTree = convert(navigationElement); children.add(navigationElementTree); buildTree( navigationElementTree, navigationElement, navigationElementList, lazyLoadResource); } } } Collections.sort(children, NavigationElementTree.SORT_POSITION); }
@Override public void execute( Map<String, String> map, HttpServletRequest request, HttpServletResponse response, NavigationElement currentNavigationElement) { if (currentNavigationElement != null && currentNavigationElement.getPageUrl().equals(getLoginPageUrl())) { try { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); KeyPair pair = kpg.generateKeyPair(); String publicKey = new Base64Encoder().encode(pair.getPublic().getEncoded()); map.put("publicKey", "'" + publicKey.replaceAll("\n", "") + "'"); HttpSession session = request.getSession(); session.setAttribute( OpenFlameSecurityConstants.PASSWORD_ENCRYPTED_PRIVATE_KEY, pair.getPrivate()); } catch (NoSuchAlgorithmException e) { logger.error( "Can't generate private/public keys for sign on process.\n" + e.getMessage(), e); } } }
private NavigationElementTree convert(NavigationElement navigationElement) { NavigationElementTree navigationElementTree = new NavigationElementTree(); String name = navigationElement.getName(); if (navigationElement.getTextResourceVersion() != null) { name = navigationElement.getTextResourceVersion().getText(); } navigationElementTree.setName(name); navigationElementTree.setUrlPath(navigationElement.getUrlPath()); navigationElementTree.setPageUrl(navigationElement.getPageUrl()); navigationElementTree.setElementType(navigationElement.getElementType()); navigationElementTree.setPath(navigationElement.getPath()); navigationElementTree.setLookup(navigationElement.getLookup()); navigationElementTree.setSortPosition(navigationElement.getSortPosition()); navigationElementTree.setChildren(new ArrayList<NavigationElementTree>()); navigationElementTree.setAllowDrag(false); navigationElementTree.setAllowDrop(false); navigationElementTree.setExpandable(true); navigationElementTree.setExpanded(false); navigationElementTree.setHidden( navigationElement.getHidden() != null && navigationElement.getHidden()); return navigationElementTree; }