Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanmw
loginservice
Commits
2ad478d6
Commit
2ad478d6
authored
Sep 07, 2022
by
lanmw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加配置项,支持LB方式集成saml或者单服务模式
parent
4b1a9c29
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
18 deletions
+158
-18
pom.xml
pom.xml
+7
-7
ContextProperties.java
...main/java/com/keymobile/login/saml/ContextProperties.java
+47
-0
SAMLConfig.java
src/main/java/com/keymobile/login/saml/SAMLConfig.java
+18
-3
SAMLConfigDefaults.java
...ain/java/com/keymobile/login/saml/SAMLConfigDefaults.java
+35
-5
SamlProperties.java
src/main/java/com/keymobile/login/saml/SamlProperties.java
+35
-1
application-local.yml
src/main/resources/application-local.yml
+14
-0
idp-okta.xml
src/main/resources/idp-okta.xml
+2
-2
No files found.
pom.xml
View file @
2ad478d6
...
@@ -21,13 +21,13 @@
...
@@ -21,13 +21,13 @@
<!--<java.version>1.8</java.version>-->
<!--<java.version>1.8</java.version>-->
<spring-cloud.version>
Finchley.RELEASE
</spring-cloud.version>
<spring-cloud.version>
Finchley.RELEASE
</spring-cloud.version>
</properties>
</properties>
<repositories
>
<!-- <repositories>--
>
<repository
>
<!-- <repository>--
>
<id>
keymobile
</id
>
<!-- <id>keymobile</id>--
>
<name>
keymobile
</name
>
<!-- <name>keymobile</name>--
>
<url>
http://139.198.127.28:18081/repository/maven-public/
</url
>
<!-- <url>http://139.198.127.28:18081/repository/maven-public/</url>--
>
</repository
>
<!-- </repository>--
>
</repositories
>
<!-- </repositories>--
>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
com.github.ulisesbocchio
</groupId>
<groupId>
com.github.ulisesbocchio
</groupId>
...
...
src/main/java/com/keymobile/login/saml/ContextProperties.java
0 → 100644
View file @
2ad478d6
package
com
.
keymobile
.
login
.
saml
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
@ConfigurationProperties
(
"demo.saml.context.provider"
)
@Configuration
public
class
ContextProperties
{
public
ContextProperties
()
{};
private
String
schema
;
private
String
serverName
;
private
String
contextPath
;
private
int
serverPort
;
public
String
getSchema
()
{
return
schema
;
}
public
void
setSchema
(
String
schema
)
{
this
.
schema
=
schema
;
}
public
String
getServerName
()
{
return
serverName
;
}
public
void
setServerName
(
String
serverName
)
{
this
.
serverName
=
serverName
;
}
public
String
getContextPath
()
{
return
contextPath
;
}
public
void
setContextPath
(
String
contextPath
)
{
this
.
contextPath
=
contextPath
;
}
public
int
getServerPort
()
{
return
serverPort
;
}
public
void
setServerPort
(
int
serverPort
)
{
this
.
serverPort
=
serverPort
;
}
}
src/main/java/com/keymobile/login/saml/SAMLConfig.java
View file @
2ad478d6
...
@@ -12,6 +12,7 @@ import org.opensaml.xml.parse.StaticBasicParserPool;
...
@@ -12,6 +12,7 @@ import org.opensaml.xml.parse.StaticBasicParserPool;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -50,6 +51,9 @@ public class SAMLConfig {
...
@@ -50,6 +51,9 @@ public class SAMLConfig {
private
final
SamlProperties
samlProperties
;
private
final
SamlProperties
samlProperties
;
@Value
(
"${server.context-path:}"
)
private
String
serverContextPath
;
@Autowired
@Autowired
public
SAMLConfig
(
SAMLUserDetailsServiceImpl
samlUserDetailsServiceImpl
,
SamlProperties
samlProperties
)
{
public
SAMLConfig
(
SAMLUserDetailsServiceImpl
samlUserDetailsServiceImpl
,
SamlProperties
samlProperties
)
{
this
.
samlUserDetailsServiceImpl
=
samlUserDetailsServiceImpl
;
this
.
samlUserDetailsServiceImpl
=
samlUserDetailsServiceImpl
;
...
@@ -201,7 +205,14 @@ public class SAMLConfig {
...
@@ -201,7 +205,14 @@ public class SAMLConfig {
// 如果为true,则生成的元数据将包含扩展名,指示其能够使用来自IDP发现服务的响应。
// 如果为true,则生成的元数据将包含扩展名,指示其能够使用来自IDP发现服务的响应。
generator
.
setIncludeDiscoveryExtension
(
false
);
generator
.
setIncludeDiscoveryExtension
(
false
);
generator
.
setKeyManager
(
keyManager
);
generator
.
setKeyManager
(
keyManager
);
generator
.
setEntityBaseURL
(
"http://localhost:8089/api/auth"
);
if
(
samlProperties
.
getUseLB
())
{
String
schema
=
samlProperties
.
getContext
().
getSchema
();
String
ip
=
samlProperties
.
getContext
().
getServerName
();
int
port
=
samlProperties
.
getContext
().
getServerPort
();
String
contextPath
=
samlProperties
.
getContext
().
getContextPath
();
String
entityBaseURL
=
String
.
format
(
"%s://%s:%s%s"
,
schema
,
ip
,
port
,
contextPath
);
generator
.
setEntityBaseURL
(
entityBaseURL
);
}
return
generator
;
return
generator
;
}
}
...
@@ -214,7 +225,11 @@ public class SAMLConfig {
...
@@ -214,7 +225,11 @@ public class SAMLConfig {
filter
.
setAuthenticationSuccessHandler
(
successRedirectHandler
());
filter
.
setAuthenticationSuccessHandler
(
successRedirectHandler
());
filter
.
setAuthenticationFailureHandler
(
authenticationFailureHandler
());
filter
.
setAuthenticationFailureHandler
(
authenticationFailureHandler
());
// 在 IDP 登录后跳转到 SP 的地址,也就是所谓的断言消费者
// 在 IDP 登录后跳转到 SP 的地址,也就是所谓的断言消费者
filter
.
setFilterProcessesUrl
(
"/saml/SSO"
);
String
ssoProcessUrl
=
"/saml/SSO"
;
if
(
StringUtils
.
isNotBlank
(
serverContextPath
))
{
ssoProcessUrl
=
serverContextPath
+
ssoProcessUrl
;
}
filter
.
setFilterProcessesUrl
(
ssoProcessUrl
);
return
filter
;
return
filter
;
}
}
...
@@ -231,7 +246,7 @@ public class SAMLConfig {
...
@@ -231,7 +246,7 @@ public class SAMLConfig {
public
SavedRequestAwareAuthenticationSuccessHandler
successRedirectHandler
()
{
public
SavedRequestAwareAuthenticationSuccessHandler
successRedirectHandler
()
{
SavedRequestAwareAuthenticationSuccessHandler
handler
=
new
SavedRequestAwareAuthenticationSuccessHandler
();
SavedRequestAwareAuthenticationSuccessHandler
handler
=
new
SavedRequestAwareAuthenticationSuccessHandler
();
handler
.
setAlwaysUseDefaultTargetUrl
(
true
);
handler
.
setAlwaysUseDefaultTargetUrl
(
true
);
handler
.
setDefaultTargetUrl
(
"http://localhost:8089/center-home/menu/index"
);
handler
.
setDefaultTargetUrl
(
samlProperties
.
getSuccessTargetUrl
()
);
return
handler
;
return
handler
;
}
}
...
...
src/main/java/com/keymobile/login/saml/SAMLConfigDefaults.java
View file @
2ad478d6
...
@@ -2,6 +2,7 @@ package com.keymobile.login.saml;
...
@@ -2,6 +2,7 @@ package com.keymobile.login.saml;
import
org.opensaml.saml2.metadata.provider.MetadataProvider
;
import
org.opensaml.saml2.metadata.provider.MetadataProvider
;
import
org.opensaml.saml2.metadata.provider.MetadataProviderException
;
import
org.opensaml.saml2.metadata.provider.MetadataProviderException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.saml.SAMLBootstrap
;
import
org.springframework.security.saml.SAMLBootstrap
;
...
@@ -26,16 +27,45 @@ public class SAMLConfigDefaults {
...
@@ -26,16 +27,45 @@ public class SAMLConfigDefaults {
return
new
ParserPoolHolder
();
return
new
ParserPoolHolder
();
}
}
@Autowired
private
SamlProperties
samlProperties
;
// @Bean
// public SAMLContextProviderLB contextProvider() {
// SAMLContextProviderLB samlContextProviderLB = new SAMLContextProviderLB();
// samlContextProviderLB.setScheme(samlProperties.getContext().getSchema());
// samlContextProviderLB.setServerName(samlProperties.getContext().getServerName());
// samlContextProviderLB.setContextPath(samlProperties.getContext().getContextPath());
// samlContextProviderLB.setServerPort(samlProperties.getContext().getServerPort());
// samlContextProviderLB.setIncludeServerPortInRequestURL(true);
// return samlContextProviderLB;
// }
@Bean
@Bean
public
SAMLContextProviderLB
contextProvider
()
{
public
SAMLContextProviderImpl
contextProvider
()
{
if
(
samlProperties
.
getUseLB
())
{
SAMLContextProviderLB
samlContextProviderLB
=
new
SAMLContextProviderLB
();
SAMLContextProviderLB
samlContextProviderLB
=
new
SAMLContextProviderLB
();
samlContextProviderLB
.
setScheme
(
"http"
);
samlContextProviderLB
.
setScheme
(
samlProperties
.
getContext
().
getSchema
()
);
samlContextProviderLB
.
setServerName
(
"localhost"
);
samlContextProviderLB
.
setServerName
(
samlProperties
.
getContext
().
getServerName
()
);
samlContextProviderLB
.
setServerPort
(
8089
);
samlContextProviderLB
.
setContextPath
(
samlProperties
.
getContext
().
getContextPath
()
);
samlContextProviderLB
.
setContextPath
(
"/api/auth"
);
samlContextProviderLB
.
setServerPort
(
samlProperties
.
getContext
().
getServerPort
()
);
samlContextProviderLB
.
setIncludeServerPortInRequestURL
(
true
);
samlContextProviderLB
.
setIncludeServerPortInRequestURL
(
true
);
return
samlContextProviderLB
;
return
samlContextProviderLB
;
}
else
{
return
new
SAMLContextProviderImpl
();
}
}
}
// @Bean
// public SAMLContextProviderLB contextProvider() {
// SAMLContextProviderLB samlContextProviderLB = new SAMLContextProviderLB();
// samlContextProviderLB.setScheme("http");
// samlContextProviderLB.setServerName("localhost");
// samlContextProviderLB.setServerPort(8089);
// samlContextProviderLB.setContextPath("/api/auth");
// samlContextProviderLB.setIncludeServerPortInRequestURL(true);
// return samlContextProviderLB;
// }
// @Bean
// @Bean
// public SAMLContextProviderImpl contextProvider() {
// public SAMLContextProviderImpl contextProvider() {
...
...
src/main/java/com/keymobile/login/saml/SamlProperties.java
View file @
2ad478d6
package
com
.
keymobile
.
login
.
saml
;
package
com
.
keymobile
.
login
.
saml
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
@ConfigurationProperties
(
prefix
=
"demo.saml"
)
@ConfigurationProperties
(
prefix
=
"demo.saml"
)
public
class
SamlProperties
{
public
class
SamlProperties
{
...
@@ -38,6 +39,38 @@ public class SamlProperties {
...
@@ -38,6 +39,38 @@ public class SamlProperties {
*/
*/
private
char
[]
keyPassword
;
private
char
[]
keyPassword
;
//配置本身服务相关信息
@Autowired
private
ContextProperties
context
;
private
String
successTargetUrl
;
private
Boolean
useLB
;
public
void
setUseLB
(
Boolean
useLB
)
{
this
.
useLB
=
useLB
;
}
public
Boolean
getUseLB
()
{
return
useLB
;
}
public
void
setSuccessTargetUrl
(
String
successTargetUrl
)
{
this
.
successTargetUrl
=
successTargetUrl
;
}
public
String
getSuccessTargetUrl
()
{
return
successTargetUrl
;
}
public
void
setContext
(
ContextProperties
context
)
{
this
.
context
=
context
;
}
public
ContextProperties
getContext
()
{
return
context
;
}
public
boolean
useKeyStore
()
{
public
boolean
useKeyStore
()
{
return
StringUtils
.
isNotBlank
(
keyStore
);
return
StringUtils
.
isNotBlank
(
keyStore
);
}
}
...
@@ -94,3 +127,4 @@ public class SamlProperties {
...
@@ -94,3 +127,4 @@ public class SamlProperties {
this
.
keyPassword
=
keyPassword
;
this
.
keyPassword
=
keyPassword
;
}
}
}
}
src/main/resources/application-local.yml
View file @
2ad478d6
server
:
server
:
port
:
8082
port
:
8082
# context-path: auth
spring
:
spring
:
application
:
application
:
...
@@ -41,3 +42,16 @@ demo:
...
@@ -41,3 +42,16 @@ demo:
# privateKeyCert: classpath:localhost.key.der
# privateKeyCert: classpath:localhost.key.der
privateKeyCert
:
classpath:localhost.key.der
privateKeyCert
:
classpath:localhost.key.der
keyPassword
:
keyPassword
:
successTargetUrl
:
http://localhost:8089/center-home/menu/index
useLB
:
true
context
:
provider
:
schema
:
http
serverName
:
localhost
contextPath
:
/api/auth
serverPort
:
8089
src/main/resources/idp-okta.xml
View file @
2ad478d6
...
@@ -14,4 +14,4 @@
...
@@ -14,4 +14,4 @@
al2aDAp3OGp/yxMN9JaMlZsVJf9QpHWX3SL0zwnr/N1lSlzP43T13a6kENhCeBjs24iBKafyH1ZG
al2aDAp3OGp/yxMN9JaMlZsVJf9QpHWX3SL0zwnr/N1lSlzP43T13a6kENhCeBjs24iBKafyH1ZG
fP6+UQxCVdYyngRKiMKRJmnNf4g5n2i27CMKk+zPTYwVMOzbDQDOTdEHU3u524XwyDDpfC2Nzoll
fP6+UQxCVdYyngRKiMKRJmnNf4g5n2i27CMKk+zPTYwVMOzbDQDOTdEHU3u524XwyDDpfC2Nzoll
ZyH4lZCjfCQPwm0MCKK+TC8hXiSZ1dMVDTDQ3n+MSmJbgul6TQXX1JCLKYu3Xbj+X1DLjvHgcSa+
ZyH4lZCjfCQPwm0MCKK+TC8hXiSZ1dMVDTDQ3n+MSmJbgul6TQXX1JCLKYu3Xbj+X1DLjvHgcSa+
gucO7vek44zuQ6NlJiCBNZ8HK75ZnBfbfMe/JQ==
</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor><md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
</md:NameIDFormat><md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
</md:NameIDFormat><md:SingleSignOnService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location=
"https://dev-95090549.okta.com/home/dev-95090549_mairuisamldemo_1/0oa67l5t6q5hdrLNV5d7/aln67lcg0a4ZyKKiv5d7"
/><md:SingleSignOnService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location=
"https://dev-95090549.okta.com/home/dev-95090549_mairuisamldemo_1/0oa67l5t6q5hdrLNV5d7/aln67lcg0a4ZyKKiv5d7"
/></md:IDPSSODescriptor></md:EntityDescriptor>
gucO7vek44zuQ6NlJiCBNZ8HK75ZnBfbfMe/JQ==
</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor><md:SingleLogoutService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location=
"https://dev-95090549.okta.com/app/dev-95090549_mairuisamldemo_1/exk67l5t6p2UNYn6l5d7/slo/saml"
/><md:SingleLogoutService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location=
"https://dev-95090549.okta.com/app/dev-95090549_mairuisamldemo_1/exk67l5t6p2UNYn6l5d7/slo/saml"
/><md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
</md:NameIDFormat><md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
</md:NameIDFormat><md:SingleSignOnService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location=
"https://dev-95090549.okta.com/app/dev-95090549_mairuisamldemo_1/exk67l5t6p2UNYn6l5d7/sso/saml"
/><md:SingleSignOnService
Binding=
"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location=
"https://dev-95090549.okta.com/app/dev-95090549_mairuisamldemo_1/exk67l5t6p2UNYn6l5d7/sso/saml"
/></md:IDPSSODescriptor></md:EntityDescriptor>
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment