PortalImpl implements Portal { @Override public boolean hasPermission(User user, Permission permission) { if(permission.isAccessibleToEveryone()) { return true; } Identity identity; if (user == User.anonymous()) { identity = new Identity(IdentityConstants.ANONIM); } else { try { identity = identityRegistry.getIdentity(user.getId()); } catch (Throwable t) { throw new ApiException("Failed top retrieve identity", t); } } if (identity == null) { try { identity = authenticator.createIdentity(user.getId()); } catch (Throwable t) { throw new ApiException("Failed to retrieve user identity", t); } if (identity == null) { throw new EntityNotFoundException("User not found"); } try { identityRegistry.register(identity); } catch (Throwable t) { throw new ApiException("Failed to register identity", t); } } try { for(Membership membership : permission.getMemberships()) { if(acl.hasPermission(identity, membership.toString())) { return true; } } return false; } catch (Throwable t) { throw new ApiException("Failed to check permissions", t); } } PortalImpl(DataStorage dataStorage, PageService pageService, NavigationService navigationService,
                      DescriptionService descriptionService, ResourceBundleManager bundleManager, Authenticator authenticator,
                      IdentityRegistry identityRegistry, UserACL acl, UserPortalConfigService userPortalConfigService,
                      OAuthProviderAccessor oauthProviderAccessor); @Override Site getSite(SiteId siteId); @Override Site createSite(SiteId siteId); @Override Site createSite(SiteId siteId, String templateName); @Override List<Site> findSites(SiteQuery query); @Override void saveSite(Site site); @Override boolean removeSite(SiteId siteId); @Override Navigation getNavigation(SiteId siteId); @Override PageBuilder newPageBuilder(); @Override ApplicationRegistry getApplicationRegistry(); @Override Page getPage(PageId pageId); List<ContainerItem> getPageRootContainer(PageContext pageContext); @Override Page createPage(PageId pageId); @Override List<Page> findPages(PageQuery query); @Override void savePage(Page page); @Override boolean removePage(PageId pageId); @Override boolean hasPermission(User user, Permission permission); @Override OAuthProvider getOAuthProvider(String oauthProviderKey);  }
@Test public void hasPermission() { createSite(new SiteId("permissions")); Page page = portal.createPage(new PageId("permissions", "page1")); page.setAccessPermission(Permission.everyone()); page.setEditPermission(new Permission("*", new Group("/platform/administrators"))); portal.savePage(page); page = portal.getPage(page.getId()); assertTrue(portal.hasPermission(new User("root"), page.getAccessPermission())); assertTrue(portal.hasPermission(new User("root"), page.getEditPermission())); assertTrue(portal.hasPermission(User.anonymous(), page.getAccessPermission())); assertFalse(portal.hasPermission(User.anonymous(), page.getEditPermission())); }