simplify groovy expressions
This commit is contained in:
parent
a3bce43d01
commit
c12829cd83
|
|
@ -7,35 +7,36 @@ import org.sonatype.nexus.ldap.persist.LdapConfigurationManager
|
|||
import org.sonatype.nexus.ldap.persist.entity.Connection
|
||||
import org.sonatype.nexus.ldap.persist.entity.LdapConfiguration
|
||||
import org.sonatype.nexus.ldap.persist.entity.Mapping
|
||||
import org.sonatype.nexus.security.user.UserSearchCriteria
|
||||
|
||||
ldapManager = container.lookup(LdapConfigurationManager.class.name)
|
||||
|
||||
if (!ldapManager.listLdapServerConfigurations().any { it.name == "dc.example.com" }) {
|
||||
ldapManager.addLdapServerConfiguration(
|
||||
new LdapConfiguration(
|
||||
name: 'dc.example.com',
|
||||
connection: new Connection(
|
||||
host: new Connection.Host(Connection.Protocol.ldaps, 'dc.example.com', 636),
|
||||
connectionTimeout: 30,
|
||||
connectionRetryDelay: 300,
|
||||
maxIncidentsCount: 3,
|
||||
searchBase: 'dc=example,dc=com',
|
||||
authScheme: 'simple',
|
||||
systemUsername: 'jane.doe@example.com',
|
||||
systemPassword: 'HeyH0Password',
|
||||
),
|
||||
mapping: new Mapping(
|
||||
userBaseDn: 'cn=users',
|
||||
userObjectClass: 'user',
|
||||
ldapFilter: '(&(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))',
|
||||
userIdAttribute: 'sAMAccountName',
|
||||
userRealNameAttribute: 'cn',
|
||||
emailAddressAttribute: 'mail',
|
||||
userPasswordAttribute: '',
|
||||
ldapGroupsAsRoles: true,
|
||||
userMemberOfAttribute: 'memberOf',
|
||||
)
|
||||
new LdapConfiguration(
|
||||
name: 'dc.example.com',
|
||||
connection: new Connection(
|
||||
host: new Connection.Host(Connection.Protocol.ldaps, 'dc.example.com', 636),
|
||||
connectionTimeout: 30,
|
||||
connectionRetryDelay: 300,
|
||||
maxIncidentsCount: 3,
|
||||
searchBase: 'dc=example,dc=com',
|
||||
authScheme: 'simple',
|
||||
systemUsername: 'jane.doe@example.com',
|
||||
systemPassword: 'HeyH0Password',
|
||||
),
|
||||
mapping: new Mapping(
|
||||
userBaseDn: 'cn=users',
|
||||
userObjectClass: 'user',
|
||||
ldapFilter: '(&(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))',
|
||||
userIdAttribute: 'sAMAccountName',
|
||||
userRealNameAttribute: 'cn',
|
||||
emailAddressAttribute: 'mail',
|
||||
userPasswordAttribute: '',
|
||||
ldapGroupsAsRoles: true,
|
||||
userMemberOfAttribute: 'memberOf',
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ if (!security.securitySystem.listRoles().any { it.roleId == "Administrators" &&
|
|||
|
||||
ldapUsers = security.securitySystem.searchUsers(new UserSearchCriteria(source: 'LDAP'))
|
||||
return JsonOutput.toJson([
|
||||
ldapUsers: ldapUsers.sort { it.userId },
|
||||
ldapGroups: security.securitySystem.listRoles('LDAP').sort { it.roleId },
|
||||
roles: security.securitySystem.listRoles().sort { it.roleId },
|
||||
ldapUsers: ldapUsers.sort { it.userId },
|
||||
ldapGroups: security.securitySystem.listRoles('LDAP').sort { it.roleId },
|
||||
roles: security.securitySystem.listRoles().sort { it.roleId },
|
||||
])
|
||||
|
|
|
|||
|
|
@ -55,13 +55,13 @@ jenkinsPassword = random((('A'..'Z')+('a'..'z')+('0'..'9')).join(), 16)
|
|||
|
||||
// set the base url. this is used when sending emails.
|
||||
// see https://help.sonatype.com/display/NXRM3/Configuration#Configuration-BaseURLCreation
|
||||
core.baseUrl("https://" + java.net.InetAddress.getLocalHost().getCanonicalHostName())
|
||||
core.baseUrl("https://" + java.net.InetAddress.localHost.canonicalHostName)
|
||||
|
||||
|
||||
// schedule a task to remove old snapshots from the maven-snapshots repository.
|
||||
// see https://github.com/sonatype/nexus-public/blob/555cc59e7fa659c0a1a4fbc881bf3fcef0e9a5b6/components/nexus-scheduling/src/main/java/org/sonatype/nexus/scheduling/TaskScheduler.java
|
||||
// see https://github.com/sonatype/nexus-public/blob/555cc59e7fa659c0a1a4fbc881bf3fcef0e9a5b6/plugins/nexus-coreui-plugin/src/main/java/org/sonatype/nexus/coreui/TaskComponent.groovy
|
||||
taskScheduler = (TaskScheduler)container.lookup(TaskScheduler.class.getName())
|
||||
taskScheduler = (TaskScheduler)container.lookup(TaskScheduler.class.name)
|
||||
taskConfiguration = taskScheduler.createTaskConfigurationInstance("repository.maven.remove-snapshots")
|
||||
taskConfiguration.name = "remove old snapshots from the maven-snapshots repository"
|
||||
// NB to see the available properties uncomment the tasksDescriptors property from JsonOutput.toJson at the end of this script.
|
||||
|
|
@ -73,7 +73,7 @@ taskScheduler.scheduleTask(taskConfiguration, new Daily(new Date().clearTime().n
|
|||
|
||||
|
||||
// enable the NuGet API-Key Realm.
|
||||
realmManager = container.lookup(RealmManager.class.getName())
|
||||
realmManager = container.lookup(RealmManager.class.name)
|
||||
realmManager.enableRealm("NuGetApiKey")
|
||||
|
||||
// enable the npm Bearer Token Realm.
|
||||
|
|
@ -86,7 +86,7 @@ def getOrCreateNuGetApiKey(String userName) {
|
|||
realmName = "NexusAuthenticatingRealm"
|
||||
apiKeyDomain = "NuGetApiKey"
|
||||
principal = new SimplePrincipalCollection(userName, realmName)
|
||||
keyStore = container.lookup(ApiKeyStore.class.getName())
|
||||
keyStore = container.lookup(ApiKeyStore.class.name)
|
||||
apiKey = keyStore.getApiKey(apiKeyDomain, principal)
|
||||
if (apiKey == null) {
|
||||
apiKey = keyStore.createApiKey(apiKeyDomain, principal)
|
||||
|
|
@ -98,7 +98,7 @@ def getOrCreateNuGetApiKey(String userName) {
|
|||
// create users in the deployer role.
|
||||
// see https://github.com/sonatype/nexus-book-examples/blob/nexus-3.x/scripting/complex-script/security.groovy#L38
|
||||
def addDeployerUser(firstName, lastName, email, userName, password) {
|
||||
if (!security.securitySystem.listRoles().any { it.getRoleId() == "deployer" }) {
|
||||
if (!security.securitySystem.listRoles().any { it.roleId == "deployer" }) {
|
||||
privileges = [
|
||||
"nx-search-read",
|
||||
"nx-repository-view-*-*-read",
|
||||
|
|
@ -123,7 +123,7 @@ addDeployerUser("Bob", "Doe", "bob.doe@example.com", "bob.doe", "password")
|
|||
// get the jenkins NuGet API Key.
|
||||
jenkinsNuGetApiKey = getOrCreateNuGetApiKey("jenkins")
|
||||
|
||||
realms = realmManager.getConfiguration().getRealmNames()
|
||||
realms = realmManager.configuration.realmNames
|
||||
users = security.securitySystem.searchUsers(new UserSearchCriteria())
|
||||
repositories = repository.repositoryManager.browse().collect { [name:it.name,type:it.type.value] }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue