/// <inheritdoc/> public async Task <XacmlPolicy> GetPolicyAsync(XacmlContextRequest request) { var app = request.GetResourceAttributes().Attributes.Where(a => a.AttributeId.ToString() == XacmlRequestAttribute.AppAttribute).Select(a => a.AttributeValues.FirstOrDefault()).FirstOrDefault().Value; var org = request.GetResourceAttributes().Attributes.Where(a => a.AttributeId.ToString() == XacmlRequestAttribute.OrgAttribute).Select(a => a.AttributeValues.FirstOrDefault()).FirstOrDefault().Value; string policyString = await _localApp.GetXACMLPolicy($"{org}/{app}"); return(ParsePolicyContent(policyString)); }
private async Task <int> GetAppAuthLevel(IEnumerable <SelectListItem> testApps) { try { var appId = testApps.Single().Value; var policyString = await _localApp.GetXACMLPolicy(appId); var document = new XmlDocument(); document.LoadXml(policyString); var nsMngr = new XmlNamespaceManager(document.NameTable); nsMngr.AddNamespace("xacml", "urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"); var authLevelNode = document.SelectSingleNode("/xacml:Policy/xacml:ObligationExpressions/xacml:ObligationExpression[@ObligationId='urn:altinn:obligation:authenticationLevel1']/xacml:AttributeAssignmentExpression[@Category='urn:altinn:minimum-authenticationlevel']/xacml:AttributeValue", nsMngr); return(int.Parse(authLevelNode.InnerText)); } catch (Exception) { // Return default auth level if Single app auth level can't be found. return(2); } }