@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 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 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; }
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 RoleRecord getRole( String roleName ) throws InvalidArgumentsException { RoleRecord role = roleRepository.getRoleByName( roleName ); if ( role == null ) { throw new InvalidArgumentsException( "Role '" + roleName + "' does not exist." ); } return role; }
@Override public User getUser( String username ) throws InvalidArgumentsException { User u = userRepository.getUserByName( username ); if ( u == null ) { throw new InvalidArgumentsException( "User '" + username + "' does not exist." ); } return u; }
@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; }
@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 ); }