2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-09-05 16:55:16 +00:00
Files
vinyldns/modules/portal/app/controllers/FrontendController.scala
Paul Cleary 7777c01359 Refactor Portal Authentication (#808)
* Initial Refactor

Pulled out logic specific to auth mechanisms into separate traits.  Updated
constructors for Controllers to take new traits.

The crux of introducing pac4j is to abstract away the details of authentication.
Most of the concerns come into play with custom action building.  Abstracting
away the old OIDC code will pave the way for using pac4j OIDC

* Another refactor

The dependency injection caused issues with the old refactor.  This refactor was
proven by actually running the application.

* DRY out tests

* Fixing merge conflicts
2019-08-23 14:41:11 -04:00

93 lines
3.3 KiB
Scala

/*
* Copyright 2018 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package controllers
import actions.SecuritySupport
import javax.inject.{Inject, Singleton}
import models.{CustomLinks, Meta}
import org.slf4j.LoggerFactory
import play.api.Configuration
import play.api.mvc._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
/*
* Controller for specific pages - sends requests along to views
*/
@Singleton
class FrontendController @Inject()(
components: ControllerComponents,
configuration: Configuration,
securitySupport: SecuritySupport
) extends AbstractController(components) {
implicit lazy val customLinks: CustomLinks = CustomLinks(configuration)
implicit lazy val meta: Meta = Meta(configuration)
private val logger = LoggerFactory.getLogger(classOf[FrontendController])
private val userAction = securitySupport.frontendAction
def loginPage(): Action[AnyContent] = securitySupport.loginPage()
def noAccess(): Action[AnyContent] = securitySupport.noAccess()
def logout(): Action[AnyContent] = securitySupport.logout()
def index(): Action[AnyContent] = userAction.async { implicit request =>
val canReview = request.user.isSuper || request.user.isSupport
Future(
Ok(views.html.batchChanges
.batchChanges(request.user.userName, canReview)))
}
def viewAllGroups(): Action[AnyContent] = userAction.async { implicit request =>
Future(Ok(views.html.groups.groups(request.user.userName)))
}
def viewGroup(groupId: String): Action[AnyContent] = userAction.async { implicit request =>
logger.info(s"View group for $groupId")
Future(Ok(views.html.groups.groupDetail(request.user.userName)))
}
def viewAllZones(): Action[AnyContent] = userAction.async { implicit request =>
Future(Ok(views.html.zones.zones(request.user.userName)))
}
def viewZone(zoneId: String): Action[AnyContent] = userAction.async { implicit request =>
Future(Ok(views.html.zones.zoneDetail(request.user.userName, zoneId)))
}
def viewAllBatchChanges(): Action[AnyContent] = userAction.async { implicit request =>
val canReview = request.user.isSuper || request.user.isSupport
Future(
Ok(views.html.batchChanges
.batchChanges(request.user.userName, canReview)))
}
def viewBatchChange(batchId: String): Action[AnyContent] = userAction.async { implicit request =>
logger.info(s"View Batch Change for $batchId")
val canReview = request.user.isSuper || request.user.isSupport
Future(
Ok(views.html.batchChanges
.batchChangeDetail(request.user.userName, canReview)))
}
def viewNewBatchChange(): Action[AnyContent] = userAction.async { implicit request =>
Future(Ok(views.html.batchChanges.batchChangeNew(request.user.userName)))
}
}