未验证 提交 def25229 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #13340 from dbeaver/changePassword#958

dbeaver/dbeaver-ee#958 ability to change password added for Oracle
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.exasol.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
public class ExasolChangeUserPassword implements DBAUserChangePassword {
private ExasolDataSource dataSource;
ExasolChangeUserPassword(ExasolDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER USER " + DBUtils.getQuotedIdentifier(dataSource, userName) + " IDENTIFIED BY \"" + CommonUtils.notEmpty(newPassword) +
"\" REPLACE \"" + CommonUtils.notEmpty(oldPassword) + "\""); // Password string must be quoted in double quote
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
}
}
......@@ -35,6 +35,7 @@ import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.DBPErrorAssistant;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
......@@ -416,6 +417,8 @@ public class ExasolDataSource extends JDBCDataSource implements DBCQueryPlanner,
return adapter.cast(new ExasolStructureAssistant(this));
} else if (adapter == DBAServerSessionManager.class) {
return adapter.cast(new ExasolServerSessionManager(this));
} else if (adapter == DBAUserChangePassword.class) {
return adapter.cast(new ExasolChangeUserPassword(this));
}
return super.getAdapter(adapter);
}
......
......@@ -81,16 +81,16 @@
</configurator>
</extension>
<extension point="org.jkiss.dbeaver.dataSourceProvider">
<!--<extension point="org.jkiss.dbeaver.dataSourceProvider">
<datasourcePatch id="sqlserver">
<treeInjection path="sqlserver/database" after="trigger">
<folder label="%tree.databaseInfo.node.name" icon="#folder_info" description="Database system information">
<treeContribution category="connectionEditor"/>
<!-- <object type="org.jkiss.dbeaver.ext.mssql.ui.editors.SQLServerSessionEditor" label="%tree.sessions.node.name" icon="#sessions" description="Server session manager" editor="org.jkiss.dbeaver.ext.mssql.ui.editors.SQLServerSessionEditor"/>-->
</folder>
<object type="org.jkiss.dbeaver.ext.mssql.ui.editors.SQLServerSessionEditor" label="%tree.sessions.node.name" icon="#sessions" description="Server session manager" editor="org.jkiss.dbeaver.ext.mssql.ui.editors.SQLServerSessionEditor"/>-->
<!--</folder>
</treeInjection>
</datasourcePatch>
</extension>
</extension>-->
<extension point="org.eclipse.ui.editors">
<editor
......
......@@ -134,7 +134,18 @@ meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerExtendedProperty.value.descripti
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerExtendedProperty.valueType.name=Value Type
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerExtendedProperty.valueType.description=Type of the value of the extended property
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.name.name = Name
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.disabled.name = Disabled
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.loginId.name = Id
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.loginTypeName.name = Login Type
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.fixedRole.name = Fixed Role
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.createDate.name = Create Date
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.modifyDate.name = Modify Date
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.defaultLanguageName.name = Default Language
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin.defaultDatabase.name = Default Database
tree.databases.node.name = Databases
tree.databases.node.tip = Server databases
tree.database.node.name = Database
tree.schemas.node.name = Schemas
tree.schema.node.name = Schema
......@@ -178,6 +189,11 @@ tree.check_constraint.node.name = Check constraint
tree.databaseTriggers.node.name = Database triggers
tree.extendedProperties.node.name = Extended Properties
tree.extendedProperty.node.name = Extended Property
tree.security.node.name = Security
tree.logins.node.name = Logins
tree.login.node.name = Login
tree.administer.node.description = Maintenance/Settings
tree.administer.node.name = Administer
driver.sqlserver.description =Microsoft JDBC Driver for SQL Server (MSSQL)
driver.jTDS.description =jTDS SQL Server (MSSQL) driver
......
......@@ -37,6 +37,7 @@
dialect="sqlserver">
<tree path="sqlserver" label="SQL Server data source">
<folder type="org.jkiss.dbeaver.ext.mssql.model.SQLServerDatabase" label="%tree.databases.node.name" icon="#folder_database" description="%tree.databases.node.tip">
<items label="%tree.database.node.name" path="database" property="databases" icon="#database">
<folder type="org.jkiss.dbeaver.ext.mssql.model.SQLServerSchema" label="%tree.schemas.node.name" icon="#folder_schema" description="Schemas">
<items label="%tree.schema.node.name" path="schema" property="schemas" icon="#schema">
......@@ -133,12 +134,6 @@
</items>
</items>
</folder>
<!--<folder type="org.jkiss.dbeaver.ext.mssql.model.SQLServerTableIndex" label="%tree.indexes.node.name" icon="#indexes" description="Table type indexes" visibleIf="object.isTableType()">
<items label="%tree.index.node.name" path="index" property="indexes" icon="#index">
<items label="%tree.index_columns.node.name" path="column" property="attributeReferences" icon="#column" virtual="true">
</items>
</items>
</folder>-->
</items>
</folder>
</items>
......@@ -146,8 +141,16 @@
<folder type="org.jkiss.dbeaver.ext.mssql.model.SQLServerDatabaseTrigger" label="%tree.databaseTriggers.node.name" icon="#triggers" description="All database triggers">
<items label="%tree.trigger.node.name" path="trigger" property="triggers" icon="#trigger"/>
</folder>
</items>
</folder>
<folder label="%tree.security.node.name" icon="#security" description="Security management">
<folder type="org.jkiss.dbeaver.ext.mssql.model.SQLServerLogin" label="%tree.logins.node.name" icon="#folder_user" description="Logins">
<items label="%tree.login.node.name" path="logins" property="logins" icon="#user"/>
</folder>
</folder>
<folder label="%tree.administer.node.name" icon="#folder_admin" description="tree.administer.node.description">
<treeContribution category="connectionEditor"/>
</folder>
</tree>
<drivers managable="true">
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
public class SQLServerChangeLoginPassword implements DBAUserChangePassword {
private SQLServerDataSource dataSource;
SQLServerChangeLoginPassword(SQLServerDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String loginName, String newPassword, String oldPassword) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user login password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER LOGIN " + DBUtils.getQuotedIdentifier(dataSource, loginName) + " WITH PASSWORD =" + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(newPassword)) +
" OLD_PASSWORD =" + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(oldPassword)));
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
}
}
......@@ -26,6 +26,7 @@ import org.jkiss.dbeaver.ext.mssql.SQLServerConstants;
import org.jkiss.dbeaver.ext.mssql.SQLServerUtils;
import org.jkiss.dbeaver.ext.mssql.model.session.SQLServerSessionManager;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.exec.*;
......@@ -57,6 +58,7 @@ public class SQLServerDataSource extends JDBCDataSource implements DBSInstanceCo
// Delegate data type reading to the driver
private final SystemDataTypeCache dataTypeCache = new SystemDataTypeCache();
private final DatabaseCache databaseCache = new DatabaseCache();
private final ServerLoginCache serverLoginCache = new ServerLoginCache();
private boolean supportsColumnProperty;
private String serverVersion;
......@@ -113,6 +115,16 @@ public class SQLServerDataSource extends JDBCDataSource implements DBSInstanceCo
return databaseCache;
}
@Association
public List<SQLServerLogin> getLogins(@NotNull DBRProgressMonitor monitor) throws DBException {
return serverLoginCache.getAllObjects(monitor, this);
}
@Association
public SQLServerLogin getLogin(@NotNull DBRProgressMonitor monitor, @NotNull String loginName) throws DBException {
return serverLoginCache.getObject(monitor, this, loginName);
}
@Override
protected Properties getAllConnectionProperties(@NotNull DBRProgressMonitor monitor, JDBCExecutionContext context, String purpose, DBPConnectionConfiguration connectionInfo) throws DBCException {
Properties properties = super.getAllConnectionProperties(monitor, context, purpose, connectionInfo);
......@@ -370,6 +382,8 @@ public class SQLServerDataSource extends JDBCDataSource implements DBSInstanceCo
return adapter.cast(new SQLServerStructureAssistant(this));
} else if (adapter == DBAServerSessionManager.class) {
return adapter.cast(new SQLServerSessionManager(this));
} else if (adapter == DBAUserChangePassword.class) {
return adapter.cast(new SQLServerChangeLoginPassword(this));
}
return super.getAdapter(adapter);
}
......@@ -485,4 +499,23 @@ public class SQLServerDataSource extends JDBCDataSource implements DBSInstanceCo
return new SQLServerDataType(dataSource, resultSet);
}
}
private class ServerLoginCache extends JDBCObjectCache<SQLServerDataSource, SQLServerLogin> {
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull SQLServerDataSource dataSource) throws SQLException {
return session.prepareStatement("SELECT * FROM sys.server_principals");
}
@Nullable
@Override
protected SQLServerLogin fetchObject(@NotNull JDBCSession session, @NotNull SQLServerDataSource dataSource, @NotNull JDBCResultSet resultSet) throws SQLException, DBException {
String loginName = JDBCUtils.safeGetString(resultSet, "name");
if (CommonUtils.isNotEmpty(loginName)) {
return new SQLServerLogin(dataSource, loginName, resultSet);
}
return null;
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.access.DBAUser;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.utils.CommonUtils;
import java.util.Date;
public class SQLServerLogin implements DBAUser {
public enum LoginType {
S("SQL Server login"),
U("Windows login"),
G("Windows group"),
R("Server role"),
C("Login mapped to a certificate"),
E("External Login"), // from Azure Active Directory
X("External group"), // from Azure Active Directory group or applications
K("Login mapped to an asymmetric key");
private final String loginType;
LoginType(String loginType) {
this.loginType = loginType;
}
public String getLoginType() {
return loginType;
}
}
private final SQLServerDataSource dataSource;
@NotNull private String loginName;
private long loginId;
private LoginType loginType;
private Date createDate;
private Date modifyDate;
@Nullable private SQLServerDatabase defaultDatabase;
@Nullable private String defaultLanguageName;
private boolean isDisabled;
private boolean isFixedRole;
public SQLServerLogin(@NotNull SQLServerDataSource dataSource, @NotNull String loginName, @NotNull JDBCResultSet resultSet) {
this.dataSource = dataSource;
this.loginName = loginName;
this.loginId = JDBCUtils.safeGetLong(resultSet, "principal_id");
String loginTypeChar = JDBCUtils.safeGetString(resultSet, "type");
if (CommonUtils.isNotEmpty(loginTypeChar)) {
this.loginType = CommonUtils.valueOf(LoginType.class, loginTypeChar);
}
this.createDate = JDBCUtils.safeGetDate(resultSet, "create_date");
this.modifyDate = JDBCUtils.safeGetDate(resultSet, "modify_date");
String defaultDatabaseName = JDBCUtils.safeGetString(resultSet, "default_database_name");
if (CommonUtils.isNotEmpty(defaultDatabaseName)) {
SQLServerDatabase database = dataSource.getDatabase(defaultDatabaseName);
if (database != null) {
defaultDatabase = database;
}
}
this.defaultLanguageName = JDBCUtils.safeGetString(resultSet, "default_language_name");
this.isDisabled = JDBCUtils.safeGetBoolean(resultSet, "is_disabled");
this.isFixedRole = JDBCUtils.safeGetBoolean(resultSet, "is_fixed_role");
}
@Nullable
@Override
public DBSObject getParentObject() {
return dataSource.getContainer();
}
@NotNull
@Override
public DBPDataSource getDataSource() {
return dataSource;
}
@NotNull
@Override
@Property(viewable = true, order = 1)
public String getName() {
return loginName;
}
@Nullable
@Override
public String getDescription() {
return null;
}
@Override
public boolean isPersisted() {
return true;
}
@Property(viewable = true, order = 2)
public long getLoginId() {
return loginId;
}
@Property(viewable = true, order = 3)
public String getLoginTypeName() {
return loginType.getLoginType();
}
@Property(viewable = true, order = 4)
public Date getCreateDate() {
return createDate;
}
@Property(viewable = true, order = 5)
public Date getModifyDate() {
return modifyDate;
}
@Nullable
@Property(viewable = true, order = 6)
public SQLServerDatabase getDefaultDatabase() {
return defaultDatabase;
}
@Nullable
@Property(viewable = true, order = 7)
public String getDefaultLanguageName() {
return defaultLanguageName;
}
@Property(viewable = true, order = 8)
public boolean isDisabled() {
return isDisabled;
}
@Property(viewable = true, order = 9)
public boolean isFixedRole() {
return isFixedRole;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.oracle.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.sql.SQLException;
public class OracleChangeUserPassword implements DBAUserChangePassword {
private OracleDataSource dataSource;
OracleChangeUserPassword(OracleDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException {
// Do not use numbers in the password beginning
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER USER " + DBUtils.getQuotedIdentifier(dataSource, userName) + " IDENTIFIED BY " + newPassword); // newPassword is unquoted, yes. That how it works in Oracle
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
}
}
......@@ -26,6 +26,7 @@ import org.jkiss.dbeaver.ext.oracle.model.plan.OracleQueryPlanner;
import org.jkiss.dbeaver.ext.oracle.model.session.OracleServerSessionManager;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.access.DBAPasswordChangeInfo;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
......@@ -522,6 +523,8 @@ public class OracleDataSource extends JDBCDataSource implements DBPObjectStatist
return adapter.cast(new OracleServerSessionManager(this));
} else if (adapter == DBCQueryPlanner.class) {
return adapter.cast(new OracleQueryPlanner(this));
} else if(adapter == DBAUserChangePassword.class) {
return adapter.cast(new OracleChangeUserPassword(this));
}
return super.getAdapter(adapter);
}
......
......@@ -37,14 +37,14 @@ public class PostgresUserChangePassword implements DBAUserChangePassword {
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword) throws DBException {
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException {
if (CommonUtils.isEmpty(newPassword)) {
// User can set new empty password, but then we will get an error when connecting with an empty password
throw new DBException("Password change error for user: " + userName + ". New password can not be empty.");
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER USER " + userName + " WITH PASSWORD " + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(newPassword)));
JDBCUtils.executeSQL(session, "ALTER USER " + DBUtils.getQuotedIdentifier(dataSource, userName) + " WITH PASSWORD " + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(newPassword)));
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.snowflake.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
public class SnowflakeChangeUserPassword implements DBAUserChangePassword {
private SnowflakeDataSource dataSource;
SnowflakeChangeUserPassword(SnowflakeDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER USER " + DBUtils.getQuotedIdentifier(dataSource, userName) + " SET PASSWORD =" + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(newPassword)));
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
}
}
......@@ -24,6 +24,7 @@ import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.GenericSchema;
import org.jkiss.dbeaver.ext.snowflake.SnowflakeConstants;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext;
......@@ -81,4 +82,12 @@ public class SnowflakeDataSource extends GenericDataSource {
executionContext.setDefaultSchema(monitor, defaultSchema, true);
}
}
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == DBAUserChangePassword.class) {
return adapter.cast(new SnowflakeChangeUserPassword(this));
}
return super.getAdapter(adapter);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.vertica.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
public class VerticaChangeUserPassword implements DBAUserChangePassword {
private VerticaDataSource dataSource;
VerticaChangeUserPassword(VerticaDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Change user password")) {
session.enableLogging(false);
JDBCUtils.executeSQL(session, "ALTER USER " + DBUtils.getQuotedIdentifier(dataSource, userName) + " IDENTIFIED BY " + SQLUtils.quoteString(dataSource, CommonUtils.notEmpty(newPassword)));
} catch (SQLException e) {
throw new DBCException("Error changing user password", e);
}
}
}
......@@ -22,6 +22,7 @@ import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
......@@ -116,6 +117,14 @@ public class VerticaDataSource extends GenericDataSource {
return nodeCache.getAllObjects(monitor, this);
}
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == DBAUserChangePassword.class) {
return adapter.cast(new VerticaChangeUserPassword(this));
}
return super.getAdapter(adapter);
}
class NodeCache extends JDBCObjectCache<VerticaDataSource, VerticaNode> {
@NotNull
@Override
......
......@@ -21,6 +21,6 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
public interface DBAUserChangePassword {
void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword) throws DBException;
void changeUserPassword(DBRProgressMonitor monitor, String userName, String newPassword, String oldPassword) throws DBException;
}
......@@ -63,7 +63,7 @@ public class ChangePasswordDialogHandler extends AbstractHandler {
try {
UIUtils.runInProgressService(monitor -> {
try {
changePassword.changeUserPassword(monitor, userName, newPassword);
changePassword.changeUserPassword(monitor, userName, newPassword, oldPassword);
if (DBWorkbench.getPlatformUI().confirmAction(
UIConnectionMessages.dialog_user_password_change_question_label,
......
......@@ -19,8 +19,10 @@ package org.jkiss.dbeaver.ui.actions;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.IAdaptable;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.access.DBAUserChangePassword;
import org.jkiss.dbeaver.model.navigator.DBNDataSource;
import org.jkiss.utils.CommonUtils;
public class ChangeUserPasswordPropertyTester extends PropertyTester {
......@@ -32,9 +34,11 @@ public class ChangeUserPasswordPropertyTester extends PropertyTester {
if (property.equals("canChangePassword")) {
DBNDataSource dsNode = (DBNDataSource) element;
DBPDataSource dataSource = dsNode.getDataSourceContainer().getDataSource();
DBPDataSourceContainer dataSourceContainer = dsNode.getDataSourceContainer();
DBPDataSource dataSource = dataSourceContainer.getDataSource();
String userName = dataSourceContainer.getConnectionConfiguration().getUserName();
if (dataSource instanceof IAdaptable) {
return ((IAdaptable) dataSource).getAdapter(DBAUserChangePassword.class) != null;
return ((IAdaptable) dataSource).getAdapter(DBAUserChangePassword.class) != null && CommonUtils.isNotEmpty(userName);
}
}
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册