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.Connection
|
||||||
import org.sonatype.nexus.ldap.persist.entity.LdapConfiguration
|
import org.sonatype.nexus.ldap.persist.entity.LdapConfiguration
|
||||||
import org.sonatype.nexus.ldap.persist.entity.Mapping
|
import org.sonatype.nexus.ldap.persist.entity.Mapping
|
||||||
|
import org.sonatype.nexus.security.user.UserSearchCriteria
|
||||||
|
|
||||||
ldapManager = container.lookup(LdapConfigurationManager.class.name)
|
ldapManager = container.lookup(LdapConfigurationManager.class.name)
|
||||||
|
|
||||||
if (!ldapManager.listLdapServerConfigurations().any { it.name == "dc.example.com" }) {
|
if (!ldapManager.listLdapServerConfigurations().any { it.name == "dc.example.com" }) {
|
||||||
ldapManager.addLdapServerConfiguration(
|
ldapManager.addLdapServerConfiguration(
|
||||||
new LdapConfiguration(
|
new LdapConfiguration(
|
||||||
name: 'dc.example.com',
|
name: 'dc.example.com',
|
||||||
connection: new Connection(
|
connection: new Connection(
|
||||||
host: new Connection.Host(Connection.Protocol.ldaps, 'dc.example.com', 636),
|
host: new Connection.Host(Connection.Protocol.ldaps, 'dc.example.com', 636),
|
||||||
connectionTimeout: 30,
|
connectionTimeout: 30,
|
||||||
connectionRetryDelay: 300,
|
connectionRetryDelay: 300,
|
||||||
maxIncidentsCount: 3,
|
maxIncidentsCount: 3,
|
||||||
searchBase: 'dc=example,dc=com',
|
searchBase: 'dc=example,dc=com',
|
||||||
authScheme: 'simple',
|
authScheme: 'simple',
|
||||||
systemUsername: 'jane.doe@example.com',
|
systemUsername: 'jane.doe@example.com',
|
||||||
systemPassword: 'HeyH0Password',
|
systemPassword: 'HeyH0Password',
|
||||||
),
|
),
|
||||||
mapping: new Mapping(
|
mapping: new Mapping(
|
||||||
userBaseDn: 'cn=users',
|
userBaseDn: 'cn=users',
|
||||||
userObjectClass: 'user',
|
userObjectClass: 'user',
|
||||||
ldapFilter: '(&(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))',
|
ldapFilter: '(&(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))',
|
||||||
userIdAttribute: 'sAMAccountName',
|
userIdAttribute: 'sAMAccountName',
|
||||||
userRealNameAttribute: 'cn',
|
userRealNameAttribute: 'cn',
|
||||||
emailAddressAttribute: 'mail',
|
emailAddressAttribute: 'mail',
|
||||||
userPasswordAttribute: '',
|
userPasswordAttribute: '',
|
||||||
ldapGroupsAsRoles: true,
|
ldapGroupsAsRoles: true,
|
||||||
userMemberOfAttribute: 'memberOf',
|
userMemberOfAttribute: 'memberOf',
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,7 +52,7 @@ if (!security.securitySystem.listRoles().any { it.roleId == "Administrators" &&
|
||||||
|
|
||||||
ldapUsers = security.securitySystem.searchUsers(new UserSearchCriteria(source: 'LDAP'))
|
ldapUsers = security.securitySystem.searchUsers(new UserSearchCriteria(source: 'LDAP'))
|
||||||
return JsonOutput.toJson([
|
return JsonOutput.toJson([
|
||||||
ldapUsers: ldapUsers.sort { it.userId },
|
ldapUsers: ldapUsers.sort { it.userId },
|
||||||
ldapGroups: security.securitySystem.listRoles('LDAP').sort { it.roleId },
|
ldapGroups: security.securitySystem.listRoles('LDAP').sort { it.roleId },
|
||||||
roles: security.securitySystem.listRoles().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.
|
// set the base url. this is used when sending emails.
|
||||||
// see https://help.sonatype.com/display/NXRM3/Configuration#Configuration-BaseURLCreation
|
// 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.
|
// 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/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
|
// 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 = taskScheduler.createTaskConfigurationInstance("repository.maven.remove-snapshots")
|
||||||
taskConfiguration.name = "remove old snapshots from the maven-snapshots repository"
|
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.
|
// 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.
|
// enable the NuGet API-Key Realm.
|
||||||
realmManager = container.lookup(RealmManager.class.getName())
|
realmManager = container.lookup(RealmManager.class.name)
|
||||||
realmManager.enableRealm("NuGetApiKey")
|
realmManager.enableRealm("NuGetApiKey")
|
||||||
|
|
||||||
// enable the npm Bearer Token Realm.
|
// enable the npm Bearer Token Realm.
|
||||||
|
|
@ -86,7 +86,7 @@ def getOrCreateNuGetApiKey(String userName) {
|
||||||
realmName = "NexusAuthenticatingRealm"
|
realmName = "NexusAuthenticatingRealm"
|
||||||
apiKeyDomain = "NuGetApiKey"
|
apiKeyDomain = "NuGetApiKey"
|
||||||
principal = new SimplePrincipalCollection(userName, realmName)
|
principal = new SimplePrincipalCollection(userName, realmName)
|
||||||
keyStore = container.lookup(ApiKeyStore.class.getName())
|
keyStore = container.lookup(ApiKeyStore.class.name)
|
||||||
apiKey = keyStore.getApiKey(apiKeyDomain, principal)
|
apiKey = keyStore.getApiKey(apiKeyDomain, principal)
|
||||||
if (apiKey == null) {
|
if (apiKey == null) {
|
||||||
apiKey = keyStore.createApiKey(apiKeyDomain, principal)
|
apiKey = keyStore.createApiKey(apiKeyDomain, principal)
|
||||||
|
|
@ -98,7 +98,7 @@ def getOrCreateNuGetApiKey(String userName) {
|
||||||
// create users in the deployer role.
|
// create users in the deployer role.
|
||||||
// see https://github.com/sonatype/nexus-book-examples/blob/nexus-3.x/scripting/complex-script/security.groovy#L38
|
// 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) {
|
def addDeployerUser(firstName, lastName, email, userName, password) {
|
||||||
if (!security.securitySystem.listRoles().any { it.getRoleId() == "deployer" }) {
|
if (!security.securitySystem.listRoles().any { it.roleId == "deployer" }) {
|
||||||
privileges = [
|
privileges = [
|
||||||
"nx-search-read",
|
"nx-search-read",
|
||||||
"nx-repository-view-*-*-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.
|
// get the jenkins NuGet API Key.
|
||||||
jenkinsNuGetApiKey = getOrCreateNuGetApiKey("jenkins")
|
jenkinsNuGetApiKey = getOrCreateNuGetApiKey("jenkins")
|
||||||
|
|
||||||
realms = realmManager.getConfiguration().getRealmNames()
|
realms = realmManager.configuration.realmNames
|
||||||
users = security.securitySystem.searchUsers(new UserSearchCriteria())
|
users = security.securitySystem.searchUsers(new UserSearchCriteria())
|
||||||
repositories = repository.repositoryManager.browse().collect { [name:it.name,type:it.type.value] }
|
repositories = repository.repositoryManager.browse().collect { [name:it.name,type:it.type.value] }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue