diff --git a/obp-api/src/main/resources/props/sample.props.template b/obp-api/src/main/resources/props/sample.props.template index ab5704f77..99c146057 100644 --- a/obp-api/src/main/resources/props/sample.props.template +++ b/obp-api/src/main/resources/props/sample.props.template @@ -1212,7 +1212,7 @@ user_account_is_validated = false retain_archive_metrics_days = 1095 # Defines the number of days we keep rows in the table "Metric" former "MappedMetric" -retain_metrics_days = 60 +retain_metrics_days = 200 #if same session used for different ip address, we can show this warning, default is false. show_ip_address_change_warning=false \ No newline at end of file diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index e3e374577..906d226de 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -1,5 +1,6 @@ package code.api.v3_1_0 +import code.api.Constant import code.api.Constant.localIdentityProvider import java.text.SimpleDateFormat @@ -513,7 +514,10 @@ trait APIMethods310 { for { (Full(u), callContext) <- authenticatedAccess(cc) _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadUserLockedStatus, callContext) - badLoginStatus <- Future { LoginAttempt.getBadLoginStatus(localIdentityProvider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername($username)", 404) } + _ <- Users.users.vend.getUserByProviderAndUsernameFuture(Constant.localIdentityProvider, username) map { + x => unboxFullOrFail(x, callContext, UserNotFoundByProviderAndUsername, 404) + } + badLoginStatus <- Future { LoginAttempt.getOrCreateBadLoginStatus(localIdentityProvider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername($username)", 404) } } yield { (createBadLoginStatusJson(badLoginStatus), HttpCode.`200`(callContext)) } @@ -547,10 +551,13 @@ trait APIMethods310 { cc => for { (Full(u), callContext) <- authenticatedAccess(cc) + user <- Users.users.vend.getUserByProviderAndUsernameFuture(Constant.localIdentityProvider, username) map { + x => unboxFullOrFail(x, callContext, UserNotFoundByProviderAndUsername, 404) + } _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canUnlockUser, callContext) _ <- Future { LoginAttempt.resetBadLoginAttempts(localIdentityProvider,username) } _ <- Future { UserLocksProvider.unlockUser(localIdentityProvider,username) } - badLoginStatus <- Future { LoginAttempt.getBadLoginStatus(localIdentityProvider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername($username)", 404) } + badLoginStatus <- Future { LoginAttempt.getOrCreateBadLoginStatus(localIdentityProvider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername($username)", 404) } } yield { (createBadLoginStatusJson(badLoginStatus), HttpCode.`200`(callContext)) } diff --git a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala index 552a562ba..d076d4cc1 100644 --- a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala +++ b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala @@ -265,8 +265,11 @@ trait APIMethods510 { for { (Full(u), callContext) <- SS.user _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadUserLockedStatus, callContext) + _ <- Users.users.vend.getUserByProviderAndUsernameFuture(provider, username) map { + x => unboxFullOrFail(x, callContext, UserNotFoundByProviderAndUsername, 404) + } badLoginStatus <- Future { - LoginAttempt.getBadLoginStatus(provider, username) + LoginAttempt.getOrCreateBadLoginStatus(provider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername provider($provider), username($username)", 404) } @@ -303,6 +306,9 @@ trait APIMethods510 { for { (Full(u), callContext) <- SS.user _ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canUnlockUser, callContext) + _ <- Users.users.vend.getUserByProviderAndUsernameFuture(provider, username) map { + x => unboxFullOrFail(x, callContext, UserNotFoundByProviderAndUsername, 404) + } _ <- Future { LoginAttempt.resetBadLoginAttempts(provider, username) } @@ -310,7 +316,7 @@ trait APIMethods510 { UserLocksProvider.unlockUser(provider, username) } badLoginStatus <- Future { - LoginAttempt.getBadLoginStatus(provider, username) + LoginAttempt.getOrCreateBadLoginStatus(provider, username) } map { unboxFullOrFail(_, callContext, s"$UserNotFoundByProviderAndUsername provider($provider), username($username)", 404) } diff --git a/obp-api/src/main/scala/code/loginattempts/LoginAttempts.scala b/obp-api/src/main/scala/code/loginattempts/LoginAttempts.scala index d96fdf711..52f9dc833 100644 --- a/obp-api/src/main/scala/code/loginattempts/LoginAttempts.scala +++ b/obp-api/src/main/scala/code/loginattempts/LoginAttempts.scala @@ -47,11 +47,17 @@ object LoginAttempt extends MdcLoggable { } } - def getBadLoginStatus(provider: String, username: String): Box[BadLoginAttempt] = { + def getOrCreateBadLoginStatus(provider: String, username: String): Box[BadLoginAttempt] = { MappedBadLoginAttempt.find( By(MappedBadLoginAttempt.Provider, provider), By(MappedBadLoginAttempt.mUsername, username) - ) + ).or(Full(MappedBadLoginAttempt.create + .mUsername(username) + .Provider(provider) + .mLastFailureDate(now) + .mBadAttemptsSinceLastSuccessOrReset(0) + .saveMe() + )) } /** diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index 03e178601..21a4ef904 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -472,7 +472,9 @@ import net.liftweb.util.Helpers._ resourceUser <- if (AuthUser.currentUser.isDefined){ //AuthUser.currentUser.get.user.foreign // this will be issue when the resource user is in remote side { val user = AuthUser.currentUser.openOrThrowException(ErrorMessages.attemptedToOpenAnEmptyBox) - Users.users.vend.getUserByUserName(user.provider.get, user.username.get) + // In case that the provider is empty field we default to "local_identity_provider" or "hostname" + val provider = if(user.provider.get.isEmpty) Constant.localIdentityProvider else user.provider.get + Users.users.vend.getUserByUserName(provider, user.username.get) }else if (directLogin.isDefined) // Direct Login DirectLogin.getUser else if (hasDirectLoginHeader(authorization)) // Direct Login Deprecated diff --git a/obp-api/src/main/scala/code/scheduler/MetricsArchiveScheduler.scala b/obp-api/src/main/scala/code/scheduler/MetricsArchiveScheduler.scala index dce229e91..00b6f5ef3 100644 --- a/obp-api/src/main/scala/code/scheduler/MetricsArchiveScheduler.scala +++ b/obp-api/src/main/scala/code/scheduler/MetricsArchiveScheduler.scala @@ -47,18 +47,18 @@ object MetricsArchiveScheduler extends MdcLoggable { def conditionalDeleteMetricsRow() = { val currentTime = new Date() - val days = APIUtil.getPropsAsLongValue("retain_metrics_days", 60) match { + val days = APIUtil.getPropsAsLongValue("retain_metrics_days", 200) match { case days if days > 59 => days case _ => 60 } val someDaysAgo: Date = new Date(currentTime.getTime - (oneDayInMillis * days)) // Get the data from the table "Metric" older than specified by retain_metrics_days - val canditateMetricRowsToMove = APIMetrics.apiMetrics.vend.getAllMetrics(List(OBPToDate(someDaysAgo))) - canditateMetricRowsToMove map { i => + val candidateMetricRowsToMove = APIMetrics.apiMetrics.vend.getAllMetrics(List(OBPToDate(someDaysAgo))) + candidateMetricRowsToMove map { i => // and copy it to the table "MetricsArchive" copyRowToMetricsArchive(i) } - val maybeDeletedRows: List[(Boolean, Long)] = canditateMetricRowsToMove map { i => + val maybeDeletedRows: List[(Boolean, Long)] = candidateMetricRowsToMove map { i => // and delete it after successful coping MetricArchive.find(By(MetricArchive.metricId, i.getMetricId())) match { case Full(_) => (MappedMetric.bulkDelete_!!(By(MappedMetric.id, i.getMetricId())), i.getMetricId()) diff --git a/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala b/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala index 094f023e1..961a8ab0e 100644 --- a/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala +++ b/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala @@ -410,6 +410,7 @@ class ConsumerRegistration extends MdcLoggable { s"App name: ${registered.name.get} \n" + s"App type: ${registered.appType.get} \n" + s"App description: ${registered.description.get} \n" + + s"App Redirect Url : ${registered.redirectURL} \n" + s"Consumer Key: ${consumerKeyOrMessage} \n" + s"Consumer Secret : ${consumerSecretOrMessage} \n" + s"OAuth Endpoint: ${oauthEndpointUrl} \n" + @@ -454,7 +455,8 @@ class ConsumerRegistration extends MdcLoggable { s"Email: ${registered.developerEmail.get} \n" + s"App name: ${registered.name.get} \n" + s"App type: ${registered.appType.get} \n" + - s"App description: ${registered.description.get}" + s"App description: ${registered.description.get} \n" + + s"App Redirect Url : ${registered.redirectURL}" //technically doesn't work for all valid email addresses so this will mess up if someone tries to send emails to "foo,bar"@example.com val to = toAddressesString.split(",").toList