--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
private val provideSaml2Client: SAML2Client = {
val cfg = new SAML2ClientConfiguration("resource:clientkeystore.jks", "changeit", "changeit", "resource:MetaData.xml")
cfg.setMaximumAuthenticationLifetime(3600)
new SAML2Client(cfg)
}
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users+unsubscribe@googlegroups.com.
--
GET /index controllers.HomeController.index
GET /public controllers.HomeController.public
# https://github.com/pac4j/play-pac4j#4-define-the-callback-endpoint-only-for-indirect-clients-callbackcontroller
POST /callback @org.pac4j.play.CallbackController.callback()
modules/SecurityModule.scala
package modules
import com.google.inject.{AbstractModule, Provides}
import controllers.CustomAuthorizer
import org.pac4j.core.client.Clients
import org.pac4j.play.http.DefaultHttpActionAdapter
import org.pac4j.play.{CallbackController, LogoutController}
import org.pac4j.saml.client.SAML2ClientConfiguration
import play.api.{Configuration, Environment}
import org.pac4j.play.store.{PlayCacheSessionStore, PlaySessionStore}
import org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer
import org.pac4j.core.config.Config
import org.pac4j.saml.client.SAML2Client
class SecurityModule(environment: Environment, configuration: Configuration) extends AbstractModule {
val baseUrl: String = "http://localhost:9000"
@Provides
def provideSaml2Client: SAML2Client = {
val cfg = new SAML2ClientConfiguration("resource:clientkeystore.jks", "changeit", "changeit", "resource:MetaData.xml")
cfg.setMaximumAuthenticationLifetime(3600)
new SAML2Client(cfg)
}
override def configure(): Unit = {
bind(classOf[PlaySessionStore]).to(classOf[PlayCacheSessionStore])
// callback
val callbackController = new CallbackController()
callbackController.setDefaultUrl("/?defaulturlafterlogout")
callbackController.setMultiProfile(true)
bind(classOf[CallbackController]).toInstance(callbackController)
// logout
val logoutController = new LogoutController()
logoutController.setDefaultUrl("/")
bind(classOf[LogoutController]).toInstance(logoutController)
}
@Provides
def provideConfig(saml2Client: SAML2Client): Config = {
val clients = new Clients(baseUrl + "/callback", saml2Client)
val config = new Config(clients)
config.addAuthorizer("custom", new CustomAuthorizer)
config.setHttpActionAdapter(new DefaultHttpActionAdapter())
config
}
}
conf/application.conf
play.http.filters = "filters.Filters"
play.modules.enabled += "modules.SecurityModule"
pac4j.security {
rules = [
{"/index" = {
authorizers = "_authenticated_"
clients = "SAML2Client"
} }
{"/public" = {
authorizers = "_anonymous_"
}}
]
}
controllers/HomeController.scala
@Singleton
class HomeController @Inject()(cc: ControllerComponents, val config: Config, val playSessionStore: PlaySessionStore)
extends AbstractController(cc) with Security[CommonProfile] {
def index() = Secure("SAML2Client") { profiles: List[CommonProfile] =>
Action { implicit request: Request[AnyContent] =>
Ok(views.html.index("protected index"))
}
}
def public() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index("public"))
}
}
controllers/CustomAuthorizer.scala
(copied from your library)
Thanks!
Kevin
--
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_8e8dc5f69a98cc4c1ff3427e5ce34606fd672f91e6" Version="2.0" IssueInstant="2014-07-17T01:01:48Z" Destination="http://sp.example.com/demo1/index.php?acs" InResponseTo="ONELOGIN_4fee3b046395c4e751011e97f8900b5273d56685">
<saml:Issuer>http://idp.example.com/metadata.php</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" ID="_d71a3a8e9fcc45c9e9d248ef7049393fc8f04e5f75" Version="2.0" IssueInstant="2014-07-17T01:01:48Z">
<saml:Issuer>http://idp.example.com/metadata.php</saml:Issuer>
<saml:Subject>
<saml:NameID SPNameQualifier="http://sp.example.com/demo1/metadata.php" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">_ce3d2948b4cf20146dee0a0b3dd6f69b6cf86f62d7</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2024-01-18T06:21:48Z" Recipient="http://sp.example.com/demo1/index.php?acs" InResponseTo="ONELOGIN_4fee3b046395c4e751011e97f8900b5273d56685"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2014-07-17T01:01:18Z" NotOnOrAfter="2024-01-18T06:21:48Z">
<saml:AudienceRestriction>
<saml:Audience>http://sp.example.com/demo1/metadata.php</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2014-07-17T01:01:48Z" SessionNotOnOrAfter="2024-07-17T09:01:48Z" SessionIndex="_be9967abd904ddcae3c0eb4189adbe3f71e327cf93">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="uid" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="mail" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xsi:type="xs:string">te...@example.com</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="eduPersonAffiliation" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xsi:type="xs:string">users</saml:AttributeValue>
<saml:AttributeValue xsi:type="xs:string">examplerole1</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>
--