1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.core.auth 21 22 import org.make.core.operation.OperationId 23 24 import java.time.ZonedDateTime 25 import org.make.core.{DateHelper, Timestamped} 26 import org.make.core.question.QuestionId 27 import org.make.core.user.{OidcInfo, Role, User, UserId} 28 29 final case class Token( 30 accessToken: String, 31 refreshToken: Option[String], 32 scope: Option[String], 33 expiresIn: Int, 34 refreshExpiresIn: Int, 35 user: UserRights, 36 client: Client, 37 override val createdAt: Option[ZonedDateTime] = None, 38 override val updatedAt: Option[ZonedDateTime] = None 39 ) extends Timestamped { 40 41 def isAccessTokenExpired: Boolean = { 42 isExpiredAfter(expiresIn) 43 } 44 def isRefreshTokenExpired: Boolean = { 45 isExpiredAfter(refreshExpiresIn) 46 } 47 48 private def isExpiredAfter(interval: Int) = { 49 createdAt.forall { date => 50 date.plusSeconds(interval).isBefore(DateHelper.now()) 51 } 52 } 53 } 54 55 final case class UserRights( 56 userId: UserId, 57 roles: Seq[Role], 58 availableQuestions: Seq[QuestionId], 59 emailVerified: Boolean, 60 oidcInfos: Option[Map[OperationId, OidcInfo]] = None 61 ) 62 63 object UserRights { 64 def fromUser(user: User): UserRights = { 65 UserRights(user.userId, user.roles, user.availableQuestions, user.emailVerified, user.profile.flatMap(_.oidcInfos)) 66 } 67 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 42 | 4622 | 1359 - 1384 | Apply | org.make.core.auth.Token.isExpiredAfter | Token.this.isExpiredAfter(Token.this.expiresIn) | |
| 42 | 1181 | 1374 - 1383 | Select | org.make.core.auth.Token.expiresIn | Token.this.expiresIn | |
| 45 | 564 | 1434 - 1466 | Apply | org.make.core.auth.Token.isExpiredAfter | Token.this.isExpiredAfter(Token.this.refreshExpiresIn) | |
| 45 | 2560 | 1449 - 1465 | Select | org.make.core.auth.Token.refreshExpiresIn | Token.this.refreshExpiresIn | |
| 49 | 4201 | 1524 - 1616 | Apply | scala.Option.forall | Token.this.createdAt.forall(((date: java.time.ZonedDateTime) => date.plusSeconds(interval.toLong).isBefore(org.make.core.DateHelper.now()))) | |
| 50 | 2838 | 1593 - 1609 | Apply | org.make.core.DefaultDateHelper.now | org.make.core.DateHelper.now() | |
| 50 | 876 | 1557 - 1610 | Apply | java.time.chrono.ChronoZonedDateTime.isBefore | date.plusSeconds(interval.toLong).isBefore(org.make.core.DateHelper.now()) | |
| 50 | 3813 | 1574 - 1582 | Select | scala.Int.toLong | interval.toLong | |
| 65 | 3824 | 1962 - 1995 | Apply | scala.Option.flatMap | user.profile.flatMap[Map[org.make.core.operation.OperationId,org.make.core.user.OidcInfo]](((x$1: org.make.core.profile.Profile) => x$1.oidcInfos)) | |
| 65 | 2146 | 1892 - 1903 | Select | org.make.core.user.User.userId | user.userId | |
| 65 | 2508 | 1942 - 1960 | Select | org.make.core.user.User.emailVerified | user.emailVerified | |
| 65 | 4666 | 1917 - 1940 | Select | org.make.core.user.User.availableQuestions | user.availableQuestions | |
| 65 | 575 | 1983 - 1994 | Select | org.make.core.profile.Profile.oidcInfos | x$1.oidcInfos | |
| 65 | 2767 | 1881 - 1996 | Apply | org.make.core.auth.UserRights.apply | UserRights.apply(user.userId, user.roles, user.availableQuestions, user.emailVerified, user.profile.flatMap[Map[org.make.core.operation.OperationId,org.make.core.user.OidcInfo]](((x$1: org.make.core.profile.Profile) => x$1.oidcInfos))) | |
| 65 | 5461 | 1905 - 1915 | Select | org.make.core.user.User.roles | user.roles |