Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from kwhetstone/master
[JENKINS-36499] Update to the new Parent POM
  • Loading branch information
stephenc committed Oct 5, 2016
2 parents 37ec8d0 + 4c429ee commit bc0db50
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 217 deletions.
43 changes: 6 additions & 37 deletions pom.xml
Expand Up @@ -5,17 +5,18 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.1</version>
<version>2.15</version>
</parent>

<artifactId>openid</artifactId>
<version>2.2-SNAPSHOT</version>
<packaging>hpi</packaging>

<properties>
<findbugs-maven-plugin.version>3.0.1</findbugs-maven-plugin.version>
<!--TODO: Enforce when the code becomes 100% clean-->
<findbugs.failOnError>false</findbugs.failOnError>
<jenkins.version>1.609.3</jenkins.version>
<java.level>6</java.level>
<concurrency>1</concurrency>
</properties>

Expand Down Expand Up @@ -45,13 +46,13 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand All @@ -66,38 +67,6 @@
<artifactId>mailer</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs-maven-plugin.version}</version>
<configuration>
<failOnError>${findbugs.failOnError}</failOnError>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>run-findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
</project>
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/openid/OpenIdExtension.java
Expand Up @@ -107,11 +107,13 @@ public static ExtensionList<OpenIdExtension> all() {
*
* @param authRequest the authentication request.
* @throws MessageException if there is a message error extending the request
* @throws IllegalStateException if there is no Jenkins instance
*/
public static void extendRequest(AuthRequest authRequest) throws MessageException {
FetchRequest request = FetchRequest.createFetchRequest();
SecurityRealm sr = Jenkins.getActiveInstance().getSecurityRealm();
for (OpenIdExtension e : all()) {
if (e.isApplicable(Jenkins.getInstance().getSecurityRealm())) {
if (e.isApplicable(sr)) {
e.extend(authRequest);
e.extendFetch(request);
}
Expand All @@ -127,10 +129,12 @@ public static void extendRequest(AuthRequest authRequest) throws MessageExceptio
* @param authSuccess the authentication success.
* @param id the identity.
* @throws MessageException if there is a message error processing the success.
* @throws IllegalStateException if there is no Jenkins instance
*/
public static void processResponse(AuthSuccess authSuccess, Identity id) throws MessageException {
SecurityRealm sc = Jenkins.getActiveInstance().getSecurityRealm();
for (OpenIdExtension e : all()) {
if (e.isApplicable(Jenkins.getInstance().getSecurityRealm())) {
if (e.isApplicable(sc)) {
e.process(authSuccess, id);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/openid/OpenIdSession.java
Expand Up @@ -25,6 +25,7 @@

import com.cloudbees.openid4java.team.TeamExtensionFactory;
import com.cloudbees.openid4java.team.TeamExtensionRequest;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.Failure;
import hudson.model.Hudson;
import hudson.util.HttpResponses;
Expand Down Expand Up @@ -81,6 +82,7 @@ public OpenIdSession(ConsumerManager manager, String openid, String finishUrl) t
/**
* Starts the login session.
*/
@SuppressFBWarnings(value="J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION", justification="Just for this login.")
public HttpResponse doCommenceLogin() throws IOException, OpenIDException {
final AuthRequest authReq = manager.authenticate(endpoint, Hudson.getInstance().getRootUrl()+ finishUrl);

Expand Down
Expand Up @@ -165,7 +165,7 @@ public HttpResponse doCommenceLogin(@QueryParameter String from) throws IOExcept
if (Stapler.getCurrentRequest().getHeader("Referer") != null) {
from = Stapler.getCurrentRequest().getHeader("Referer");
} else {
from = Jenkins.getInstance().getRootUrl();
from = Jenkins.getActiveInstance().getRootUrl();
}
}

Expand Down
Expand Up @@ -83,7 +83,7 @@ public UserProperty newInstance(User user) {

@Override
public boolean isEnabled() {
return Jenkins.getInstance().getSecurityRealm() instanceof AbstractPasswordBasedSecurityRealm
return Jenkins.getActiveInstance().getSecurityRealm() instanceof AbstractPasswordBasedSecurityRealm
&& (openIdLoginService != null && !openIdLoginService.isDisabled());
}

Expand Down
Expand Up @@ -30,6 +30,6 @@ public String getUrlName() {

// serve static resources
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
Jenkins.getInstance().getPlugin("openid").doDynamic(req,rsp);
Jenkins.getActiveInstance().getPlugin("openid").doDynamic(req,rsp);
}
}
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<div>
<link type="text/css" rel="stylesheet" href="${resURL}/openid-assets/openid.css"/>
Expand Down
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:if test="${!it.disabled}">
<div style="padding-top:3em">
Expand Down
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<l:layout title="${%OpenID Successfully Associated}">
<l:main-panel>
Expand Down
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%OpenIDs}">
<ul>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/index.jelly
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This plugin enables user authentication via OpenID.
</div>
Expand Up @@ -32,21 +32,28 @@
import hudson.plugins.openid.OpenIdTestService.IdProperty;
import hudson.tasks.Mailer;
import hudson.tasks.Mailer.UserProperty;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;

import java.io.IOException;
import java.util.Map;

import static hudson.plugins.openid.OpenIdTestService.*;
import static org.junit.Assert.*;

/**
* @author Nirmal Jonnalagedda
*/
public class OpenIdAXEmailAttributesTest extends OpenIdTestCase {

void _testEmailAttributes(String userName) throws Exception {
WebClient wc = new WebClient();
WebClient wc = jr.createWebClient();

OpenIdSsoSecurityRealm realm = new OpenIdSsoSecurityRealm(openid.url);
hudson.setSecurityRealm(realm);
OpenIdSsoSecurityRealm realm = new OpenIdSsoSecurityRealm(jr.openid.url);
jr.jenkins.setSecurityRealm(realm);

HtmlPage top = wc.goTo("");
top = top.getAnchorByText("log in").click();
Expand All @@ -56,61 +63,66 @@ void _testEmailAttributes(String userName) throws Exception {

assertTrue(up.hasExplicitlyConfiguredAddress());

if (openid.props.get(IdProperty.email) != null)
assertEquals(up.getAddress(), openid.props.get(IdProperty.email));
else if (openid.props.get(IdProperty.email2) != null)
assertEquals(up.getAddress(), openid.props.get(IdProperty.email2));
if (jr.openid.props.get(IdProperty.email) != null)
assertEquals(up.getAddress(), jr.openid.props.get(IdProperty.email));
else if (jr.openid.props.get(IdProperty.email2) != null)
assertEquals(up.getAddress(), jr.openid.props.get(IdProperty.email2));
else
assertEquals(up.getAddress(), openid.props.get(IdProperty.email3));
assertEquals(up.getAddress(), jr.openid.props.get(IdProperty.email3));
}

@Test
public void testEmailWithAXExtensionWithAllSameEmailAttributes() throws Exception {
openid = new OpenIdTestService(
getServiceUrl(),
jr.openid = new OpenIdTestService(
jr.getServiceUrl(),
getPropsAllSameEmails(),
Sets.newHashSet("foo", "bar"),
Lists.newArrayList(SREG_EXTENSION, AX_EXTENSION, TEAM_EXTENSION));

_testEmailAttributes(openid.props.get(IdProperty.nick));
_testEmailAttributes(jr.openid.props.get(IdProperty.nick));
}

@Test
public void testEmailWithAXExtensionWithAllDifferentEmailAttributes() throws Exception {
openid = new OpenIdTestService(
getServiceUrl(),
jr.openid = new OpenIdTestService(
jr.getServiceUrl(),
getPropsAllDifferentEmails(),
Sets.newHashSet("foo", "bar"),
Lists.newArrayList(SREG_EXTENSION, AX_EXTENSION, TEAM_EXTENSION));

_testEmailAttributes(openid.props.get(IdProperty.nick));
_testEmailAttributes(jr.openid.props.get(IdProperty.nick));
}

@Test
public void testEmailWithAXExtensionWithAnyTwoDifferentEmailAttributes() throws Exception {
openid = new OpenIdTestService(
getServiceUrl(),
jr.openid = new OpenIdTestService(
jr.getServiceUrl(),
getPropsWithAnyTwoDifferentEmails(),
Sets.newHashSet("foo", "bar"),
Lists.newArrayList(SREG_EXTENSION, AX_EXTENSION, TEAM_EXTENSION));

_testEmailAttributes(openid.props.get(IdProperty.nick));
_testEmailAttributes(jr.openid.props.get(IdProperty.nick));
}

@Test
public void testEmailWithAXExtensionWithAnyTwoSameEmailAttributes() throws Exception {
openid = new OpenIdTestService(
getServiceUrl(),
jr.openid = new OpenIdTestService(
jr.getServiceUrl(),
getPropsWithAnyTwoSameEmails(),
Sets.newHashSet("foo", "bar"),
Lists.newArrayList(SREG_EXTENSION, AX_EXTENSION, TEAM_EXTENSION));

_testEmailAttributes(openid.props.get(IdProperty.nick));
_testEmailAttributes(jr.openid.props.get(IdProperty.nick));
}

@Test
public void testEmailWithAXExtensionWithOneEmailAttribute() throws Exception {
openid = new OpenIdTestService(
getServiceUrl(),
jr.openid = new OpenIdTestService(
jr.getServiceUrl(),
getPropsWithOneEmail(),
Sets.newHashSet("foo", "bar"),
Lists.newArrayList(SREG_EXTENSION, AX_EXTENSION, TEAM_EXTENSION));

_testEmailAttributes(openid.props.get(IdProperty.nick));
_testEmailAttributes(jr.openid.props.get(IdProperty.nick));
}
}

0 comments on commit bc0db50

Please sign in to comment.