Skip to content

Commit ae429f5

Browse files
committed
#866 Backport to Jaybird 6.0.2: #834 FBManager auth plugin support
1 parent a705d77 commit ae429f5

File tree

3 files changed

+73
-39
lines changed

3 files changed

+73
-39
lines changed

src/docs/asciidoc/release_notes.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Changes per Jaybird 6 release.
3333
See also <<whats-new-in-jaybird-6>>.
3434
For known issues, consult <<known-issues>>.
3535

36+
=== Jaybird 6.0.2
37+
38+
The following was fixed or changed since Jaybird 6.0.1:
39+
40+
* Improvement: added `authPlugins` property on `FBManager` (https://github.com/FirebirdSQL/jaybird/issues/866[#866])
41+
3642
=== Jaybird 6.0.1
3743

3844
The following was fixed or changed since Jaybird 6.0.0:

src/main/org/firebirdsql/management/FBManager.java

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@
4242
*/
4343
public class FBManager implements FBManagerMBean {
4444

45-
private static final int DEFAULT_PORT = 3050;
4645
private static final System.Logger log = System.getLogger(FBManager.class.getName());
4746

4847
private FbDatabaseFactory dbFactory;
49-
private String host = "localhost";
50-
private Integer port;
48+
private final IConnectionProperties connectionProperties = new FbConnectionProperties();
5149
private String fileName;
52-
private String userName;
53-
private String password;
54-
private String roleName;
55-
private String enableProtocol;
5650
private int dialect = ISCConstants.SQL_DIALECT_CURRENT;
5751
private int pageSize = -1;
5852
private String defaultCharacterSet;
@@ -71,10 +65,11 @@ public FBManager() {
7165

7266
public FBManager(GDSType type) {
7367
this.type = type;
68+
connectionProperties.setType(type.toString());
7469
}
7570

7671
public FBManager(String type) {
77-
this.type = GDSType.getType(type);
72+
this(GDSType.getType(type));
7873
}
7974

8075
//Service methods
@@ -129,22 +124,22 @@ public String getName() {
129124

130125
@Override
131126
public void setServer(String host) {
132-
this.host = host;
127+
connectionProperties.setServerName(host);
133128
}
134129

135130
@Override
136131
public String getServer() {
137-
return host;
132+
return connectionProperties.getServerName();
138133
}
139134

140135
@Override
141136
public void setPort(int port) {
142-
this.port = port;
137+
connectionProperties.setPortNumber(port);
143138
}
144139

145140
@Override
146141
public int getPort() {
147-
return port != null ? port : DEFAULT_PORT;
142+
return connectionProperties.getPortNumber();
148143
}
149144

150145
@Override
@@ -159,7 +154,7 @@ public void setFileName(String fileName) {
159154

160155
@Override
161156
public String getType() {
162-
return this.type.toString();
157+
return type.toString();
163158
}
164159

165160
@Override
@@ -171,46 +166,57 @@ public void setType(String type) {
171166
}
172167

173168
this.type = gdsType;
169+
connectionProperties.setType(gdsType.toString());
174170
}
175171

176172
@Override
177173
public String getUserName() {
178-
return userName;
174+
return connectionProperties.getUser();
179175
}
180176

181177
@Override
182178
public void setUserName(String userName) {
183-
this.userName = userName;
179+
connectionProperties.setUser(userName);
184180
}
185181

186182
@Override
187183
public String getPassword() {
188-
return password;
184+
return connectionProperties.getPassword();
189185
}
190186

191187
@Override
192188
public void setPassword(String password) {
193-
this.password = password;
189+
connectionProperties.setPassword(password);
194190
}
195191

196192
@Override
197193
public String getRoleName() {
198-
return roleName;
194+
return connectionProperties.getRoleName();
199195
}
200196

201197
@Override
202198
public void setRoleName(String roleName) {
203-
this.roleName = roleName;
199+
connectionProperties.setRoleName(roleName);
200+
}
201+
202+
@Override
203+
public String getAuthPlugins() {
204+
return connectionProperties.getAuthPlugins();
205+
}
206+
207+
@Override
208+
public void setAuthPlugins(String authPlugins) {
209+
connectionProperties.setAuthPlugins(authPlugins);
204210
}
205211

206212
@Override
207213
public void setEnableProtocol(String enableProtocol) {
208-
this.enableProtocol = enableProtocol;
214+
connectionProperties.setEnableProtocol(enableProtocol);
209215
}
210216

211217
@Override
212218
public String getEnableProtocol() {
213-
return enableProtocol;
219+
return connectionProperties.getEnableProtocol();
214220
}
215221

216222
@Override
@@ -299,15 +305,16 @@ public synchronized void createDatabase(String fileName, String user, String pas
299305
IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password, roleName);
300306
connectionProperties.setDatabaseName(fileName);
301307
FbDatabase db = dbFactory.connect(connectionProperties);
302-
db.attach();
303-
304-
// if forceCreate is set, drop the database correctly
305-
// otherwise exit, database already exists
306-
if (forceCreate)
307-
db.dropDatabase();
308-
else {
309-
db.close();
310-
return; //database exists, don't wipe it out.
308+
try {
309+
db.attach();
310+
if (forceCreate) {
311+
db.dropDatabase();
312+
} else {
313+
// database exists, don't wipe it out
314+
return;
315+
}
316+
} finally {
317+
if (db.isAttached()) db.close();
311318
}
312319
} catch (SQLException e) {
313320
// we ignore it
@@ -349,8 +356,12 @@ public synchronized void dropDatabase(String fileName, String user, String passw
349356
IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password, roleName);
350357
connectionProperties.setDatabaseName(fileName);
351358
FbDatabase db = dbFactory.connect(connectionProperties);
352-
db.attach();
353-
db.dropDatabase();
359+
try {
360+
db.attach();
361+
db.dropDatabase();
362+
} finally {
363+
if (db.isAttached()) db.close();
364+
}
354365
} catch (Exception e) {
355366
log.log(System.Logger.Level.ERROR, "Exception dropping database", e);
356367
throw e;
@@ -363,23 +374,20 @@ public synchronized boolean isDatabaseExists(String fileName, String user, Strin
363374
try {
364375
IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password, null);
365376
connectionProperties.setDatabaseName(fileName);
366-
FbDatabase db = dbFactory.connect(connectionProperties);
367-
db.attach();
368-
db.close();
377+
try (FbDatabase db = dbFactory.connect(connectionProperties)) {
378+
db.attach();
379+
}
369380
return true;
370381
} catch (Exception e) {
371382
return false;
372383
}
373384
}
374385

375386
private IConnectionProperties createDefaultConnectionProperties(String user, String password, String roleName) {
376-
FbConnectionProperties connectionProperties = new FbConnectionProperties();
387+
var connectionProperties = this.connectionProperties.asNewMutable();
377388
connectionProperties.setUser(user);
378389
connectionProperties.setPassword(password);
379390
connectionProperties.setRoleName(roleName);
380-
connectionProperties.setServerName(getServer());
381-
connectionProperties.setPortNumber(getPort());
382-
connectionProperties.setEnableProtocol(getEnableProtocol());
383391
return connectionProperties;
384392
}
385393

src/main/org/firebirdsql/management/FBManagerMBean.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ public interface FBManagerMBean extends AutoCloseable {
192192
*/
193193
void setRoleName(String roleName);
194194

195+
/**
196+
* Sets the authentication plugins to try.
197+
* <p>
198+
* Invalid names are skipped during authentication.
199+
* </p>
200+
*
201+
* @param authPlugins
202+
* comma-separated list of authentication plugins
203+
* @since 6.0.2
204+
*/
205+
void setAuthPlugins(String authPlugins);
206+
207+
/**
208+
* Get the list of authentication plugins to try.
209+
*
210+
* @return comma-separated list of authentication plugins
211+
* @since 6.0.2
212+
*/
213+
String getAuthPlugins();
214+
195215
/**
196216
* @return enable protocol value (see also {@link AttachmentProperties#getEnableProtocol()}.
197217
* @since 6

0 commit comments

Comments
 (0)