Example #1
0
        public void AuthorizationSimple()
        {
            PvpApplicationLdapAuthorizer authorizer = new PvpApplicationLdapAuthorizer("http://test.rubicon-it.com",
                                                                                       @"egora1");

            Assert.IsNotNull(authorizer);
            Assert.IsTrue(authorizer.IsValid);
            var fragment = authorizer.UserPrincipalSoapFragment;
            var ns       = new XmlNamespaceManager(new NameTable());

            ns.AddNamespace("pvp", PvpToken.PvpTokenNamespace);
            var userId = fragment.SelectSingleNode("//pvp:userId", ns);

            Assert.AreEqual("*****@*****.**", userId.InnerText);
            Assert.AreEqual("*****@*****.**", authorizer.Mail, "MailAddress");
            Assert.AreEqual("&<>\"'ZMR-Behoerdenabfrage_(&GKZ=&1234)", authorizer.Roles, "Roles");
            Assert.AreEqual("Vienna", authorizer.CostCenterId);
            Assert.AreEqual("egora/Development", authorizer.ChargeCode);
            Assert.AreEqual(600, authorizer.AuthorizationTimeToLive, "TimeToLive");
            Assert.AreEqual(
                "<role value=\"&amp;&lt;&gt;&quot;&apos;ZMR-Behoerdenabfrage_\">\n<param>\n<key>&amp;GKZ</key><value>&amp;1234</value>\n</param>\n</role>",
                authorizer.GetPvpToken().RoleAttribute.GetXmlPart(), "SoapRoles");
            Assert.IsTrue(authorizer.GetAttributeValue(PvpAttributes.X_AUTHENTICATE_cn).EndsWith(" through formatter"));
            Assert.AreEqual("1.8", authorizer.Version);
        }
Example #2
0
    public CustomAuthorization GetAuthorization(string rootUrl, string userId)
    {
        LdapConfiguration configuration = LdapConfiguration.GetConfiguration();

        rootUrl = rootUrl.ToLowerInvariant();
        PvpApplicationLdapAuthorizer authorizer = new PvpApplicationLdapAuthorizer(rootUrl, userId, configuration);

        if (!authorizer.IsValid)
        {
            return(null);
        }

        CustomAuthorization auth = new CustomAuthorization();

        auth.TimeToLive = authorizer.AuthorizationTimeToLive;
        auth.PvpVersion = authorizer.Version;

        if (authorizer.IsWeb)
        {
            if (rootUrl.Contains("assertion"))
            {
                auth.SoapHeaderXmlFragment = authorizer.GetPvpToken().GetSamlAttributeStatement();
            }
            else
            {
                List <HttpHeader> headers = authorizer.GetPvpToken().GetHeaders();
                auth.HttpHeaders = headers.ToArray();
            }
        }
        else if (authorizer.IsSoap)
        {
            auth.SoapHeaderXmlFragment = authorizer.UserPrincipalSoapFragment;
        }
        else
        {
            auth = CustomAuthorization.NoAuthorization;
        }

        return(auth);
    }
Example #3
0
        public void FixedRoleAttribute()
        {
            PvpApplicationLdapAuthorizer authorizer = new PvpApplicationLdapAuthorizer("https://dummy.com/fixedrole/", "egora2");

            Assert.IsNotNull(authorizer);
            Assert.AreEqual("*****@*****.**", authorizer.Mail);
            Assert.IsTrue(authorizer.IsValid);
            Assert.IsFalse(authorizer.IsWeb);
            Assert.IsTrue(authorizer.IsSoap);
            Assert.That(authorizer.Roles, Is.EqualTo("FixedRole(param=val)"));

            var chainedToken = authorizer.GetPvpToken().GetChainedSoapFragment();
        }
Example #4
0
    public CustomAuthorization GetAuthorization(string rootUrl, string userId)
    {
        var file = Path.Combine(Server.MapPath("~"), "ConfigurationFixed.xml");
        LdapConfiguration configuration = LdapConfiguration.GetConfiguration(file);

        rootUrl = rootUrl.ToLowerInvariant();
        PvpApplicationLdapAuthorizer authorizer = new PvpApplicationLdapAuthorizer(rootUrl, userId, configuration);

        if (!authorizer.IsValid)
        {
            return(CustomAuthorization.NoAuthorization);
        }

        CustomAuthorization auth = new CustomAuthorization();

        auth.TimeToLive = authorizer.AuthorizationTimeToLive;
        auth.PvpVersion = authorizer.Version;
        var dummy        = authorizer.GvGID;
        var chainedToken = authorizer.GetPvpToken().GetChainedSoapFragment();
        var token        = String.Format(
            @"<pvpToken version=""{0}"" xmlns=""http://egov.gv.at/pvp1.xsd"">
<authenticate>
  <participantId>{1}</participantId>
  <systemPrincipal>
    <userId>egovstar.appserv1.intra.xyz.gv.at</userId>
    <cn>Anwendung 1 Register-Interface</cn>
    <gvOuId>AT:L6:4711</gvOuId>
    <ou>Fachabteilung 1B Informationstechnik</ou>
    <gvOuID>{2}</gvOuID>
    <gvSecClass>{3}</gvSecClass>
  </systemPrincipal>
</authenticate>
<authorize>
  <role value=""Registerabfrage""></role>
</authorize>
{4}
</pvpToken>",
            authorizer.Version,
            authorizer.ParticipantID,
            authorizer.GvOuID,
            authorizer.GvSecClass,
            chainedToken.OuterXml);

        XmlDocument doc = new XmlDocument();

        doc.LoadXml(token);
        auth.SoapHeaderXmlFragment = doc.DocumentElement;

        return(auth);
    }