Class KeyboardLayout

java.lang.Object
org.hibernate.validator.spi.password.KeyboardLayout

@Incubating public final class KeyboardLayout extends Object
Defines a keyboard layout as a mapping from characters to physical key positions. Used by the noKeyboardWalk() password policy rule to detect walks across adjacent keys.

Pre-built layouts are available as constants. Custom layouts can be created via of(String[], String[], String[], String[]), where each array represents a keyboard row (top to bottom) and each string in the array groups all characters produced by the same physical key (e.g. "aAą" for a key that produces a, A, and ą).

Since:
9.2.0
  • Field Details

    • QWERTY

      public static final KeyboardLayout QWERTY
      Standard US QWERTY layout.
    • AZERTY

      public static final KeyboardLayout AZERTY
      French AZERTY layout, including diacritical characters on dedicated keys.
    • DVORAK

      public static final KeyboardLayout DVORAK
      Dvorak simplified layout.
    • NORDIC

      public static final KeyboardLayout NORDIC
      Nordic QWERTY layout (Swedish/Finnish variant) with Å, Ä, Ö keys.
    • CYRILLIC_UA

      public static final KeyboardLayout CYRILLIC_UA
      Ukrainian Cyrillic (ЙЦУКЕН) layout.
  • Method Details

    • of

      public static KeyboardLayout of(String[] row0, String[] row1, String[] row2, String[] row3)
      Creates a custom keyboard layout from four rows of key groups.

      Each row is an array of strings. Each string groups all characters produced by the same physical key — for example, "aAą" means that a, A, and ą all occupy the same physical position.

      Rows are ordered top to bottom (number row, top letter row, home row, bottom row). The standard keyboard row stagger is applied automatically.

      Parameters:
      row0 - number/symbol row (topmost)
      row1 - top letter row
      row2 - middle letter row
      row3 - bottom letter row
      Returns:
      a new keyboard layout
    • areAdjacent

      public boolean areAdjacent(char a, char b)
      Returns whether two characters occupy physically adjacent keys on this layout. Returns false if either character is not present in this layout.
      Parameters:
      a - the first character
      b - the second character
      Returns:
      true if both characters are present and their keys are adjacent