public void AuthorisationsEmpty()
        {
            AuthorisationsType at = new AuthorisationsType();
            AuthorisationsParser ap = new AuthorisationsParser();

            ap.Load(at);

            bool result = ap.HasPrivilege(AuthorisationsParser.PrivilegeFor.CvrNumber, "", "");

            Assert.IsFalse(result, "Has privilege unexpectedly returned true");
        }
Esempio n. 2
0
        public void Load(AuthorisationsType authorisations)
        {
            if (authorisations == null)
            {
                _isLoaded = false;
                throw new ArgumentException(Errors.LoadNullAuthorisations, "authorisations");
            }

            _autorisations = authorisations;
            _isLoaded = true;
        }
Esempio n. 3
0
 public void Load(string base64AuthorisationsAttribute)
 {
     try
     {
         string decoded = Encoding.UTF8.GetString(Convert.FromBase64String(base64AuthorisationsAttribute));
         AuthorisationsType authorisations = Serialization.DeserializeFromXmlString<AuthorisationsType>(decoded);
         _autorisations = authorisations;
         _isLoaded = true;
     }
     catch (Exception e)
     {
         _isLoaded = false;
         if(Trace.ShouldTrace(TraceEventType.Error))
             Trace.TraceData(TraceEventType.Error, string.Format(Errors.DecodeFailed,base64AuthorisationsAttribute,e.Message));
         throw new Saml20BRSException(Errors.DecodeFailedMsg, e);
     }
 }
        public void HasPrivilege3()
        {
            string privilege = "TestPriv";
            string productionUnit = "6029537682";
            AuthorisationsParser ap = new AuthorisationsParser();
            AuthorisationsType at = new AuthorisationsType();

            PrivilegeType priv = new PrivilegeType();
            priv.Value = privilege;

            AuthorisationType auth = new AuthorisationType();
            auth.resource = "urn:dk:cvr:productionUnitIdentifier:" + productionUnit;
            auth.Privilege.Add(priv);
            at.Authorisations.Add(auth);

            ap.Load(at);

            Assert.That(ap.HasPrivilege(AuthorisationsParser.PrivilegeFor.ProductionUnit, productionUnit, privilege), "User unexpectedly does not have privilege for production unit");
        }
        public void HasPrivilege2()
        {
            string privilege = "TestPriv";
            string cvrNumber = "29537682";
            AuthorisationsParser ap = new AuthorisationsParser();
            AuthorisationsType at = new AuthorisationsType();

            PrivilegeType priv = new PrivilegeType();
            priv.Value = privilege;

            AuthorisationType auth = new AuthorisationType();
            auth.resource = "urn:dk:cvr:cVRnumberIdentifier:" + cvrNumber;
            auth.Privilege.Add(priv);
            at.Authorisations.Add(auth);

            ap.Load(at);

            Assert.IsFalse(ap.HasPrivilege(AuthorisationsParser.PrivilegeFor.ProductionUnit, cvrNumber, privilege), "User unexpectedly has privilege");
        }
Esempio n. 6
0
        public void LoadFromStronglyTypedObject()
        {
            string privilege = "TestPriv";
            string cvrNumber = "29537682";
            AuthorisationsParser ap = new AuthorisationsParser();
            AuthorisationsType at = new AuthorisationsType();

            PrivilegeType priv = new PrivilegeType();
            priv.Value = privilege;

            AuthorisationType auth = new AuthorisationType();
            auth.resource = "urn:dk:cvr:cVRnumberIdentifier:" + cvrNumber;
            auth.Privilege.Add(priv);
            at.Authorisations.Add(auth);

            ap.Load(at);

            Assert.That(ap.HasPrivilege(AuthorisationsParser.PrivilegeFor.CvrNumber, cvrNumber, privilege), "User does not have expected privilege");

        }
        public void HasPrivilege5()
        {
            string privilege = "SomePrivilege";
            string productionUnit = "6029537682";
            AuthorisationsParser ap = new AuthorisationsParser();
            AuthorisationsType at = new AuthorisationsType();

            PrivilegeType priv = new PrivilegeType();
            priv.Value = privilege;

            AuthorisationType auth = new AuthorisationType();
            auth.resource = "urn:dk:cvr:productionUnitIdentifier:" + productionUnit;
            auth.Privilege.Add(priv);
            at.Authorisations.Add(auth);

            string xml = Serialization.SerializeToXmlString(at);

            ap.Load(Convert.ToBase64String(Encoding.UTF8.GetBytes(xml)));

            Assert.That(ap.HasPrivilege(AuthorisationsParser.PrivilegeFor.ProductionUnit, productionUnit, privilege), "User unexpectedly does not have privilege for production unit");
        }