Exemplo n.º 1
0
        public async Task <IActionResult> Search([FromBody] SearchModel <OrderSearchModel> searchModel)
        {
            var websiteId = TokenRole.Equals(nameof(Role.SuperAdmin)) ? (int?)null : WebsiteId;
            var orders    = await this.orderService.SearchAsync(websiteId, searchModel);

            return(Ok(new ApiResponse <PaginationResponse <List <OrderModel> > >(orders)));
        }
 internal TokenInfo(string tokenValue, TokenRole role, DateTime?expires = null, ValidateTokenDelegate validateTokenDelegate = null)
 {
     TokenValue             = tokenValue;
     Role                   = role;
     Expires                = expires;
     _validateTokenDelegate = validateTokenDelegate;
 }
Exemplo n.º 3
0
        public async Task DeleteInvalidTokenRole_Success()
        {
            string    roleID    = UK.GetKey("DelRole");
            TokenRole tokenRole = new TokenRole(roleID);

            Assert.IsTrue(await _tokenAuthEngine.DeleteTokenRole(roleID), "Deletion of token role failed.");
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post(UserModel userModel)
        {
            //Prevent Administrator create user on other website
            if (TokenRole != null && TokenRole.Equals(nameof(Role.Administrator)) &&
                this.TokenWebsiteId != this.WebsiteId)
            {
                return(Ok(new ApiResponse <UserModel>(
                              Structure.Enums.StatusCode.Forbidden, Constants.MessageResponse.ForbiddenError)));
            }

            Role role;
            int  websiteId;

            //If token role is super admin => create administrator user else create normal user
            if (TokenRole != null && TokenRole.Equals(nameof(Role.SuperAdmin)))
            {
                role      = Role.Administrator;
                websiteId = userModel.WebsiteId;
            }
            else
            {
                role      = Role.User;
                websiteId = this.WebsiteId;
            }
            await userService.CreateAsync(websiteId, role, userModel);

            return(Ok(new ApiResponse <UserModel>()));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates / Saves a token role.
        /// </summary>
        /// <param name="tokenRole">The TokenRole object that contains the Token Role to be created / updated.</param>
        /// <returns>True if token Role was successfully created.</returns>
        public async Task <bool> SaveTokenRole(TokenRole tokenRole)
        {
            string path = MountPointPath + "roles/" + tokenRole.Name;
            string json = JsonConvert.SerializeObject(tokenRole, Formatting.None);

            try {
                VaultDataResponseObjectB vdro = await ParentVault._httpConnector.PostAsync_B(path, "SaveTokenRole", json);

                if (vdro.Success)
                {
                    return(true);
                }
                else
                {
                    throw new VaultUnexpectedCodePathException();
                }
            }
            catch (VaultInvalidDataException e) {
                if (e.Message.Contains("invalid accessor"))
                {
                    return(false);
                }

                throw e;
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> ChangeStatus(int id, [FromBody] Status status)
        {
            var websiteId = TokenRole.Equals(nameof(Role.SuperAdmin)) ? (int?)null : this.WebsiteId;
            await userService.ChangeStatusAsync(websiteId, id, (int)status);

            return(Ok(new ApiResponse <UserModel>()));
        }
Exemplo n.º 7
0
        public async Task CreateToken()
        {
            // SETUP

            // We need our own vault since we will be manipulating the token value
            VaultAgentAPI ourVault = await VaultServerRef.ConnectVault("TokenTest");

            TokenAuthEngine ourTokenAuthEngine = (TokenAuthEngine)ourVault.ConnectAuthenticationBackend(EnumBackendTypes.A_Token);

            // Need a Token Role so we can autogenerate a token
            TokenRole tokenRole = new TokenRole();

            tokenRole.Name = UK.GetKey();
            await ourTokenAuthEngine.SaveTokenRole(tokenRole);

            string           tokenName        = "Name" + tokenRole.Name;
            TokenNewSettings tokenNewSettings = new TokenNewSettings()
            {
                Name          = tokenName,
                NumberOfUses  = 6,
                NoParentToken = true,
                RoleName      = tokenRole.Name
            };

            Token token = await ourTokenAuthEngine.CreateToken(tokenNewSettings);

            Assert.NotNull(token, "A10:  Expected to receive the new token back, instead we received a null value.");

            // Read the token we just created.
            //Token token = await _tokenAuthEngine.GetTokenWithID(tokenID);
            Assert.IsNotNull(token, "A20: No Token returned.  Was expecting one.");

            ourVault.TokenID = token.ID;
            Assert.AreEqual(ourVault.TokenID, token.ID, "A30: Vault did not store token correctly");
        }
Exemplo n.º 8
0
 public CSharpTokenNode(TextLocation location, TokenRole role)
 {
     this.startLocation = location;
     if (role != null)
     {
         this.flags |= role.TokenIndex << AstNodeFlagsUsedBits;
     }
 }
Exemplo n.º 9
0
        public async Task <IActionResult> Put(int id, UserUpdateModel userModel)
        {
            var websiteId = TokenRole.Equals(nameof(Role.SuperAdmin))
                            ? userModel.WebsiteId
                            : this.WebsiteId;
            await userService.UpdateAsync(websiteId, id, userModel);

            return(Ok(new ApiResponse <UserUpdateModel>()));
        }
Exemplo n.º 10
0
        public async Task CreateTokenRole_Simple_Success()
        {
            string roleID = UK.GetKey("TokRole");

            TokenRole tokenRole = new TokenRole();

            tokenRole.Name = roleID;

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault failed.");
        }
Exemplo n.º 11
0
        public async Task ListTokenAccessors_Success()
        {
            string    roleID    = UK.GetKey("ListAcc");
            TokenRole tokenRole = new TokenRole(roleID);

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault Failed.");

            List <string> Accessors = await _tokenAuthEngine.ListTokenAccessors();

            Assert.GreaterOrEqual(Accessors.Count, 1);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Get(int id)
        {
            //Prevent user get information of other user
            if (TokenRole.Equals(nameof(Role.User)) && this.UserId != id)
            {
                return(Ok(new ApiResponse <UserModel>(
                              Structure.Enums.StatusCode.Forbidden, Constants.MessageResponse.ForbiddenError)));
            }

            var websiteId = TokenRole.Equals(nameof(Role.SuperAdmin)) ? (int?)null : this.WebsiteId;
            var user      = await userService.GetByIdAsync(websiteId, id);

            return(Ok(new ApiResponse <UserModel>(user)));
        }
Exemplo n.º 13
0
        public async Task CreateTokenRole_WithNonExistentPolicies_Success()
        {
            string roleID = UK.GetKey("TokRole");

            TokenRole tokenRole = new TokenRole(roleID);

            tokenRole.AllowedPolicies.Add("Pol1");
            tokenRole.AllowedPolicies.Add("Pol2");

            tokenRole.DisallowedPolicies.Add("DisPol1");
            tokenRole.DisallowedPolicies.Add("DisPol2");

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault failed.");
        }
Exemplo n.º 14
0
        public async Task ListTokenRoles_Success()
        {
            string roleID = UK.GetKey("TokRole");

            TokenRole tokenRole = new TokenRole(roleID);

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault failed.");

            string roleID2 = UK.GetKey("TokRole");

            TokenRole tokenRole2 = new TokenRole(roleID2);

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole2), "M2:  Creation of TokenRole in Vault failed.");

            List <string> roles = await _tokenAuthEngine.ListTokenRoles();

            Assert.GreaterOrEqual(roles.Count, 2);
        }
Exemplo n.º 15
0
        public async Task DeleteValidTokenRole_Success()
        {
            string    roleID    = UK.GetKey("DelRole");
            TokenRole tokenRole = new TokenRole(roleID);

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault Failed.");

            // Validate token exists.
            TokenRole tokenRole2 = await _tokenAuthEngine.GetTokenRole(roleID);

            Assert.IsNotNull(tokenRole2, "M2:  Retrieval of token role failed.  Expected it to exist.");

            // Delete and validate
            Assert.IsTrue(await _tokenAuthEngine.DeleteTokenRole(roleID), "Deletion of token role failed.");
            TokenRole tokenRole3 = await _tokenAuthEngine.GetTokenRole(roleID);

            Assert.IsNull(tokenRole3, "M3:  Retrieval of token role was successful.  Expected it to be null if deletion had been successful.");
        }
Exemplo n.º 16
0
        public async Task NormalLogin()
        {
            // SETUP

            // We need our own vault since we will be manipulating the token value
            VaultAgentAPI ourVault = await VaultServerRef.ConnectVault("TokenTest");

            TokenAuthEngine ourTokenAuthEngine = (TokenAuthEngine)ourVault.ConnectAuthenticationBackend(EnumBackendTypes.A_Token);

            // Need a Token Role so we can autogenerate a token
            TokenRole tokenRole = new TokenRole();

            UniqueKeys UK = new UniqueKeys("", "");       // Unique Key generator

            tokenRole.Name = UK.GetKey();
            await ourTokenAuthEngine.SaveTokenRole(tokenRole);

            string           tokenName        = "Name" + tokenRole.Name;
            TokenNewSettings tokenNewSettings = new TokenNewSettings()
            {
                Name          = tokenName,
                NumberOfUses  = 6,
                NoParentToken = true,
                RoleName      = tokenRole.Name
            };

            Token token = await ourTokenAuthEngine.CreateToken(tokenNewSettings);

            Assert.NotNull(token, "A10:  Expected to receive the new token back, instead we received a null value.");

            // Read the token we just created.
            //Token token = await _tokenAuthEngine.GetTokenWithID(tokenID);
            Assert.IsNotNull(token, "A20: No Token returned.  Was expecting one.");


            VaultAgentAPI vault2 = await VaultServerRef.ConnectVault("TokenLoginTest");

            TokenLoginConnector loginConnector = new TokenLoginConnector(vault2, "test");

            loginConnector.TokenId = token.ID;
            Assert.IsTrue(await loginConnector.Connect(), "A30:  Login Failed");
        }
Exemplo n.º 17
0
        public async Task CreateTokenRole_WithMinimalFieldsSet_Success()
        {
            string roleID = UK.GetKey("TokRole");

            TokenRole tokenRole = new TokenRole(roleID);

            Assert.True(await _tokenAuthEngine.SaveTokenRole(tokenRole), "M1:  Creation of TokenRole in Vault failed.");

            // Now read the token role...
            TokenRole role2 = await _tokenAuthEngine.GetTokenRole(roleID);

            // Validate The token Role and its properties.
            Assert.AreEqual(roleID, role2.Name, "M2:  RoleToken Name does not match expected value. TokeRole={0}", roleID);
            Assert.IsNotNull(role2.AllowedPolicies, "M3:  Allowed Policies seems to be null.  Expected no value.  TokeRole={0}", roleID);
            Assert.AreEqual(0, role2.AllowedPolicies.Count, "M4:  Allowed policies count was expected to be zero, but was something else.   TokeRole={0}", roleID);

            // Disallowed Policies
            Assert.IsNotNull(role2.DisallowedPolicies, "M10:  Disallowed Policies seems to be null.  Expected No value. TokeRole={0}", roleID);
            Assert.AreEqual(0, role2.DisallowedPolicies.Count, "M11:  DisallowedPolicies count is not correct. TokeRole={0}", roleID);

            Assert.IsNotNull(role2.BoundCidrs, "M20:  BoundCidrs seems to be null, Expected no value. TokeRole={0}", roleID);
            Assert.AreEqual(0, role2.BoundCidrs.Count, "M21:  BoundCidrs count is not correct.  Expected zero. TokeRole={0}", roleID);
        }
Exemplo n.º 18
0
		/// <summary>
		/// Writes a keyword, and all specials up to
		/// </summary>
		void WriteKeyword(TokenRole tokenRole)
		{
			WriteKeyword(tokenRole.Token, tokenRole);
		}
Exemplo n.º 19
0
		protected virtual void WriteToken(TokenRole tokenRole)
		{
			WriteToken(tokenRole.Token, tokenRole);
		}
Exemplo n.º 20
0
		/// <summary>
		/// Writes a keyword, and all specials up to
		/// </summary>
		protected virtual void WriteKeyword(TokenRole tokenRole)
		{
			WriteKeyword(tokenRole.Token, tokenRole);
		}
Exemplo n.º 21
0
		void DebugStart(AstNode node, TokenRole role)
		{
			WriteKeyword(role, node);
		}
Exemplo n.º 22
0
		void PrintInitializerElements(AstNodeCollection<Expression> elements, TokenRole open, TokenRole close)
		{
//			BraceStyle style;
//			if (policy.ArrayInitializerWrapping == Wrapping.WrapAlways) {
//				style = BraceStyle.NextLine;
//			} else {
//				style = BraceStyle.EndOfLine;
//			}
			WriteSpecialsUpToRole (open);
			WriteToken (open);
			formatter.Indent ();
			NewLine ();
			var col = 0;
			bool isFirst = true;
			foreach (AstNode node in elements) {
				if (isFirst) {
					isFirst = false;
				} else {
					Comma(node, noSpaceAfterComma: true);
					Space ();
				}
				col++;
				if ((col % 20) == 0) {
					NewLine ();
				}
				node.AcceptVisitor(this);
			}
			OptionalComma();
			NewLine();
			formatter.Unindent ();
			WriteSpecialsUpToRole (close);
			WriteToken (close);
		}
Exemplo n.º 23
0
		void DebugStartReference(AstNode node, TokenRole role, object reference, ref int keywordStartIndex)
		{
			int start = keywordStartIndex < 0 ? writer.GetLocation() ?? 0 : keywordStartIndex;
			keywordStartIndex = -1;
			WriteKeyword(role, node);
			int end = writer.GetLocation() ?? 0;
			writer.AddHighlightedKeywordReference(reference, start, end);
		}
Exemplo n.º 24
0
		void WriteKeywordReference(TokenRole tokenRole) => WriteKeywordReference(tokenRole, new object());
Exemplo n.º 25
0
		protected virtual void WriteToken(TokenRole tokenRole, object data)
		{
			WriteToken(tokenRole.Token, tokenRole, data);
		}
Exemplo n.º 26
0
		void WriteToken(TokenRole tokenRole)
		{
			WriteToken(tokenRole.Token, tokenRole);
		}
Exemplo n.º 27
0
		void WriteKeywordIdentifier(TokenRole tokenRole)
		{
			WriteKeywordIdentifier(tokenRole.Token, tokenRole, null, true);
		}
Exemplo n.º 28
0
		void WriteKeywordReferences(TokenRole tokenRole1, TokenRole tokenRole2, object reference)
		{
			int start = writer.GetLocation() ?? 0;
			WriteKeyword(tokenRole1);
			WriteKeyword(tokenRole2);
			int end = writer.GetLocation() ?? 0;
			writer.AddHighlightedKeywordReference(reference, start, end);
		}
Exemplo n.º 29
0
		/// <summary>
		/// Writes a keyword, and all specials up to
		/// </summary>
		protected virtual void WriteKeyword(TokenRole tokenRole, AstNode node = null)
		{
			WriteKeywordIdentifier(tokenRole.Token, tokenRole, node, false);
		}
Exemplo n.º 30
0
 JsonValue GetKeyword(TokenRole tokenRole)
 {
     return new JsonElement(tokenRole.Token);
 }
Exemplo n.º 31
0
 public CPlusPlusModifierToken(TextLocation location, TokenRole role) : base(location, role)
 {
 }