@Override public void validatePassword( byte[] password ) throws InvalidArgumentsException { if ( password == null || password.length == 0 ) { throw new InvalidArgumentsException( "A password cannot be empty." ); } } }
new Neo4jError( e.status(), e.getMessage() ) ) );
@Test public void shouldDeleteUser() throws Exception { authManager.newUser( "andres", UTF8.encode( "123" ), false ); assertEmpty( admin, "CALL dbms.security.deleteUser('andres')" ); try { authManager.getUser( "andres" ); fail("Andres should no longer exist, expected exception."); } catch ( InvalidArgumentsException e ) { assertThat( e.getMessage(), containsString( "User 'andres' does not exist." ) ); } catch ( Throwable t ) { assertThat( t.getClass(), equalTo( InvalidArgumentsException.class ) ); } }
new Neo4jError( e.status(), e.getMessage() ) ) );
@Test public void shouldFailToDeleteUnknownUser() throws Throwable { // Given manager.start(); manager.newUser( "jake", password( "abc123" ), true ); try { // When manager.deleteUser( "nonExistentUser" ); fail("User 'nonExistentUser' should no longer exist, expected exception."); } catch ( InvalidArgumentsException e ) { assertThat( e.getMessage(), containsString( "User 'nonExistentUser' does not exist." ) ); } catch ( Throwable t ) { assertThat( t.getClass(), IsEqual.equalTo( InvalidArgumentsException.class ) ); } // Then assertNotNull( users.getUserByName( "jake" ) ); }
static InvalidArgumentsException unknownSectionException( String section ) { return new InvalidArgumentsException( String.format( "Unknown section '%s', known sections are %s", section, NAMES ) ); } }
@Override public void assertValidUsername( String username ) throws InvalidArgumentsException { if ( username == null || username.isEmpty() ) { throw new InvalidArgumentsException( "The provided username is empty." ); } if ( !usernamePattern.matcher( username ).matches() ) { throw new InvalidArgumentsException( "Username '" + username + "' contains illegal characters. Use ascii characters that are not ',', ':' or whitespaces." ); } }
private int asInteger( Object value ) throws InvalidArgumentsException { if ( value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long ) { return ((Number)value).intValue(); } throw new InvalidArgumentsException( String.format( "Option `%s` requires integer argument, got `%s`", name, value ) ); } }
@Override Integer parse( Object value ) throws InvalidArgumentsException { int x = asInteger( value ); if ( x < 0 ) { throw new InvalidArgumentsException( String.format( "Option `%s` requires positive integer argument, got `%d`", name, x ) ); } return x; }
@Override public User getUser( String username ) throws InvalidArgumentsException { User user = userRepository.getUserByName( username ); if ( user == null ) { throw new InvalidArgumentsException( "User '" + username + "' does not exist." ); } return user; }
private QueryCollector collectorStateMachine( String section ) throws InvalidArgumentsException { switch ( section ) { case Sections.TOKENS: case Sections.GRAPH_COUNTS: throw new InvalidArgumentsException( "Section '%s' does not have to be explicitly collected, it can always be directly retrieved." ); case Sections.QUERIES: return dataCollector.queryCollector; default: throw Sections.unknownSectionException( section ); } } }
@Override public void create( User user ) throws InvalidArgumentsException, IOException { assertValidUsername( user.name() ); synchronized ( this ) { // Check for existing user for ( User other : users ) { if ( other.name().equals( user.name() ) ) { throw new InvalidArgumentsException( "The specified user '" + user.name() + "' already exists." ); } } users.add( user ); usersByName.put( user.name(), user ); persistUsers(); } }
@Description( "Delete the specified user." ) @Procedure( name = "dbms.security.deleteUser", mode = DBMS ) public void deleteUser( @Name( "username" ) String username ) throws InvalidArgumentsException, IOException { securityContext.assertCredentialsNotExpired(); if ( securityContext.subject().hasUsername( username ) ) { throw new InvalidArgumentsException( "Deleting yourself (user '" + username + "') is not allowed." ); } userManager.deleteUser( username ); }
throw new InvalidArgumentsException( "Old password and new password cannot be the same." );
private QueryId( long kernelQueryId ) throws InvalidArgumentsException { if ( kernelQueryId <= 0 ) { throw new InvalidArgumentsException( "Negative query ids are not supported (expected format: query-1234)" ); } this.kernelQueryId = kernelQueryId; }
@Override public void validatePassword( byte[] password ) throws InvalidArgumentsException { if ( password == null || password.length == 0 ) { throw new InvalidArgumentsException( "A password cannot be empty." ); } } }
static InvalidArgumentsException unknownSectionException( String section ) { return new InvalidArgumentsException( String.format( "Unknown section '%s', known sections are %s", section, NAMES ) ); } }
@Override public void assertValidRoleName( String name ) throws InvalidArgumentsException { if ( name == null || name.isEmpty() ) { throw new InvalidArgumentsException( "The provided role name is empty." ); } if ( !roleNamePattern.matcher( name ).matches() ) { throw new InvalidArgumentsException( "Role name '" + name + "' contains illegal characters. Use simple ascii characters and numbers." ); } }
@Override public void assertValidUsername( String username ) throws InvalidArgumentsException { if ( username == null || username.isEmpty() ) { throw new InvalidArgumentsException( "The provided username is empty." ); } if ( !usernamePattern.matcher( username ).matches() ) { throw new InvalidArgumentsException( "Username '" + username + "' contains illegal characters. Use ascii characters that are not ',', ':' or whitespaces." ); } }
private int asInteger( Object value ) throws InvalidArgumentsException { if ( value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long ) { return ((Number)value).intValue(); } throw new InvalidArgumentsException( String.format( "Option `%s` requires integer argument, got `%s`", name, value ) ); } }