|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2026 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement.create.user; |
| 11 | + |
| 12 | +import java.io.Serializable; |
| 13 | +import net.sf.jsqlparser.expression.StringValue; |
| 14 | + |
| 15 | +/** Structured authentication clause of a MySQL user account. */ |
| 16 | +public class UserAuthentication implements Serializable { |
| 17 | + |
| 18 | + public enum Mode { |
| 19 | + BY_PASSWORD, BY_RANDOM_PASSWORD, WITH_PLUGIN, WITH_PLUGIN_BY_PASSWORD, WITH_PLUGIN_BY_RANDOM_PASSWORD, WITH_PLUGIN_AS_STRING |
| 20 | + } |
| 21 | + |
| 22 | + private Mode mode; |
| 23 | + private String plugin; |
| 24 | + private StringValue credential; |
| 25 | + |
| 26 | + public Mode getMode() { |
| 27 | + return mode; |
| 28 | + } |
| 29 | + |
| 30 | + public void setMode(Mode mode) { |
| 31 | + this.mode = mode; |
| 32 | + } |
| 33 | + |
| 34 | + public String getPlugin() { |
| 35 | + return plugin; |
| 36 | + } |
| 37 | + |
| 38 | + public void setPlugin(String plugin) { |
| 39 | + this.plugin = plugin; |
| 40 | + } |
| 41 | + |
| 42 | + public StringValue getCredential() { |
| 43 | + return credential; |
| 44 | + } |
| 45 | + |
| 46 | + public void setCredential(StringValue credential) { |
| 47 | + this.credential = credential; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public String toString() { |
| 52 | + switch (mode) { |
| 53 | + case BY_PASSWORD: |
| 54 | + return "IDENTIFIED BY " + credential; |
| 55 | + case BY_RANDOM_PASSWORD: |
| 56 | + return "IDENTIFIED BY RANDOM PASSWORD"; |
| 57 | + case WITH_PLUGIN: |
| 58 | + return "IDENTIFIED WITH " + plugin; |
| 59 | + case WITH_PLUGIN_BY_PASSWORD: |
| 60 | + return "IDENTIFIED WITH " + plugin + " BY " + credential; |
| 61 | + case WITH_PLUGIN_BY_RANDOM_PASSWORD: |
| 62 | + return "IDENTIFIED WITH " + plugin + " BY RANDOM PASSWORD"; |
| 63 | + case WITH_PLUGIN_AS_STRING: |
| 64 | + return "IDENTIFIED WITH " + plugin + " AS " + credential; |
| 65 | + default: |
| 66 | + throw new IllegalStateException("Unsupported authentication mode: " + mode); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public UserAuthentication withMode(Mode mode) { |
| 71 | + setMode(mode); |
| 72 | + return this; |
| 73 | + } |
| 74 | + |
| 75 | + public UserAuthentication withPlugin(String plugin) { |
| 76 | + setPlugin(plugin); |
| 77 | + return this; |
| 78 | + } |
| 79 | + |
| 80 | + public UserAuthentication withCredential(StringValue credential) { |
| 81 | + setCredential(credential); |
| 82 | + return this; |
| 83 | + } |
| 84 | +} |
0 commit comments