@Test public void testParseXacml() throws Exception { assertEquals(acl.getEntries(), XACMLUtils.parseXacml(this.getClass().getResourceAsStream("/xacml.xml")).getEntries()); }
public static AccessControlList parseXacml(InputStream xacml) throws XACMLParsingException { try { @SuppressWarnings("unchecked") final AccessControlList acl = new AccessControlList(); final List<AccessControlEntry> entries = acl.getEntries(); final PolicyType policy = ((JAXBElement<PolicyType>) XACMLUtils.jBossXacmlJaxbContext.createUnmarshaller().unmarshal(xacml)).getValue(); for (Object object : policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { if (!(object instanceof RuleType)) { throw new XACMLParsingException("Object " + object + " of policy " + policy + " is not of type RuleType"); } RuleType rule = (RuleType) object; if (rule.getTarget() == null) { if (rule.getRuleId().equals("DenyRule")) { logger.trace("Skipping global deny rule"); continue; } throw new XACMLParsingException("Empty rule " + rule + " in policy " + policy); } String role = null; String actionForAce = null; try { ActionType action = rule.getTarget().getActions().getAction().get(0); actionForAce = (String) action.getActionMatch().get(0).getAttributeValue().getContent().get(0); @SuppressWarnings("unchecked") JAXBElement<ApplyType> apply = (JAXBElement<ApplyType>) rule.getCondition().getExpression(); for (JAXBElement<?> element : apply.getValue().getExpression()) { if (element.getValue() instanceof AttributeValueType) { role = (String) ((AttributeValueType) element.getValue()).getContent().get(0); break; } } } catch (Exception e) { throw new XACMLParsingException("Rule " + rule + " of policy " + policy + " could not be parsed", e); } if (role == null) { throw new XACMLParsingException("Unable to find role in rule " + rule + " of policy " + policy); } AccessControlEntry ace = new AccessControlEntry(role, actionForAce, rule.getEffect().equals(EffectType.PERMIT)); entries.add(ace); } return acl; } catch (Exception e) { if (e instanceof XACMLParsingException) { throw (XACMLParsingException) e; } throw new XACMLParsingException("XACML could not be parsed", e); } }
XACMLUtils { public static AccessControlList parseXacml(InputStream xacml) throws XACMLParsingException { try { @SuppressWarnings("unchecked") final AccessControlList acl = new AccessControlList(); final List<AccessControlEntry> entries = acl.getEntries(); final PolicyType policy = ((JAXBElement<PolicyType>) XACMLUtils.jBossXacmlJaxbContext.createUnmarshaller().unmarshal(xacml)).getValue(); for (Object object : policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { if (!(object instanceof RuleType)) { throw new XACMLParsingException("Object " + object + " of policy " + policy + " is not of type RuleType"); } RuleType rule = (RuleType) object; if (rule.getTarget() == null) { if (rule.getRuleId().equals("DenyRule")) { logger.trace("Skipping global deny rule"); continue; } throw new XACMLParsingException("Empty rule " + rule + " in policy " + policy); } String role = null; String actionForAce = null; try { ActionType action = rule.getTarget().getActions().getAction().get(0); actionForAce = (String) action.getActionMatch().get(0).getAttributeValue().getContent().get(0); @SuppressWarnings("unchecked") JAXBElement<ApplyType> apply = (JAXBElement<ApplyType>) rule.getCondition().getExpression(); for (JAXBElement<?> element : apply.getValue().getExpression()) { if (element.getValue() instanceof AttributeValueType) { role = (String) ((AttributeValueType) element.getValue()).getContent().get(0); break; } } } catch (Exception e) { throw new XACMLParsingException("Rule " + rule + " of policy " + policy + " could not be parsed", e); } if (role == null) { throw new XACMLParsingException("Unable to find role in rule " + rule + " of policy " + policy); } AccessControlEntry ace = new AccessControlEntry(role, actionForAce, rule.getEffect().equals(EffectType.PERMIT)); entries.add(ace); } return acl; } catch (Exception e) { if (e instanceof XACMLParsingException) { throw (XACMLParsingException) e; } throw new XACMLParsingException("XACML could not be parsed", e); } } }
XACMLUtils { public static AccessControlList parseXacml(InputStream xacml) throws XACMLParsingException { try { @SuppressWarnings("unchecked") final AccessControlList acl = new AccessControlList(); final List<AccessControlEntry> entries = acl.getEntries(); final PolicyType policy = ((JAXBElement<PolicyType>) XACMLUtils.jBossXacmlJaxbContext.createUnmarshaller().unmarshal(xacml)).getValue(); for (Object object : policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { if (!(object instanceof RuleType)) { throw new XACMLParsingException("Object " + object + " of policy " + policy + " is not of type RuleType"); } RuleType rule = (RuleType) object; if (rule.getTarget() == null) { if (rule.getRuleId().equals("DenyRule")) { logger.trace("Skipping global deny rule"); continue; } throw new XACMLParsingException("Empty rule " + rule + " in policy " + policy); } String role = null; String actionForAce = null; try { ActionType action = rule.getTarget().getActions().getAction().get(0); actionForAce = (String) action.getActionMatch().get(0).getAttributeValue().getContent().get(0); @SuppressWarnings("unchecked") JAXBElement<ApplyType> apply = (JAXBElement<ApplyType>) rule.getCondition().getExpression(); for (JAXBElement<?> element : apply.getValue().getExpression()) { if (element.getValue() instanceof AttributeValueType) { role = (String) ((AttributeValueType) element.getValue()).getContent().get(0); break; } } } catch (Exception e) { throw new XACMLParsingException("Rule " + rule + " of policy " + policy + " could not be parsed", e); } if (role == null) { throw new XACMLParsingException("Unable to find role in rule " + rule + " of policy " + policy); } AccessControlEntry ace = new AccessControlEntry(role, actionForAce, rule.getEffect().equals(EffectType.PERMIT)); entries.add(ace); } return acl; } catch (Exception e) { if (e instanceof XACMLParsingException) { throw (XACMLParsingException) e; } throw new XACMLParsingException("XACML could not be parsed", e); } } private  XACMLUtils(); }
XACMLUtils { public static AccessControlList parseXacml(InputStream xacml) throws XACMLParsingException { try { @SuppressWarnings("unchecked") final AccessControlList acl = new AccessControlList(); final List<AccessControlEntry> entries = acl.getEntries(); final PolicyType policy = ((JAXBElement<PolicyType>) XACMLUtils.jBossXacmlJaxbContext.createUnmarshaller().unmarshal(xacml)).getValue(); for (Object object : policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { if (!(object instanceof RuleType)) { throw new XACMLParsingException("Object " + object + " of policy " + policy + " is not of type RuleType"); } RuleType rule = (RuleType) object; if (rule.getTarget() == null) { if (rule.getRuleId().equals("DenyRule")) { logger.trace("Skipping global deny rule"); continue; } throw new XACMLParsingException("Empty rule " + rule + " in policy " + policy); } String role = null; String actionForAce = null; try { ActionType action = rule.getTarget().getActions().getAction().get(0); actionForAce = (String) action.getActionMatch().get(0).getAttributeValue().getContent().get(0); @SuppressWarnings("unchecked") JAXBElement<ApplyType> apply = (JAXBElement<ApplyType>) rule.getCondition().getExpression(); for (JAXBElement<?> element : apply.getValue().getExpression()) { if (element.getValue() instanceof AttributeValueType) { role = (String) ((AttributeValueType) element.getValue()).getContent().get(0); break; } } } catch (Exception e) { throw new XACMLParsingException("Rule " + rule + " of policy " + policy + " could not be parsed", e); } if (role == null) { throw new XACMLParsingException("Unable to find role in rule " + rule + " of policy " + policy); } AccessControlEntry ace = new AccessControlEntry(role, actionForAce, rule.getEffect().equals(EffectType.PERMIT)); entries.add(ace); } return acl; } catch (Exception e) { if (e instanceof XACMLParsingException) { throw (XACMLParsingException) e; } throw new XACMLParsingException("XACML could not be parsed", e); } } private  XACMLUtils(); static AccessControlList parseXacml(InputStream xacml); static String getXacml(MediaPackage mediapackage, AccessControlList accessControlList); }
XACMLUtils { public static AccessControlList parseXacml(InputStream xacml) throws XACMLParsingException { try { @SuppressWarnings("unchecked") final AccessControlList acl = new AccessControlList(); final List<AccessControlEntry> entries = acl.getEntries(); final PolicyType policy = ((JAXBElement<PolicyType>) XACMLUtils.jBossXacmlJaxbContext.createUnmarshaller().unmarshal(xacml)).getValue(); for (Object object : policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { if (!(object instanceof RuleType)) { throw new XACMLParsingException("Object " + object + " of policy " + policy + " is not of type RuleType"); } RuleType rule = (RuleType) object; if (rule.getTarget() == null) { if (rule.getRuleId().equals("DenyRule")) { logger.trace("Skipping global deny rule"); continue; } throw new XACMLParsingException("Empty rule " + rule + " in policy " + policy); } String role = null; String actionForAce = null; try { ActionType action = rule.getTarget().getActions().getAction().get(0); actionForAce = (String) action.getActionMatch().get(0).getAttributeValue().getContent().get(0); @SuppressWarnings("unchecked") JAXBElement<ApplyType> apply = (JAXBElement<ApplyType>) rule.getCondition().getExpression(); for (JAXBElement<?> element : apply.getValue().getExpression()) { if (element.getValue() instanceof AttributeValueType) { role = (String) ((AttributeValueType) element.getValue()).getContent().get(0); break; } } } catch (Exception e) { throw new XACMLParsingException("Rule " + rule + " of policy " + policy + " could not be parsed", e); } if (role == null) { throw new XACMLParsingException("Unable to find role in rule " + rule + " of policy " + policy); } AccessControlEntry ace = new AccessControlEntry(role, actionForAce, rule.getEffect().equals(EffectType.PERMIT)); entries.add(ace); } return acl; } catch (Exception e) { if (e instanceof XACMLParsingException) { throw (XACMLParsingException) e; } throw new XACMLParsingException("XACML could not be parsed", e); } } private  XACMLUtils(); static AccessControlList parseXacml(InputStream xacml); static String getXacml(MediaPackage mediapackage, AccessControlList accessControlList); static final String RULE_COMBINING_ALG; static final String ACTION_IDENTIFIER; static final String RESOURCE_IDENTIFIER; static final String SUBJECT_IDENTIFIER; static final String SUBJECT_ROLE_IDENTIFIER; static final String XACML_STRING_EQUAL; static final String XACML_STRING_IS_IN; static final String W3C_STRING; static final String ISSUER; }