Skip to content

Commit

Permalink
Add pre-commit hooks (#126)
Browse files Browse the repository at this point in the history
* Add pre-commit github action
* Add spotless config
* Change line endings to unix
  • Loading branch information
sboardwell authored Jan 16, 2024
1 parent 9c51c7b commit ddb90c1
Show file tree
Hide file tree
Showing 32 changed files with 1,546 additions and 1,492 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*.ipr
target
work
/.idea
/.classpath
/.project
/.settings
.vscode
.vscode
2 changes: 0 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@

tasks:
- init: mvn install -DskipTests=false


18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
- id: check-executables-have-shebangs
- repo: https://github.com/gherynos/pre-commit-java
rev: v0.2.14
hooks:
- id: cpd
exclude: /test/
- id: checkstyle
exclude: /test/
args: ["-c", "/google_checks.xml"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When it comes to authorisation, the offers two options to developers: HTTP heade
1. Header User Name: X-Forwarded-User
2. Header Groups Name: X-Forwarded-Groups
3. Header Groups Delimiter: |

The LDAP options can be displayed via the Advanced... button, located on the right side of the security settings.

If no LDAP information is given, the default used will be the HEADER fields. However, if both are configured, the LDAP has priority over the HTTP header.
Expand All @@ -18,7 +18,7 @@ If the username is not forwarded to Jenkins, the user will be authenticated as A

However, once the LDAP is properly configured instead of groups on the HTTP header, there is guarantee that only the groups of a given user will be returned. There is no possibility to get groups injected via the header.

See the fields in [ReverseProxySecurityRealm.java](https://github.com/jenkinsci/reverse-proxy-auth-plugin/blob/master/src/main/java/org/jenkinsci/plugins/reverse_proxy_auth/ReverseProxySecurityRealm.java) for details about the available options.
See the fields in [ReverseProxySecurityRealm.java](https://github.com/jenkinsci/reverse-proxy-auth-plugin/blob/master/src/main/java/org/jenkinsci/plugins/reverse_proxy_auth/ReverseProxySecurityRealm.java) for details about the available options.

## Alternative authentication: API Token
An other possibility to authenticate is to the use an HTTP Basic authentication with the Jenkins API Token.
Expand Down Expand Up @@ -59,7 +59,7 @@ The default values for the HTTP header fields are:
ProxyRequests Off
AllowEncodedSlashes NoDecode
Timeout 5400
ProxyTimeout 5400
ProxyTimeout 5400

<Proxy "*">
Order deny,allow
Expand All @@ -68,7 +68,7 @@ The default values for the HTTP header fields are:
AuthName "Please sign in with your Apache user name and password"
# file created with htpasswd
AuthUserFile /usr/local/apache2/conf/passwd
Require valid-user
Require valid-user

# Remove these header before to set the right value after, it prevent the client from setting this header
RequestHeader unset "X-Forwarded-User"
Expand All @@ -78,7 +78,7 @@ The default values for the HTTP header fields are:

# Adds the X-Forwarded-User header that indicates the current user name.
# this portion came from http://old.nabble.com/Forcing-a-proxied-host-to-generate-REMOTE_USER-td2911573.html#a2914465
RewriteEngine On
RewriteEngine On

# User to use to login in Jenkins
RequestHeader set "X-Forwarded-User" "%{RU}e"
Expand Down Expand Up @@ -270,7 +270,7 @@ Compatibility with [JEP-227](https://jenkins.io/jep/227). Should be no functiona
### Version 1.6.0 (2018 January 29)

- ![(error)](https://wiki.jenkins.io/s/en_GB/8100/5084f018d64a97dc638ca9a178856f851ea353ff/_/images/icons/emoticons/error.svg) [JENKINS-22402](https://issues.jenkins-ci.org/browse/JENKINS-22402)/[JENKINS-48970](https://issues.jenkins-ci.org/browse/JENKINS-48970) -
Stop storing authentication context and caches on the disk
Stop storing authentication context and caches on the disk
- The change also fixes compatibility with JEP-200 in Jenkins
2.102+
- More info: [Plugins affected by fix for
Expand All @@ -288,15 +288,15 @@ Compatibility with [JEP-227](https://jenkins.io/jep/227). Should be no functiona

- [![(plus)](https://wiki.jenkins.io/s/en_GB/8100/5084f018d64a97dc638ca9a178856f851ea353ff/_/images/icons/emoticons/add.svg) PR
\#25](https://github.com/jenkinsci/reverse-proxy-auth-plugin/pull/25) -
Add support of custom log output redirect
Add support of custom log output redirect

- [![(plus)](https://wiki.jenkins.io/s/en_GB/8100/5084f018d64a97dc638ca9a178856f851ea353ff/_/images/icons/emoticons/add.svg) PR
\#26](https://github.com/jenkinsci/reverse-proxy-auth-plugin/pull/26) -
Add support of custom login URL
Add support of custom login URL

- [![(info)](https://wiki.jenkins.io/s/en_GB/8100/5084f018d64a97dc638ca9a178856f851ea353ff/_/images/icons/emoticons/information.svg) PR
\#33](https://github.com/jenkinsci/reverse-proxy-auth-plugin/pull/33) -
Plugin now requires Jenkins core 1.625.3 or above
Plugin now requires Jenkins core 1.625.3 or above

### Version 1.5 (2016 January 22)

Expand Down
195 changes: 113 additions & 82 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -10,14 +11,6 @@
<artifactId>reverse-proxy-auth-plugin</artifactId>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<properties>
<revision>1.7.8</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/reverse-proxy-auth-plugin</gitHubRepo>
<jenkins.version>2.387.3</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.failOnError>true</spotbugs.failOnError>
</properties>

<name>Jenkins Reverse Proxy Auth Plugin</name>
<url>https://github.com/jenkinsci/reverse-proxy-auth-plugin</url>
Expand Down Expand Up @@ -46,80 +39,91 @@
<scm>
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
<url>https://github.com/${gitHubRepo}</url>
</scm>
<properties>
<revision>1.7.8</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/reverse-proxy-auth-plugin</gitHubRepo>
<jenkins.version>2.387.3</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.failOnError>true</spotbugs.failOnError>
<spotless.check.skip>false</spotless.check.skip>
</properties>

<dependencies>
<dependency> <!-- to appear earlier in the test CP for purposes of PCT -->
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-core</artifactId>
<version>${jenkins.version}</version>
</dependency>
<dependency> <!-- for compatibility with https://github.com/jenkinsci/jenkins/pull/4848 -->
<groupId>org.acegisecurity</groupId>
<artifactId>acegi-security</artifactId>
<version>1.0.7</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-remoting</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-support</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-dao</artifactId>
<version>2.0.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>457.v3f72cb_e015e5</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<!-- to appear earlier in the test CP for purposes of PCT -->
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-core</artifactId>
<version>${jenkins.version}</version>
</dependency>
<dependency>
<!-- for compatibility with https://github.com/jenkinsci/jenkins/pull/4848 -->
<groupId>org.acegisecurity</groupId>
<artifactId>acegi-security</artifactId>
<version>1.0.7</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-remoting</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-support</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-dao</artifactId>
<version>2.0.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>457.v3f72cb_e015e5</version>
</dependency>
</dependencies>

<repositories>
<repository>
Expand All @@ -130,8 +134,35 @@

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<configuration>
<pom>
<sortPom>
<sortDependencies>scope</sortDependencies>
</sortPom>
</pom>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.util.logging.Level;
import java.util.logging.Logger;

import org.acegisecurity.ldap.InitialDirContextFactory;
import org.acegisecurity.userdetails.ldap.LdapUserDetails;

Expand All @@ -35,9 +34,7 @@
* @author Kohsuke Kawaguchi
*/
public class BindAuthenticator2 extends BindAuthenticator {
/**
* If we ever had a successful authentication,
*/
/** If we ever had a successful authentication, */
private boolean hadSuccessfulAuthentication;

public BindAuthenticator2(InitialDirContextFactory initialDirContextFactory) {
Expand All @@ -53,10 +50,12 @@ public LdapUserDetails authenticate(String username, String password) {

@Override
void handleBindException(String userDn, String username, Throwable cause) {
LOGGER.log(hadSuccessfulAuthentication? Level.FINE : Level.WARNING,
"Failed to bind to LDAP: userDn"+userDn+" username="+username,cause);
LOGGER.log(
hadSuccessfulAuthentication ? Level.FINE : Level.WARNING,

Check warning on line 54 in src/main/java/org/acegisecurity/providers/ldap/authenticator/BindAuthenticator2.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 53-54 are not covered by tests
"Failed to bind to LDAP: userDn" + userDn + " username=" + username,
cause);
super.handleBindException(userDn, username, cause);
}

private static final Logger LOGGER = Logger.getLogger(BindAuthenticator2.class.getName());
}
}
Loading

0 comments on commit ddb90c1

Please sign in to comment.