Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - Inaccessibility of RealmConfiguration.getConfiguration() Method in Nexus Version >3.6 #83

Open
YaraGomezSaiz opened this issue May 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@YaraGomezSaiz
Copy link
Contributor

Description

In the newer versions of Nexus (version >3.6), the getConfiguration() method from org.sonatype.nexus.security.realm.RealmConfiguration is no longer accessible (private method). This change is causing the following error:

{
  "name" : "security_realm",
  "result" : "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype..security.internal.RealmManagerImpl$$EnhancerByGuice$$4cc466e.getConfiguration() is applicable for argument types: () values: []"
}

Why is this needed?

Change is needed to be able to use nexus-role with newer version of nexus

Additional Information

- Content length: '284'
- Content type: application/json
- Date: Wed, 08 May 2024 09:37:14 GMT
- Elapsed: 0
- JSON: 
  - name: security_realm
  - result: 'javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype..security.internal.RealmManagerImpl$$EnhancerByGuice$$4cc466e.getConfiguration() is applicable for argument types: () values: []'
- Message: 'Status code was 400 and not [200, 204]: HTTP Error 400: Bad Request'

Proposed solution

realm.groovy ( files/scripts/security/realm.groovy) script is used to enable or disable a security realm in Nexus Repository Manager.
Currently the script is retrieving the RealConfiguration object from the RealmManager before enabling or disabling the realm. However, this is not necessary for the operation and can cause an error in newer versions of Nexus, as the getConfiguration() method may not be accessible or exist in the RealmManager interface.

Existing script:

import groovy.json.JsonSlurper
import org.sonatype.nexus.security.realm.RealmManager
import org.sonatype.nexus.security.realm.RealmConfiguration

parsed_args = new JsonSlurper().parseText(args)

def realmManager = container.lookup(RealmManager.class.getName());
RealmConfiguration realmConfig = realmManager.getConfiguration()
realmManager.enableRealm(parsed_args.name, parsed_args.enabled && parsed_args.enabled.toBoolean())

The proposed solution is to remove the access to realmConfig and directly enables or disables the realm using the enableRealm method on the RealmManager object.

Proposed script:

import org.sonatype.nexus.security.realm.RealmManager

parsed_args = new JsonSlurper().parseText(args)

def realmManager = container.lookup(RealmManager.class.getName());
realmManager.enableRealm(parsed_args.name, parsed_args.enabled && parsed_args.enabled.toBoolean())```

This simplified version of the script should be compatible with more versions of Nexus, both old and new.

@YaraGomezSaiz YaraGomezSaiz added the enhancement New feature or request label May 8, 2024
@YaraGomezSaiz YaraGomezSaiz self-assigned this May 8, 2024
YaraGomezSaiz added a commit that referenced this issue May 10, 2024
…n() Method in Nexus Version >3.6 (#84)

Inaccessibility of RealmConfiguration.getConfiguration() Method in Nexus Version >3.6 (#84)
YaraGomezSaiz added a commit that referenced this issue May 10, 2024
[FEATURE-#83] - Inaccessibility of RealmConfiguration.getConfiguration() Method in Nexus Version >3.6 (#84)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant