Skip to content

Commit

Permalink
Merge pull request #3 from mpassid/updateVersion5
Browse files Browse the repository at this point in the history
Update IdP version 5 support
  • Loading branch information
JarToi authored Jun 17, 2024
2 parents 7d36123 + 1c93a68 commit 90dadf5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
31 changes: 21 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ THE SOFTWARE.
<parent>
<groupId>net.shibboleth</groupId>
<artifactId>parent</artifactId>
<version>11.3.3</version>
<version>17.0.2</version>
</parent>
<groupId>fi.mpass</groupId>
<artifactId>idp-authn-impl-jwt</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<nimbusds-version>9.23</nimbusds-version>
<shib.idp.version>4.2.1</shib.idp.version>
<shib.idp.version>5.0.0</shib.idp.version>
<checkstyle.configLocation>mpassid-checkstyle.xml</checkstyle.configLocation>
<automatic.module.name>fi.mpass.authn.jwt.impl</automatic.module.name>
<opensaml.groupId>org.opensaml</opensaml.groupId>
<opensaml.version>4.2.0</opensaml.version>
<opensaml.version>5.0.0</opensaml.version>
</properties>

<repositories>
Expand Down Expand Up @@ -94,8 +94,8 @@ THE SOFTWARE.
</dependency>
<!-- Provided Dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

Expand All @@ -104,10 +104,9 @@ THE SOFTWARE.
<!-- Test Dependencies -->
<dependency>
<groupId>${opensaml.groupId}</groupId>
<artifactId>opensaml-core</artifactId>
<artifactId>opensaml-core-impl</artifactId>
<version>${opensaml.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
Expand All @@ -116,12 +115,24 @@ THE SOFTWARE.
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
<artifactId>opensaml-testing</artifactId>
<version>${opensaml.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
<artifactId>opensaml-security-impl</artifactId>
<version>${opensaml.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.shibboleth.idp</groupId>
<artifactId>idp-testing</artifactId>
<version>${shib.idp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.shibboleth.idp</groupId>
<artifactId>idp-profile-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

import javax.annotation.Nonnull;
import javax.security.auth.Subject;
//import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
Expand All @@ -44,11 +43,10 @@
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.principal.UsernamePrincipal;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.logic.ConstraintViolationException;
import net.shibboleth.shared.primitive.StringSupport;

/**
* An action that checks for incoming JWT token and produces an
Expand Down Expand Up @@ -127,7 +125,7 @@ public String getUsernameId() {
* @param username The attribute name containing the user identifier.
*/
public void setUsernameId(String username) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
ifInitializedThrowUnmodifiabledComponentException();
Constraint.isNotEmpty(username, "Username cannot be null");
usernameId = username;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/flows/authn/jwt/jwt-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<bean id="ValidateJwtTokenAuthentication"
class="fi.mpass.shibboleth.authn.impl.ValidateJwtTokenAuthentication" scope="prototype"
p:httpServletRequest-ref="shibboleth.HttpServletRequest"
p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"
p:usernameId="id">
<constructor-arg value="shared_secret" />
<constructor-arg value="jwt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.security.Principal;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.annotation.Nonnull;

import jakarta.servlet.http.HttpServletRequest;

import org.opensaml.profile.action.EventIds;
import org.springframework.mock.web.MockHttpServletRequest;
Expand All @@ -46,8 +48,9 @@
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.impl.testing.BaseAuthenticationContextTest;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.ConstraintViolationException;
import net.shibboleth.shared.primitive.NonnullSupplier;

/**
* Unit tests for {@link ValidateJwtTokenAuthentication}.
Expand Down Expand Up @@ -80,8 +83,18 @@ public class ValidateJwtTokenAuthenticationTest extends BaseAuthenticationContex
action = new ValidateJwtTokenAuthentication(sharedSecret, jwtParameterName);
action.setUsernameId(uidConfig);
Assert.assertEquals(uidConfig, action.getUsernameId());
action.setHttpServletRequest((HttpServletRequest) src.getExternalContext().getNativeRequest());

action.setHttpServletRequestSupplier(new NonnullSupplier<HttpServletRequest>() {

@Override
public MockHttpServletRequest get() {
return (MockHttpServletRequest) src.getExternalContext().getNativeRequest();
}

});

}


/**
* Runs action without attempted flow.
Expand Down Expand Up @@ -114,7 +127,15 @@ public void testInvalidSecret() throws Exception {
* Runs action without {@link HttpServletRequest}.
*/
@Test public void testMissingServlet() throws Exception {
action.setHttpServletRequest(null);
action.setHttpServletRequestSupplier(new NonnullSupplier<HttpServletRequest>() {

@Override
@Nonnull
public HttpServletRequest get() {
return null;
}

});
action.initialize();
prc.getSubcontext(AuthenticationContext.class, false).setAttemptedFlow(authenticationFlows.get(0));
final Event event = action.execute(src);
Expand Down

0 comments on commit 90dadf5

Please sign in to comment.