public override long Add(object id) { string @string = ( string )id; sbyte[] bytes = UTF8.encode(@string); int length = bytes.Length; if (length > 0xFFFF) { throw new System.ArgumentException(@string); } long startOffset = _offset; _cache.setByte(_offset++, 0, ( sbyte )length); _cache.setByte(_offset++, 0, ( sbyte )(( int )(( uint )length >> (sizeof(sbyte) * 8)))); _current = _cache.at(_offset); for (int i = 0; i < length;) { int bytesLeftToWrite = length - i; int bytesLeftInChunk = ( int )(_chunkSize - _offset % _chunkSize); int bytesToWriteInThisChunk = min(bytesLeftToWrite, bytesLeftInChunk); for (int j = 0; j < bytesToWriteInThisChunk; j++) { _current.setByte(_offset++, 0, bytes[i++]); } if (length > i) { _current = _cache.at(_offset); } } return(startOffset); }
private TextValue String(RecordPropertyCursor cursor, long reference, PageCursor page) { ByteBuffer buffer = cursor.Buffer = _read.loadString(reference, cursor.Buffer, page); buffer.flip(); return(Values.stringValue(UTF8.decode(buffer.array(), 0, buffer.limit()))); }
/// <summary> /// Serialize the provided ConstraintRule onto the target buffer </summary> /// <param name="constraintRule"> the ConstraintRule to serialize </param> /// <exception cref="IllegalStateException"> if the ConstraintRule is of type unique, but the owned index has not been set </exception> public static sbyte[] Serialize(ConstraintRule constraintRule) { ByteBuffer target = ByteBuffer.allocate(LengthOf(constraintRule)); target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID); target.put(CONSTRAINT_RULE); ConstraintDescriptor constraintDescriptor = constraintRule.ConstraintDescriptor; switch (constraintDescriptor.Type()) { case EXISTS: target.put(EXISTS_CONSTRAINT); break; case UNIQUE: target.put(UNIQUE_CONSTRAINT); target.putLong(constraintRule.OwnedIndex); break; case UNIQUE_EXISTS: target.put(UNIQUE_EXISTS_CONSTRAINT); target.putLong(constraintRule.OwnedIndex); break; default: throw new System.NotSupportedException(format("Got unknown index descriptor type '%s'.", constraintDescriptor.Type())); } constraintDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target)); UTF8.putEncodedStringInto(constraintRule.Name, target); return(target.array()); }
/// <summary> /// Serialize the provided IndexRule onto the target buffer /// </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor to serialize </param> /// <exception cref="IllegalStateException"> if the StoreIndexDescriptor is of type unique, but the owning constrain has not been set </exception> public static sbyte[] Serialize(StoreIndexDescriptor indexDescriptor) { ByteBuffer target = ByteBuffer.allocate(LengthOf(indexDescriptor)); target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID); target.put(INDEX_RULE); IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); UTF8.putEncodedStringInto(providerDescriptor.Key, target); UTF8.putEncodedStringInto(providerDescriptor.Version, target); switch (indexDescriptor.Type()) { case GENERAL: target.put(GENERAL_INDEX); break; case UNIQUE: target.put(UNIQUE_INDEX); // The owning constraint can be null. See IndexRule.getOwningConstraint() long?owningConstraint = indexDescriptor.OwningConstraint; target.putLong(owningConstraint == null ? NO_OWNING_CONSTRAINT_YET : owningConstraint); break; default: throw new System.NotSupportedException(format("Got unknown index descriptor type '%s'.", indexDescriptor.Type())); } indexDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target)); UTF8.putEncodedStringInto(indexDescriptor.Name, target); return(target.array()); }
public override object Get(long offset) { int length = _cache.getByte(offset++, 0) & 0xFF; length |= (_cache.getByte(offset++, 0) & 0xFF) << (sizeof(sbyte) * 8); ByteArray array = _cache.at(offset); sbyte[] bytes = new sbyte[length]; for (int i = 0; i < length;) { int bytesLeftToRead = length - i; int bytesLeftInChunk = ( int )(_chunkSize - offset % _chunkSize); int bytesToReadInThisChunk = min(bytesLeftToRead, bytesLeftInChunk); for (int j = 0; j < bytesToReadInThisChunk; j++) { bytes[i++] = array.GetByte(offset++, 0); } if (length > i) { array = _cache.at(offset); } } return(UTF8.decode(bytes)); }
private static Optional <string> ReadRuleName(ByteBuffer source) { if (source.remaining() >= UTF8.MINIMUM_SERIALISED_LENGTH_BYTES) { string ruleName = UTF8.getDecodedStringFrom(source); return(ruleName.Length == 0 ? null : ruleName); } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowWithNoScheme() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowWithNoScheme() { // Expect Exception.expect(typeof(AuthenticationException)); Exception.expect(HasStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.Unauthorized)); // When _authentication.authenticate(map("principal", "bob", "credentials", UTF8.encode("secret"))); }
protected internal override void Encode(ChannelHandlerContext ctx, FileHeader msg, ByteBuf @out) { string name = msg.FileName(); sbyte[] bytes = UTF8.encode(name); @out.writeInt(bytes.Length); @out.writeBytes(bytes); @out.writeInt(msg.RequiredAlignment()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static void changeVersionNumber(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File storeFile, String versionString) throws java.io.IOException internal static void ChangeVersionNumber(FileSystemAbstraction fileSystem, File storeFile, string versionString) { sbyte[] versionBytes = UTF8.encode(versionString); using (StoreChannel fileChannel = fileSystem.Open(storeFile, OpenMode.READ_WRITE)) { fileChannel.Position(fileSystem.GetFileSize(storeFile) - versionBytes.Length); fileChannel.write(ByteBuffer.wrap(versionBytes)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private java.io.File fileContaining(org.neo4j.io.fs.FileSystemAbstraction fs, String content) throws java.io.IOException private File FileContaining(FileSystemAbstraction fs, string content) { File shortFile = _directory.file("file"); fs.DeleteFile(shortFile); using (Stream outputStream = fs.OpenAsOutputStream(shortFile, false)) { outputStream.Write(UTF8.encode(content), 0, UTF8.encode(content).Length); return(shortFile); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static Authentication createAuthentication(int maxFailedAttempts) throws Exception private static Authentication CreateAuthentication(int maxFailedAttempts) { UserRepository users = new InMemoryUserRepository(); PasswordPolicy policy = mock(typeof(PasswordPolicy)); Config config = Config.defaults(GraphDatabaseSettings.auth_max_failed_attempts, maxFailedAttempts.ToString()); BasicAuthManager manager = new BasicAuthManager(users, policy, Clocks.systemClock(), users, config); Authentication authentication = new BasicAuthentication(manager, manager); manager.NewUser("bob", UTF8.encode("secret"), true); manager.NewUser("mike", UTF8.encode("secret2"), false); return(authentication); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldClearCredentialsAfterUse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldClearCredentialsAfterUse() { // When sbyte[] oldPassword = UTF8.encode("secret2"); sbyte[] newPassword1 = UTF8.encode("secret"); sbyte[] newPassword2 = UTF8.encode("secret"); _authentication.authenticate(map("scheme", "basic", "principal", "mike", "credentials", oldPassword, "new_credentials", newPassword1)); _authentication.authenticate(map("scheme", "basic", "principal", "mike", "credentials", newPassword2)); // Then assertThat(oldPassword, Cleared); assertThat(newPassword1, Cleared); assertThat(newPassword2, Cleared); }
/// <summary> /// Compute the byte size needed to serialize the provided ConstraintRule using serialize. </summary> /// <param name="constraintRule"> the ConstraintRule </param> /// <returns> the byte size of ConstraintRule </returns> internal static int LengthOf(ConstraintRule constraintRule) { int length = 4; // legacy label or relType id length += 1; // schema rule type length += 1; // constraint type ConstraintDescriptor constraintDescriptor = constraintRule.ConstraintDescriptor; if (constraintDescriptor.EnforcesUniqueness()) { length += 8; // owned index id } length += constraintDescriptor.Schema().computeWith(schemaSizeComputer); length += UTF8.computeRequiredByteBufferSize(constraintRule.Name); return(length); }
// __________ ACTIONS ___________ internal virtual void CreateUser() { try { outerInstance.FlatFileRealm.newUser(Username, UTF8.encode(Password), false); Exists = true; } catch (IOException e) { outerInstance.Errors.Add(e); } catch (InvalidArgumentsException e) { if (!Exists || !e.Message.contains("The specified user '" + Username + "' already exists")) { outerInstance.Errors.Add(e); } } }
/// <summary> /// Compute the byte size needed to serialize the provided IndexRule using serialize. </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor </param> /// <returns> the byte size of StoreIndexDescriptor </returns> internal static int LengthOf(StoreIndexDescriptor indexDescriptor) { int length = 4; // legacy label or relType id length += 1; // schema rule type IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Key); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Version); length += 1; // index type if (indexDescriptor.Type() == IndexDescriptor.Type.UNIQUE) { length += 8; // owning constraint id } length += indexDescriptor.Schema().computeWith(schemaSizeComputer); length += UTF8.computeRequiredByteBufferSize(indexDescriptor.Name); return(length); }
internal virtual void ChangePassword() { string newPassword = DeviousPassword(); try { outerInstance.FlatFileRealm.setUserPassword(Username, UTF8.encode(newPassword), false); Password = newPassword; } catch (IOException e) { outerInstance.Errors.Add(e); } catch (InvalidArgumentsException e) { if (!ValidUserDoesNotExist(e) && !ValidSamePassword(newPassword, e)) { outerInstance.Errors.Add(e); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToActOnSessionWhenUpdatingCredentials() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToActOnSessionWhenUpdatingCredentials() { BoltStateMachine machine = Env.newMachine(_boltChannel); BoltResponseRecorder recorder = new BoltResponseRecorder(); // when InitMessage message = new InitMessage(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", UTF8.encode("neo4j"), "new_credentials", UTF8.encode("secret"))); machine.Process(message, recorder); machine.Process(new RunMessage("CREATE ()", EMPTY_MAP), recorder); // then assertThat(recorder.NextResponse(), succeeded()); assertThat(recorder.NextResponse(), succeeded()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailWhenTooManyAttempts() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFailWhenTooManyAttempts() { // Given int maxFailedAttempts = ThreadLocalRandom.current().Next(1, 10); Authentication auth = CreateAuthentication(maxFailedAttempts); for (int i = 0; i < maxFailedAttempts; ++i) { try { auth.Authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("gelato"))); } catch (AuthenticationException e) { assertThat(e.Status(), equalTo(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.Unauthorized)); } } // Expect Exception.expect(typeof(AuthenticationException)); Exception.expect(HasStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.AuthenticationRateLimit)); Exception.expectMessage("The client has provided incorrect authentication details too many times in a row."); //When auth.Authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("gelato"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIndicateThatCredentialsExpired() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldIndicateThatCredentialsExpired() { // When AuthenticationResult result = _authentication.authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("secret"))); // Then assertTrue(result.CredentialsExpired()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotDoAnythingOnSuccess() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotDoAnythingOnSuccess() { // When AuthenticationResult result = _authentication.authenticate(map("scheme", "basic", "principal", "mike", "credentials", UTF8.encode("secret2"))); // Then assertThat(result.LoginContext.subject().username(), equalTo("mike")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailOnMalformedToken() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFailOnMalformedToken() { // Expect Exception.expect(typeof(AuthenticationException)); Exception.expect(HasStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.Unauthorized)); Exception.expectMessage("Unsupported authentication token, the value associated with the key `principal` " + "must be a String but was: SingletonList"); // When _authentication.authenticate(map("scheme", "basic", "principal", singletonList("bob"), "credentials", UTF8.encode("secret"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotBeAbleToUpdateCredentialsIfOldCredentialsAreInvalid() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotBeAbleToUpdateCredentialsIfOldCredentialsAreInvalid() { // Expect Exception.expect(typeof(AuthenticationException)); Exception.expect(HasStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.Unauthorized)); Exception.expectMessage("The client is unauthorized due to authentication failure."); // When _authentication.authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("gelato"), "new_credentials", UTF8.encode("secret2"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToUpdateExpiredCredentials() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToUpdateExpiredCredentials() { // When AuthenticationResult result = _authentication.authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("secret"), "new_credentials", UTF8.encode("secret2"))); // Then assertThat(result.CredentialsExpired(), equalTo(false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowAndLogOnFailure() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowAndLogOnFailure() { // Expect Exception.expect(typeof(AuthenticationException)); Exception.expect(HasStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.Unauthorized)); Exception.expectMessage("The client is unauthorized due to authentication failure."); // When _authentication.authenticate(map("scheme", "basic", "principal", "bob", "credentials", UTF8.encode("banana"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToUpdateCredentials() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToUpdateCredentials() { // When _authentication.authenticate(map("scheme", "basic", "principal", "mike", "credentials", UTF8.encode("secret2"), "new_credentials", UTF8.encode("secret"))); // Then _authentication.authenticate(map("scheme", "basic", "principal", "mike", "credentials", UTF8.encode("secret"))); }