Skip to content

Commit

Permalink
Update auth in Neo4j Server to remove token
Browse files Browse the repository at this point in the history
Authentication is now applied directly on all endpoint calls
  • Loading branch information
cleishm committed Feb 5, 2015
1 parent e9e1475 commit 3ec19b0
Show file tree
Hide file tree
Showing 46 changed files with 1,745 additions and 2,294 deletions.
Expand Up @@ -248,8 +248,8 @@ enum Security implements Status
{
// client
AuthenticationFailed( ClientError, "The client provided an incorrect username and/or password." ),
AuthorizationFailed( ClientError, "The client provided an invalid authorization token, or does not have privileges to perform the operation requested." ),
AuthenticationRateLimit( ClientError, "The client has provided incorrect authentication details too many times in a row. You will be allowed to try again in a few seconds." ),
AuthorizationFailed( ClientError, "The client does not have privileges to perform the operation requested." ),
AuthenticationRateLimit( ClientError, "The client has provided incorrect authentication details too many times in a row." ),
ModifiedConcurrently( TransientError, "The user was modified concurrently to this request." );

private final Code code;
Expand Down

This file was deleted.

@@ -0,0 +1,66 @@
/**
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.util;

public class Codecs
{
final private static char[] hexArray = "0123456789ABCDEF".toCharArray();

/**
* Converts a byte array to a hexadecimal string.
*
* @param bytes Bytes to be encoded
* @return A string of hex characters [0-9A-F]
*/
public static String encodeHexString( byte[] bytes )
{
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ )
{
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String( hexChars );
}

/**
* Converts a hexadecimal string to a byte array
*
* @param hexString A string of hexadecimal characters [0-9A-Fa-f] to decode
* @return Decoded bytes, or null if the {@param hexString} is not valid
*/
public static byte[] decodeHexString( String hexString )
{
int len = hexString.length();
byte[] data = new byte[len / 2];
for ( int i = 0, j = 0; i < len; i += 2, j++ )
{
int highByte = Character.digit( hexString.charAt( i ), 16 ) << 4;
int lowByte = Character.digit( hexString.charAt( i + 1 ), 16 );
if ( highByte < 0 || lowByte < 0 )
{
return null;
}
data[j] = (byte) ( highByte + lowByte );
}
return data;
}
}
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class CodecsTest
{
@Test
public void shouldEncodeBytesToString()
{
String result = Codecs.encodeHexString( new byte[]{(byte) 0xFF, (byte) 0x94, (byte) 0x5C, (byte) 0x00, (byte) 0x3D} );
assertEquals( "FF945C003D", result );
}

@Test
public void shouldEncodeEmptyBytesToEmptyString()
{
String result = Codecs.encodeHexString( new byte[]{} );
assertEquals( "", result );
}

@Test
public void shouldDecodeStringToBytes()
{
byte[] result = Codecs.decodeHexString( "00f34CEFFF3e02" );
byte[] expected = new byte[] {(byte) 0x00, (byte) 0xF3, (byte) 0x4C, (byte) 0xEF, (byte) 0xFF, (byte) 0x3E, (byte) 0x02 };
assertArrayEquals( expected, result );
}

@Test
public void shouldDecodeEmptyStringToEmptyBytes()
{
byte[] result = Codecs.decodeHexString( "" );
assertArrayEquals( new byte[]{}, result );
}
}

0 comments on commit 3ec19b0

Please sign in to comment.