MagicAceDefinition { @SuppressWarnings( "unchecked" ) public static List<MagicAceDefinition> parseYamlMagicAceDefinitions( InputStream yamlFileInputStream, SessionImpl systemSession ) throws RepositoryException { List<MagicAceDefinition> magicAceDefinitions = new ArrayList<MagicAceDefinition>(); try { Yaml yaml = new Yaml(); Map<String, Object> map = (Map<String, Object>) yaml.load( yamlFileInputStream ); List<Map<String, Object>> magicAceList = (List<Map<String, Object>>) map.get( "MagicAces" ); for ( Map<String, Object> magicAceMap : magicAceList ) { MagicAceDefinition pam = parseMagicAceDefinition( magicAceMap, systemSession ); magicAceDefinitions.add( pam ); } } catch ( Exception e ) { throw new RuntimeException( "Could not parse magic ace configurations from Yaml file.", e ); } return magicAceDefinitions; } MagicAceDefinition( final String path, final String logicalRole, final Privilege[] privileges,
      final boolean applyToTarget, final boolean applyToChildren, final boolean applyToAncestors,
      final String[] exceptChildren ); @Override int hashCode(); @Override boolean equals( Object obj ); @SuppressWarnings( "nls" ) @Override String toString(); @SuppressWarnings( "unchecked" ) static List<MagicAceDefinition> parseYamlMagicAceDefinitions( InputStream yamlFileInputStream,
      SessionImpl systemSession ); public String path; public String logicalRole; public Privilege[] privileges; public boolean applyToChildren; public boolean applyToAncestors; public boolean applyToTarget; public String[] exceptChildren; }
@Test public void parseYamlMagicAceDefinitionsTest() throws Exception { List<MagicAceDefinition> aces = parseYamlFile( "./src/test/resources/MagicAceTest.yaml" ); assertEquals( 3, aces.size() ); boolean[] caseHit = new boolean[3]; for ( MagicAceDefinition ace : aces ) { switch ( ace.path ) { case "{0}": caseHit[0] = true; assertEquals( "org.pentaho.security.administerSecurity", ace.logicalRole ); assertNotNull( ace.privileges ); assertEquals( 1, ace.privileges.length ); assertEquals( true, ace.applyToTarget ); assertEquals( true, ace.applyToChildren ); assertEquals( false, ace.applyToAncestors ); assertNull( ace.exceptChildren ); break; case "{0}/etc": caseHit[1] = true; assertEquals( "org.pentaho.repository.read", ace.logicalRole ); assertNotNull( ace.privileges ); assertEquals( 2, ace.privileges.length ); assertEquals( true, ace.applyToTarget ); assertEquals( false, ace.applyToChildren ); assertEquals( false, ace.applyToAncestors ); assertNotNull( ace.exceptChildren ); assertEquals( 1, ace.exceptChildren.length ); assertEquals( "{0}/etc/pdi/databases", ace.exceptChildren[0] ); break; case "{0}/foo": caseHit[2] = true; assertEquals( "org.pentaho.repository.create", ace.logicalRole ); assertNotNull( ace.privileges ); assertEquals( 7, ace.privileges.length ); assertEquals( true, ace.applyToTarget ); assertEquals( false, ace.applyToChildren ); assertEquals( true, ace.applyToAncestors ); assertNotNull( ace.exceptChildren ); assertEquals( 2, ace.exceptChildren.length ); assertEquals( "one", ace.exceptChildren[0] ); assertEquals( "two", ace.exceptChildren[1] ); break; default: fail( "Unknown Ace path" ); } } assertTrue( "All aces in yaml file were not present", caseHit[0] && caseHit[1] && caseHit[2] ); }