From 9f7cdb9d95fc276411980e16158349627866e29d Mon Sep 17 00:00:00 2001 From: Bartosz Nowak <9051964+DuMaM@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:15:25 +0200 Subject: [PATCH] Feature/update pomxml (#221) * feat: update plugin deps tree * feat: remove min java 11 check * feat: improve build scripts * feat: bump docker used in casc * feat: add useful docs --- CONTRIBUTING.md | 5 + _start.sh | 14 +- _stop.sh | 2 +- casc/docker-compose.yml | 2 +- pom.xml | 96 ++++---- .../crowd/CrowdConfigurationService.java | 213 +++++------------- 6 files changed, 120 insertions(+), 212 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c936ff95..5bcf1ddc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,3 +40,8 @@ Crowd login credentials are: Application: * application: jenkins * pass: jenkins + +## Other docs + +Apart of jenkins plugin developer documentation it's recommended to also read this one. +https://docs.google.com/document/d/1PKYIpPlRVGsBqrz0Ob1Cv3cefOZ5j2xtGZdWs27kLuw/edit?usp=sharing diff --git a/_start.sh b/_start.sh index 3305c46b..37bb2d58 100755 --- a/_start.sh +++ b/_start.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x CROWD_SNAPSHOT_FILE_PATH='target/crowd2.hpi' export GITPOD_SITE="${HOSTNAME}.${GITPOD_WORKSPACE_CLUSTER_HOST}" @@ -11,21 +11,25 @@ export CROWD_BACKUP_FILE="casc/crowd_backup.xml" if [[ ! -f "$CROWD_SNAPSHOT_FILE_PATH" ]]; then echo "--- No builds found - building plugin ---" mvn -ntp clean verify +else + echo "--- Build found - using it ---" + mvn -ntp clean verify -DskipTests fi +export JAVA_VERSION="${1:-11}" + # create new img with crowd2-snapshot file installed # if there is args passed use java8 if [[ $# -gt 0 ]] || ! docker image inspect casc_jenkins:latest &> /dev/null; then echo "--- Build Docker img ---" - export JAVA_VERSION="${1:-11}" - docker-compose -f casc/docker-compose.yml build + docker compose -f casc/docker-compose.yml build fi # fetch all needed images (crowd and jenkins one) -docker-compose -f casc/docker-compose.yml pull +docker compose -f casc/docker-compose.yml pull echo '--- Start docker services ---' -docker-compose -f casc/docker-compose.yml up -d --remove-orphans +docker compose -f casc/docker-compose.yml up -d --remove-orphans # TODO: Remove those comments after confirmation that this setup is also working localy # replace crowd address to current one diff --git a/_stop.sh b/_stop.sh index baac4f90..46ca44be 100755 --- a/_stop.sh +++ b/_stop.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker-compose -f casc/docker-compose.yml down -v +docker compose -f casc/docker-compose.yml down -v diff --git a/casc/docker-compose.yml b/casc/docker-compose.yml index 051a06ec..74b74f59 100644 --- a/casc/docker-compose.yml +++ b/casc/docker-compose.yml @@ -23,7 +23,7 @@ services: - /var/run/docker.sock:/var/run/docker.sock crowd: - image: atlassian/crowd:5.1.0-jdk11 + image: atlassian/crowd:5.1.5-jdk11 container_name: crowd networks: - crowd_net diff --git a/pom.xml b/pom.xml index aeffeb64..932e6694 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -54,7 +55,7 @@ -SNAPSHOT jenkinsci/crowd2-plugin 2.387.3 - 5.1.3 + 5.1.5 false Max true @@ -75,6 +76,10 @@ repo.jenkins-ci.org https://repo.jenkins-ci.org/public/ + + maven.jenkins-ci.org + https://repo.jenkins-ci.org/releases + @@ -84,9 +89,42 @@ + + io.jenkins.plugins + commons-lang3-api + + + io.jenkins.plugins + jaxb + + + org.jenkins-ci.plugins + apache-httpcomponents-client-4-api + + + + com.google.guava + guava + + + com.google.errorprone + error_prone_annotations + + + com.google.j2objc + j2objc-annotations + + + org.checkerframework + checker-qual + + + + + com.atlassian.crowd - crowd-integration-client-rest + crowd-integration-client-common ${crowd-integration-client-rest.version} @@ -97,14 +135,6 @@ org.apache.httpcomponents httpclient-cache - @@ -114,41 +144,14 @@ com.atlassian.crowd - crowd-integration-client-common + crowd-integration-client-rest ${crowd-integration-client-rest.version} - - org.jenkins-ci.plugins - apache-httpcomponents-client-4-api - org.jenkins-ci.plugins mailer - - io.jenkins.plugins - jaxb - - - - com.google.guava - guava - - - com.google.errorprone - error_prone_annotations - - - com.google.j2objc - j2objc-annotations - - - org.checkerframework - checker-qual - - - @@ -167,26 +170,11 @@ 3.24.2 test - - - net.bytebuddy - byte-buddy - 1.14.8 - - - org.apache.commons - commons-lang3 - 3.13.0 - - io.jenkins.tools.bom bom-2.387.x diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java b/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java index cda6e6f0..a82859dc 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java @@ -65,7 +65,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.SystemUtils; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -85,15 +84,6 @@ * @since 08.09.2011 */ public class CrowdConfigurationService { - - /** - * Classloader problem with Java 11 and jaxb - * - */ - // TODO remove it if a better solutions is found without classloader hack - // @Issue("JENKINS-59301") - private static final boolean IS_MIN_JAVA_11 = SystemUtils.JAVA_VERSION_FLOAT >= 11.0f; - /** * Used for logging purposes. */ @@ -423,19 +413,14 @@ public User authenticateUser(String login, String password) throws UserNotFoundE ExpiredCredentialException, ApplicationPermissionException, InvalidAuthenticationException, OperationFailedException { LOG.log(Level.FINEST, "CrowdClient.authenticateUser()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdClient.authenticateUser(login, password); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -450,19 +435,13 @@ public User getUser(String username) throws UserNotFoundException, OperationFail LOG.log(Level.FINEST, "getUser() cache hit MISS: {0}", username); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { retval = crowdClient.getUser(username); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } // If correct object was returned save it to cache @@ -482,22 +461,15 @@ public Group getGroup(String name) throws GroupNotFoundException, OperationFaile } LOG.log(Level.FINEST, "getGroup() cache hit MISS: {0}", name); - LOG.log(Level.FINEST, "CrowdClient.getGroup()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread();; + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader();; + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { retval = crowdClient.getGroup(name); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } // If correct object was returned save it to cache @@ -511,38 +483,28 @@ public List getGroupsForNestedUser(String username, int start, int size) throws OperationFailedException, InvalidAuthenticationException, ApplicationPermissionException, UserNotFoundException { LOG.log(Level.FINEST, "CrowdClient.getGroupsForNestedUser()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdClient.getGroupsForNestedUser(username, start, size); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } public List getGroupsForUser(String username, int start, int size) throws OperationFailedException, InvalidAuthenticationException, ApplicationPermissionException, UserNotFoundException { LOG.log(Level.FINEST, "CrowdClient.getGroupsForUser()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdClient.getGroupsForUser(username, start, size); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -550,19 +512,13 @@ public boolean isUserDirectGroupMember(String username, String groupname) throws OperationFailedException, ApplicationPermissionException, InvalidAuthenticationException { LOG.log(Level.FINEST, "CrowdClient.isUserDirectGroupMember()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdClient.isUserDirectGroupMember(username, groupname); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -570,19 +526,13 @@ public boolean isUserNestedGroupMember(String username, String groupname) throws OperationFailedException, ApplicationPermissionException, InvalidAuthenticationException { LOG.log(Level.FINEST, "CrowdClient.isUserNestedGroupMember()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdClient.isUserNestedGroupMember(username, groupname); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -597,22 +547,16 @@ public void validateSSOAuthentication(String token, List list) LOG.log(Level.FINEST, "validateSSOAuthentication() cache hit MISS"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { crowdClient.validateSSOAuthentication(token, list); LOG.log(Level.FINEST, "Valid Token"); retval = true; } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } // Successful validation call means token is valid @@ -631,19 +575,13 @@ public User findUserFromSSOToken(String token) throws OperationFailedException, LOG.log(Level.FINEST, "findUserFromSSOToken() cache hit MISS"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { retval = crowdClient.findUserFromSSOToken(token); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } // If correct object was returned save it to cache @@ -656,39 +594,28 @@ public User findUserFromSSOToken(String token) throws OperationFailedException, public void shutdown() { LOG.log(Level.FINEST, "CrowdClient.shutdown()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { crowdClient.shutdown(); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } public void testConnection() throws OperationFailedException, InvalidAuthenticationException, ApplicationPermissionException { - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + LOG.log(Level.FINEST, "CrowdClient.testConnection()"); + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { crowdClient.testConnection(); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -706,19 +633,13 @@ public void logout(HttpServletRequest httpServletRequest, HttpServletResponse ht throws ApplicationPermissionException, InvalidAuthenticationException, OperationFailedException { LOG.log(Level.FINEST, "CrowdHttpAuthenticator.logout()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { crowdHttpAuthenticator.logout(httpServletRequest, httpServletResponse); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } @@ -729,38 +650,28 @@ public User authenticate(HttpServletRequest httpServletRequest, HttpServletRespo ApplicationAccessDeniedException, ExpiredCredentialException, InactiveAccountException, InvalidTokenException { LOG.log(Level.FINEST, "CrowdHttpAuthenticator.authenticate()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdHttpAuthenticator.authenticate(httpServletRequest, httpServletResponse, name, credentials); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } } public boolean isAuthenticated(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws OperationFailedException { LOG.log(Level.FINEST, "CrowdHttpAuthenticator.isAuthenticated()"); - ClassLoader orgContextClassLoader = null; - Thread currentThread = null; - if (IS_MIN_JAVA_11) { - currentThread = Thread.currentThread(); - orgContextClassLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); - } + + Thread currentThread = Thread.currentThread(); + ClassLoader orgContextClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(CrowdConfigurationService.class.getClassLoader()); try { return crowdHttpAuthenticator.checkAuthenticated(httpServletRequest, httpServletResponse).isAuthenticated(); } finally { - if (currentThread != null) { - currentThread.setContextClassLoader(orgContextClassLoader); - } + currentThread.setContextClassLoader(orgContextClassLoader); } }