Skip to content

Commit

Permalink
Merge pull request #53 from AndyHWChung/AIV-262-log-payload
Browse files Browse the repository at this point in the history
AIV-262 - made logging userinfo response payload configurable
  • Loading branch information
peteanning authored Sep 28, 2018
2 parents 6c572f4 + 96f749f commit e90f61c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ object UserInfoFeatureSwitches {
def allSwitches: Seq[FeatureSwitch] = Seq(countryCode, addressLine5)

}

object LoggingSwitches {

lazy val logUserInfoResponsePayload: FeatureSwitch = FeatureSwitch.forName("log-userinfo-response-payload")

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ package uk.gov.hmrc.openidconnect.userinfo.controllers
* limitations under the License.
*/

import play.api.Logger
import play.api.libs.json.Json
import uk.gov.hmrc.api.controllers.HeaderValidator
import uk.gov.hmrc.http.{BadRequestException, Upstream4xxResponse, Upstream5xxResponse}
import uk.gov.hmrc.openidconnect.userinfo.config.LoggingSwitches.logUserInfoResponsePayload
import uk.gov.hmrc.openidconnect.userinfo.services.{LiveUserInfoService, SandboxUserInfoService, UserInfoService}
import uk.gov.hmrc.play.microservice.controller.BaseController

Expand All @@ -43,9 +45,17 @@ import scala.concurrent.ExecutionContext.Implicits.global
trait UserInfoController extends BaseController with HeaderValidator {
val service: UserInfoService

val responseLogger = Logger("userinfo-response-payload-logger")

final def userInfo() = validateAccept(acceptHeaderValidationRules).async { implicit request =>
service.fetchUserInfo() map { userInfo =>
Ok(Json.toJson(userInfo))
val json = Json.toJson(userInfo)

if(logUserInfoResponsePayload.isEnabled){
responseLogger.debug(s"Returning userinfo payload: $json")
}

Ok(json)
} recover {
case Upstream4xxResponse(msg, 401, _, _) => Unauthorized(Json.toJson(ErrorUnauthorized()))
case Upstream4xxResponse(msg4xx, _, _ , _) => BadGateway(Json.toJson(ErrorBadGateway(msg4xx)))
Expand Down
2 changes: 2 additions & 0 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

<logger name="application" level="DEBUG"/>

<logger name="userinfo-response-payload-logger" level="DEBUG"/>

<logger name="connector" level="TRACE">
<appender-ref ref="STDOUT"/>
</logger>
Expand Down

0 comments on commit e90f61c

Please sign in to comment.