Skip to content

Commit

Permalink
SAK-45364 rubrics: Update Joda-time => java.time (sakaiproject#9183)
Browse files Browse the repository at this point in the history
  • Loading branch information
axxter99 authored Apr 20, 2021
1 parent 6a49ca2 commit 213aee8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 0 additions & 5 deletions rubrics/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
<artifactId>java-jwt</artifactId>
<version>${sakai.java.jwt.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -47,7 +49,6 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.joda.time.DateTime;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.FunctionManager;
import org.sakaiproject.authz.api.SecurityService;
Expand Down Expand Up @@ -95,6 +96,7 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -192,22 +194,22 @@ public String generateJsonWebToken(String tool, String siteId) {
String userId = sessionManager.getCurrentSessionUserId();

try {
DateTime now = DateTime.now();
Instant now = Instant.now();

JWTCreator.Builder jwtBuilder = JWT.create();
jwtBuilder.withIssuer(JWT_ISSUER)
.withAudience(JWT_AUDIENCE)
.withSubject(userId)
.withClaim(JWT_CUSTOM_CLAIM_TOOL_ID, tool)
.withClaim(JWT_CUSTOM_CLAIM_SESSION_ID, sessionManager.getCurrentSession().getId())
.withIssuedAt(now.toDate());
.withIssuedAt(Date.from(now));
int sessionTimeoutInSeconds = sessionManager.getCurrentSession().getMaxInactiveInterval();
if (sessionTimeoutInSeconds > 0) {
jwtBuilder.withExpiresAt(now.plusSeconds(sessionTimeoutInSeconds).toDate());
jwtBuilder.withExpiresAt(Date.from(now.plusSeconds(sessionTimeoutInSeconds)));
} else {
// if Sakai is configured for sessions to never timeout (negative value), we will set 30 minutes for
// tokens - the rubrics service will check Sakai session validity if it receives an expired token.
jwtBuilder.withExpiresAt(now.plusMinutes(30).toDate());
jwtBuilder.withExpiresAt(Date.from(now.plusSeconds(30*60)));
}

if (securityService.isSuperUser()) {
Expand Down

0 comments on commit 213aee8

Please sign in to comment.