1
1
package modules
2
2
3
3
import com .google .inject .{AbstractModule , Provides }
4
- import org .pac4j .core .client .Clients
4
+ import org .pac4j .core .client .{ Client , Clients }
5
5
import org .pac4j .core .client .direct .AnonymousClient
6
6
import org .pac4j .core .config .Config
7
7
import org .pac4j .core .context .session .SessionStore
8
8
import org .pac4j .core .profile .CommonProfile
9
+ import org .pac4j .http .client .direct .DirectBasicAuthClient
9
10
import org .pac4j .play .scala .{DefaultSecurityComponents , Pac4jScalaTemplateHelper , SecurityComponents }
10
11
import org .pac4j .play .store .{PlayCookieSessionStore , ShiroAesDataEncrypter }
11
12
import org .pac4j .play .{CallbackController , LogoutController }
@@ -43,16 +44,21 @@ class SecurityModule(environment: Environment, configuration: Configuration) ext
43
44
@ Provides
44
45
def provideConfig (): Config = {
45
46
val maybeConfiguredClientName = configuration.getOptional[String ](ConfigKeyAuthClient ).filter(_.nonEmpty)
46
- val authClientOpt = maybeConfiguredClientName.map {
47
- case " SAML2Client" => createSaml2Client(s " $ConfigKeyPrefixClientConfig.SAML2Client " )
47
+ val config : Option [Config ] = maybeConfiguredClientName.map {
48
+ case " DirectBasicAuthClient" => createConfiguredDirectBasicAuthConfig(s " $ConfigKeyPrefixClientConfig.ConfiguredDirectBasicAuthClient " )
49
+ case " SAML2Client" => createSaml2Config(s " $ConfigKeyPrefixClientConfig.SAML2Client " )
48
50
case other => throw new RuntimeException (s " Unsupported auth client config value: $other" )
49
51
}
50
- val allClients = authClientOpt.toSeq :+ new AnonymousClient ()
51
- // callback URL path as configured in `routes`
52
- val clients = new Clients (s " $baseUrl/callback " , allClients:_* )
53
- new Config (clients)
52
+ config.getOrElse(new Config ())
53
+ }
54
+
55
+ private def createConfiguredDirectBasicAuthConfig (keyPrefix : String ): Config = {
56
+ val username = configuration.get[String ](s " $keyPrefix.username " )
57
+ val password = configuration.get[String ](s " $keyPrefix.password " )
58
+ new Config (new DirectBasicAuthClient (ConfiguredBasicAuthAuthenticator (username, password)))
54
59
}
55
- private def createSaml2Client (keyPrefix : String ): SAML2Client = {
60
+
61
+ private def createSaml2Config (keyPrefix : String ): Config = {
56
62
val cfg = new SAML2Configuration (
57
63
configuration.get[String ](s " $keyPrefix.keystore " ),
58
64
configuration.get[String ](s " $keyPrefix.keystorePassword " ),
@@ -62,7 +68,10 @@ class SecurityModule(environment: Environment, configuration: Configuration) ext
62
68
cfg.setServiceProviderEntityId(configuration.get[String ](s " $keyPrefix.serviceProviderEntityId " ))
63
69
cfg.setServiceProviderMetadataPath(configuration.get[String ](s " $keyPrefix.serviceProviderMetadataPath " ))
64
70
cfg.setMaximumAuthenticationLifetime(configuration.get[Long ](s " $keyPrefix.maximumAuthenticationLifetime " ))
65
- new SAML2Client (cfg)
71
+ val allClients = Option (new SAML2Client (cfg)).toSeq :+ new AnonymousClient ()
72
+ // callback URL path as configured in `routes`
73
+ val clients = new Clients (s " $baseUrl/callback " , allClients:_* )
74
+ new Config (clients)
66
75
}
67
76
68
77
}
0 commit comments