Skip to content

Commit

Permalink
Merge branch 'bugfix/IJMP-2143' into 'release/v2.1.0'
Browse files Browse the repository at this point in the history
IJMP-2143 Password strings changed to CharArrays

See merge request ijmp/for-mainframe!639
  • Loading branch information
Uladzislau Kalesnikau committed Jan 17, 2025
2 parents 6661f25 + 4aed8d0 commit cfda6e6
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/_template__of_Kotest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gradle = "2.1.0"
kotlinJvm = "1.9.22"
changelog = "2.2.1"
kover = "0.8.3"
dependencycheck = "10.0.4"
dependencycheck = "12.0.0"

[libraries]
# build deps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ConfigSandboxImpl : ConfigSandbox {
.filterIsInstance<EntityWithUuid>()
.map {
with(CredentialService.getService()) {
Credentials(it.uuid, getUsernameByKey(it.uuid) ?: "", getPasswordByKey(it.uuid) ?: "")
Credentials(it.uuid, getUsernameByKey(it.uuid) ?: "", getPasswordByKey(it.uuid) ?: charArrayOf())
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,27 @@ interface CredentialService {

companion object {

@JvmStatic
fun getService(): CredentialService = service()

/**
* Returns a username of a particular connection config or throws the [CredentialsNotFoundForConnectionException]
* @param connectionConfig connection config instance to search username for
* @return the username of the connection config
*/
@JvmStatic
fun <ConnectionConfig : ConnectionConfigBase> getUsername(connectionConfig: ConnectionConfig) =
getService().getUsernameByKey(connectionConfig.uuid)
fun <ConnectionConfig : ConnectionConfigBase> getUsername(connectionConfig: ConnectionConfig): String {
return getService().getUsernameByKey(connectionConfig.uuid)
?: throw CredentialsNotFoundForConnectionException(connectionConfig)
}

/**
* Returns a password of a particular connection config or throws the [CredentialsNotFoundForConnectionException]
* @param connectionConfig connection config instance to search password for
* @return the password of the connection config
*/
@JvmStatic
fun <ConnectionConfig : ConnectionConfigBase> getPassword(connectionConfig: ConnectionConfig) =
getService().getPasswordByKey(connectionConfig.uuid)
fun <ConnectionConfig : ConnectionConfigBase> getPassword(connectionConfig: ConnectionConfig): CharArray {
return getService().getPasswordByKey(connectionConfig.uuid)
?: throw CredentialsNotFoundForConnectionException(connectionConfig)
}

/**
* Returns owner of particular connection config if the owner field is not empty or conforms
Expand All @@ -75,7 +74,6 @@ interface CredentialService {
* @param connectionConfig connection config instance to get owner from
* @return owner of the connection config if the owner is present, empty string otherwise
*/
@JvmStatic
fun getOwner(connectionConfig: ConnectionConfig): String {
val possibleOwner = connectionConfig.owner
return if (possibleOwner.isNotEmpty() && possibleOwner.length <= USER_OR_OWNER_SYMBOLS_MAX_SIZE) {
Expand All @@ -99,15 +97,15 @@ interface CredentialService {
* @param connectionConfigUuid id of connection config
* @return password of config
*/
fun getPasswordByKey(connectionConfigUuid: String): String?
fun getPasswordByKey(connectionConfigUuid: String): CharArray?

/**
* Sets user and password for particular connection config
* @param connectionConfigUuid id of connection config
* @param username username to set in config
* @param password password to set in config
*/
fun setCredentials(connectionConfigUuid: String, username: String, password: String)
fun setCredentials(connectionConfigUuid: String, username: String, password: CharArray)

/**
* Resets user and password in particular connection config
Expand All @@ -121,5 +119,5 @@ val ConnectionConfig.authToken: String
get() = runTask("Retrieving information for auth token") {
val username = CredentialService.getUsername(this)
val password = CredentialService.getPassword(this)
Credentials.basic(username, password)
Credentials.basic(username, String(password))
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ class CredentialServiceImpl : CredentialService {
* Get user password by connection config UUID.
* @see CredentialService.getPasswordByKey
*/
override fun getPasswordByKey(connectionConfigUuid: String): String? {
override fun getPasswordByKey(connectionConfigUuid: String): CharArray? {
val credentials = getCredentials(connectionConfigUuid)
return credentials?.getPasswordAsString()
return credentials?.password?.chars
}

/**
* Set user credentials.
* @see CredentialService.setCredentials
*/
override fun setCredentials(connectionConfigUuid: String, username: String, password: String) {
override fun setCredentials(connectionConfigUuid: String, username: String, password: CharArray) {
val credentialAttributes = createCredentialAttributes(connectionConfigUuid)
val credentials = Credentials(username, password)
runBackgroundableTask("Setting user credentials") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Credentials {
var username = ""

@Column
var password = ""
var password: CharArray = charArrayOf()

constructor()
constructor(connectionConfigUuid: String, username: String, password: String) {
constructor(connectionConfigUuid: String, username: String, password: CharArray) {
this.configUuid = connectionConfigUuid
this.username = username
this.password = password
Expand All @@ -42,7 +42,7 @@ class Credentials {
if (other == null || javaClass != other.javaClass) return false
val that = other as Credentials
if (configUuid != that.configUuid) return false
return username == that.username && password == that.password
return username == that.username && password.contentEquals(that.password)
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ChangePasswordDialog(

init {
init()
title = "Change user password"
title = "Change User Password"
}

/** Create dialog with the fields */
Expand All @@ -54,8 +54,8 @@ class ChangePasswordDialog(
row {
label("Old password: ")
.widthGroup(sameWidthLabelsGroup)
cell(JPasswordField())
.bindText(state::oldPassword)
passwordField()
.bindText({ String(state.oldPassword) }, { state.oldPassword = it.toCharArray() })
.applyToComponent {
this.layout = BorderLayout()
addShowHidePasswordIcon(this)
Expand All @@ -66,14 +66,14 @@ class ChangePasswordDialog(
row {
label("New password: ")
.widthGroup(sameWidthLabelsGroup)
cell(JPasswordField())
.bindText(state::newPassword)
passwordField()
.bindText({ String(state.newPassword) }, { state.newPassword = it.toCharArray() })
.applyToComponent {
this.layout = BorderLayout()
addShowHidePasswordIcon(this)
addFocusListener(object : FocusAdapter() {
override fun focusLost(e: FocusEvent?) {
state.newPassword = String(this@applyToComponent.password)
state.newPassword = this@applyToComponent.password
}
})
}
Expand All @@ -83,8 +83,8 @@ class ChangePasswordDialog(
row {
label("Confirm password: ")
.widthGroup(sameWidthLabelsGroup)
cell(JPasswordField())
.bindText(state::confirmPassword)
passwordField()
.bindText({ String(state.confirmPassword) }, { state.confirmPassword = it.toCharArray() })
.applyToComponent {
this.layout = BorderLayout()
addShowHidePasswordIcon(this)
Expand Down Expand Up @@ -116,5 +116,4 @@ class ChangePasswordDialog(
component.add(eyeIcon, BorderLayout.EAST)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,27 @@ package eu.ibagroup.formainframe.config.connect.ui
*/
data class ChangePasswordDialogState(
var username: String = "",
var oldPassword: String = "",
var newPassword: String = "",
var confirmPassword: String = ""
)
var oldPassword: CharArray = charArrayOf(),
var newPassword: CharArray = charArrayOf(),
var confirmPassword: CharArray = charArrayOf()
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ChangePasswordDialogState) return false

if (username != other.username) return false
if (!oldPassword.contentEquals(other.oldPassword)) return false
if (!newPassword.contentEquals(other.newPassword)) return false
if (!confirmPassword.contentEquals(other.confirmPassword)) return false

return true
}

override fun hashCode(): Int {
var result = username.hashCode()
result = 31 * result + oldPassword.contentHashCode()
result = 31 * result + newPassword.contentHashCode()
result = 31 * result + confirmPassword.contentHashCode()
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class ConnectionDialogStateBase<ConnectionConfig: ConnectionConfigBase>
abstract var connectionName: String
abstract var username: String
abstract var owner: String
abstract var password: String
abstract var password: CharArray
abstract var connectionUrl: String
abstract var credentials: Credentials
abstract var connectionConfig: ConnectionConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ConnectionDialog(
return initialState.connectionName != state.connectionName &&
initialState.connectionUrl == state.connectionUrl &&
initialState.username == state.username &&
initialState.password == state.password &&
initialState.password.contentEquals(state.password) &&
initialState.isAllowSsl == state.isAllowSsl
}

Expand Down Expand Up @@ -310,8 +310,8 @@ class ConnectionDialog(
row {
label("Password: ")
.widthGroup(sameWidthLabelsGroup)
passField = cell(JPasswordField())
.bindText(state::password)
passField = passwordField()
.bindText({ String(state.password) }, { state.password = it.toCharArray() })
.validationOnApply { validateForBlank(it) }
.align(AlignX.FILL)
}
Expand Down Expand Up @@ -356,8 +356,8 @@ class ConnectionDialog(
}
if (state.zVersion > ZVersion.ZOS_2_4) {
row {
button("Change user password") {
val changePasswordInitState = ChangePasswordDialogState(state.username, state.password, "")
button("Change User Password") {
val changePasswordInitState = ChangePasswordDialogState(state.username, state.password, charArrayOf())
val dataOpsManager = DataOpsManager.getService()
showUntilDone(
initialState = changePasswordInitState,
Expand All @@ -372,8 +372,8 @@ class ConnectionDialog(
operation = ChangePasswordOperation(
request = ChangePassword(
changePasswordState.username,
changePasswordState.oldPassword,
changePasswordState.newPassword
String(changePasswordState.oldPassword),
String(changePasswordState.newPassword)
),
connectionConfig = state.connectionConfig
),
Expand Down Expand Up @@ -402,7 +402,7 @@ class ConnectionDialog(
} else {
if (state.username == changePasswordState.username) {
passField.applyToComponent {
this.text = changePasswordState.newPassword
this.text = String(changePasswordState.newPassword)
state.password = changePasswordState.newPassword
val balloon = JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class ConnectionDialogState(
override var connectionUrl: String = "",
/*var apiMeditationLayer: String = "",*/
override var username: String = "",
override var password: String = "",
override var password: CharArray = charArrayOf(),
override var owner: String = "",
var isAllowSsl: Boolean = false,
var zVersion: ZVersion = ZVersion.ZOS_2_1,
Expand Down Expand Up @@ -70,6 +70,36 @@ data class ConnectionDialogState(
owner = owner
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConnectionDialogState) return false

if (isAllowSsl != other.isAllowSsl) return false
if (connectionUuid != other.connectionUuid) return false
if (connectionName != other.connectionName) return false
if (connectionUrl != other.connectionUrl) return false
if (username != other.username) return false
if (!password.contentEquals(other.password)) return false
if (owner != other.owner) return false
if (zVersion != other.zVersion) return false
if (mode != other.mode) return false

return true
}

override fun hashCode(): Int {
var result = isAllowSsl.hashCode()
result = 31 * result + connectionUuid.hashCode()
result = 31 * result + connectionName.hashCode()
result = 31 * result + connectionUrl.hashCode()
result = 31 * result + username.hashCode()
result = 31 * result + password.contentHashCode()
result = 31 * result + owner.hashCode()
result = 31 * result + zVersion.hashCode()
result = 31 * result + mode.hashCode()
return result
}
}

fun ConnectionDialogState.initEmptyUuids(crudable: Crudable): ConnectionDialogState {
Expand All @@ -79,7 +109,7 @@ fun ConnectionDialogState.initEmptyUuids(crudable: Crudable): ConnectionDialogSt

fun ConnectionConfig.toDialogState(crudable: Crudable): ConnectionDialogState {
var username = ""
var password = ""
var password = charArrayOf()
var owner = ""
try {
username = CredentialService.getUsername(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ fun validateForBlank(text: String, component: JComponent): ValidationInfo? {
* @param password new password
* @param component confirm password component
*/
fun validateForPassword(password: String, component: JPasswordField): ValidationInfo? {
return if (password != component.password.toString()) ValidationInfo("Passwords do not match", component) else null
fun validateForPassword(password: CharArray, component: JPasswordField): ValidationInfo? {
return if (!password.contentEquals(component.password)) ValidationInfo("Passwords do not match", component) else null
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class ConfigTestSpec : WithApplicationShouldSpec({
}
context("Credentials.hashCode") {
should("check hashcode for uniqueness") {
val credentials = Credentials("uuid", "username", "password")
val credentials2 = Credentials("uuid", "username", "password")
val credentials = Credentials("uuid", "username", "password".toCharArray())
val credentials2 = Credentials("uuid", "username", "password".toCharArray())
val hashcode = credentials.hashCode()
val hashcode2 = credentials2.hashCode()

Expand Down
Loading

0 comments on commit cfda6e6

Please sign in to comment.