public void IsCloudFoundryRequest_ReturnsExpected()
        {
            var securityBase = new SecurityBase(new CloudFoundryOptions(), null);

            Assert.True(securityBase.IsCloudFoundryRequest("/"));
            Assert.True(securityBase.IsCloudFoundryRequest("/badpath"));
        }
Exemplo n.º 2
0
 public CloudFoundrySecurity(ICloudFoundryOptions options, IManagementOptions managementOptions, ILogger <CloudFoundrySecurity> logger = null)
 {
     _options           = options;
     _managementOptions = managementOptions;
     _logger            = logger;
     _base = new SecurityBase(options, managementOptions, logger);
 }
 public CloudFoundrySecurityOwinMiddleware(OwinMiddleware next, ICloudFoundryOptions options, ILogger <CloudFoundrySecurityOwinMiddleware> logger = null)
     : base(next)
 {
     _options = options;
     _logger  = logger;
     _base    = new SecurityBase(options, logger);
 }
 protected static void ValidateResponse(SecurityBase response)
 {
     if (!string.Equals(response.Code, SuccessCode, StringComparison.OrdinalIgnoreCase))
     {
         throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture, "Unable to retrieve credentials. Code = \"{0}\". Message = \"{1}\".", response.Code, response.Message));
     }
 }
 public CloudFoundrySecurityOwinMiddleware(OwinMiddleware next, ICloudFoundryOptions options, IEnumerable <IManagementOptions> mgmtOptions, ILogger <CloudFoundrySecurityOwinMiddleware> logger = null)
     : base(next)
 {
     _options     = options;
     _logger      = logger;
     _mgmtOptions = mgmtOptions.OfType <CloudFoundryManagementOptions>().Single();
     _base        = new SecurityBase(options, _mgmtOptions, logger);
 }
Exemplo n.º 6
0
        public void IsCloudFoundryRequest_ReturnsExpected()
        {
            var cloudOpts = new CloudFoundryEndpointOptions();
            var mgmtOpts  = new CloudFoundryManagementOptions();

            mgmtOpts.EndpointOptions.Add(cloudOpts);
            var securityBase = new SecurityBase(cloudOpts, mgmtOpts, null);

            Assert.True(securityBase.IsCloudFoundryRequest("/cloudfoundryapplication"));
            Assert.True(securityBase.IsCloudFoundryRequest("/cloudfoundryapplication/badpath"));
        }
Exemplo n.º 7
0
        public async Task GetPermissionsAsyncTest()
        {
            var cloudOpts = new CloudFoundryEndpointOptions();
            var mgmtOpts  = new CloudFoundryManagementOptions();

            mgmtOpts.EndpointOptions.Add(cloudOpts);
            var securityBase = new SecurityBase(cloudOpts, mgmtOpts, null);
            var result       = await securityBase.GetPermissionsAsync("testToken");

            Assert.NotNull(result);
        }
Exemplo n.º 8
0
        public async Task GetPermissionsTest()
        {
            var cloudOpts = new CloudFoundryEndpointOptions();
            var mgmtOpts  = new CloudFoundryManagementOptions();

            mgmtOpts.EndpointOptions.Add(cloudOpts);
            var securityBase = new SecurityBase(cloudOpts, mgmtOpts, null);
            var response     = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            var perms        = new Dictionary <string, object> {
                { "read_sensitive_data", true }
            };

            response.Content = JsonContent.Create(perms);
            var result = await securityBase.GetPermissions(response);

            Assert.Equal(Permissions.FULL, result);
        }
Exemplo n.º 9
0
        public string GenerateToken(GenerateTokenModel model)
        {
            var claims = new[]
            {
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
                new Claim("vId", SecurityBase.Encrypt(model.VolunterId.ToString())),
                new Claim("oId", SecurityBase.Encrypt(model.OrganisationId.ToString())),
                new Claim(JwtRegisteredClaimNames.Email, SecurityBase.Encrypt(model.Email))
            };

            var symmetricSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(model.Key));
            var signingCredentials   = new SigningCredentials(symmetricSecurityKey, SecurityAlgorithms.HmacSha256Signature, "http://www.w3.org/2001/04/xmlenc#sha256");

            var jwtSecurityToken = new JwtSecurityToken(
                issuer: model.Issuer,
                audience: model.Audience,
                claims: claims,
                //expires: DateTime.UtcNow,//DateTime.UtcNow.AddDays(1),
                signingCredentials: signingCredentials
                );

            var jwtSecurityTokenHandler = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken);

            var tokenId = claims.First(claim => claim.Type == JwtRegisteredClaimNames.Jti).Value;

            var volunteerToken = new VolunteerToken
            {
                Id           = new Guid(tokenId),
                Volunteer_ID = model.VolunterId,
                Token_VC     = jwtSecurityTokenHandler,
                Active_BT    = true
            };

            _volunteerTokenRepository.SaveToken(volunteerToken);

            return(jwtSecurityTokenHandler);
        }
 private static void ValidateResponse(SecurityBase response)
 {
     if (!string.Equals(response.Code, SuccessCode, StringComparison.OrdinalIgnoreCase))
     {
         throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture, 
             "Unable to retrieve credentials. Code = \"{0}\". Message = \"{1}\".",
             response.Code, response.Message));
     }
 }
Exemplo n.º 11
0
        public ActionResult About()
        {
            LicenseModel model = SecurityBase.GetLicense();

            return(View(model));
        }
 public ActuatorSecurityMiddlewareTest(IManagementOptions mopts)
 {
     Environment.SetEnvironmentVariable("VCAP_APPLICATION", "somestuff");
     _base = new SecurityBase(new CloudFoundryEndpointOptions(), mopts);
 }