Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
1a5db6c5
Commit
1a5db6c5
authored
Jun 20, 2019
by
wuzishu
Committed by
Jason Song
Jun 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ldap userId with case problem (#2326)
fix ldap userId with case problem
parent
3bfed3c8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
213 additions
and
111 deletions
+213
-111
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java
...rk/apollo/portal/spi/configuration/AuthConfiguration.java
+5
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java
...apollo/portal/spi/configuration/LdapExtendProperties.java
+0
-108
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java
.../apollo/portal/spi/configuration/LdapGroupProperties.java
+50
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java
...pollo/portal/spi/configuration/LdapMappingProperties.java
+76
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java
...llo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java
+82
-0
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java
View file @
1a5db6c5
...
@@ -15,6 +15,7 @@ import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultLogoutHandler;
...
@@ -15,6 +15,7 @@ import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultLogoutHandler;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserService
;
import
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserService
;
import
com.ctrip.framework.apollo.portal.spi.ldap.ApolloLdapAuthenticationProvider
;
import
com.ctrip.framework.apollo.portal.spi.ldap.FilterLdapByGroupUserSearch
;
import
com.ctrip.framework.apollo.portal.spi.ldap.FilterLdapByGroupUserSearch
;
import
com.ctrip.framework.apollo.portal.spi.ldap.LdapUserService
;
import
com.ctrip.framework.apollo.portal.spi.ldap.LdapUserService
;
import
com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserInfoHolder
;
...
@@ -392,9 +393,10 @@ public class AuthConfiguration {
...
@@ -392,9 +393,10 @@ public class AuthConfiguration {
ldapContextSource
,
null
);
ldapContextSource
,
null
);
defaultAuthAutoConfiguration
.
setIgnorePartialResultException
(
true
);
defaultAuthAutoConfiguration
.
setIgnorePartialResultException
(
true
);
defaultAuthAutoConfiguration
.
setSearchSubtree
(
true
);
defaultAuthAutoConfiguration
.
setSearchSubtree
(
true
);
LdapAuthenticationProvider
ldapAuthenticationProvider
=
new
LdapAuthenticationProvider
(
// Rewrite the logic of LdapAuthenticationProvider with ApolloLdapAuthenticationProvider,
bindAuthenticator
,
defaultAuthAutoConfiguration
);
// use userId in LDAP system instead of userId input by user.
return
ldapAuthenticationProvider
;
return
new
ApolloLdapAuthenticationProvider
(
bindAuthenticator
,
defaultAuthAutoConfiguration
,
ldapExtendProperties
);
}
}
@Override
@Override
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java
View file @
1a5db6c5
...
@@ -33,111 +33,3 @@ public class LdapExtendProperties {
...
@@ -33,111 +33,3 @@ public class LdapExtendProperties {
this
.
group
=
group
;
this
.
group
=
group
;
}
}
}
}
class
LdapMappingProperties
{
/**
* user ldap objectClass
*/
private
String
objectClass
;
/**
* user login Id
*/
private
String
loginId
;
/**
* user rdn key
*/
private
String
rdnKey
;
/**
* user display name
*/
private
String
userDisplayName
;
/**
* email
*/
private
String
email
;
public
String
getObjectClass
()
{
return
objectClass
;
}
public
void
setObjectClass
(
String
objectClass
)
{
this
.
objectClass
=
objectClass
;
}
public
String
getLoginId
()
{
return
loginId
;
}
public
void
setLoginId
(
String
loginId
)
{
this
.
loginId
=
loginId
;
}
public
String
getRdnKey
()
{
return
rdnKey
;
}
public
void
setRdnKey
(
String
rdnKey
)
{
this
.
rdnKey
=
rdnKey
;
}
public
String
getUserDisplayName
()
{
return
userDisplayName
;
}
public
void
setUserDisplayName
(
String
userDisplayName
)
{
this
.
userDisplayName
=
userDisplayName
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
}
class
LdapGroupProperties
{
/**
* group search base
*/
private
String
groupBase
;
/**
* group search filter
*/
private
String
groupSearch
;
/**
* group membership prop
*/
private
String
groupMembership
;
public
String
getGroupBase
()
{
return
groupBase
;
}
public
void
setGroupBase
(
String
groupBase
)
{
this
.
groupBase
=
groupBase
;
}
public
String
getGroupSearch
()
{
return
groupSearch
;
}
public
void
setGroupSearch
(
String
groupSearch
)
{
this
.
groupSearch
=
groupSearch
;
}
public
String
getGroupMembership
()
{
return
groupMembership
;
}
public
void
setGroupMembership
(
String
groupMembership
)
{
this
.
groupMembership
=
groupMembership
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java
0 → 100644
View file @
1a5db6c5
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
configuration
;
/**
* the LdapGroupProperties description.
*
* @author wuzishu
*/
public
class
LdapGroupProperties
{
/**
* group search base
*/
private
String
groupBase
;
/**
* group search filter
*/
private
String
groupSearch
;
/**
* group membership prop
*/
private
String
groupMembership
;
public
String
getGroupBase
()
{
return
groupBase
;
}
public
void
setGroupBase
(
String
groupBase
)
{
this
.
groupBase
=
groupBase
;
}
public
String
getGroupSearch
()
{
return
groupSearch
;
}
public
void
setGroupSearch
(
String
groupSearch
)
{
this
.
groupSearch
=
groupSearch
;
}
public
String
getGroupMembership
()
{
return
groupMembership
;
}
public
void
setGroupMembership
(
String
groupMembership
)
{
this
.
groupMembership
=
groupMembership
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java
0 → 100644
View file @
1a5db6c5
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
configuration
;
/**
* the LdapMappingProperties description.
*
* @author wuzishu
*/
public
class
LdapMappingProperties
{
/**
* user ldap objectClass
*/
private
String
objectClass
;
/**
* user login Id
*/
private
String
loginId
;
/**
* user rdn key
*/
private
String
rdnKey
;
/**
* user display name
*/
private
String
userDisplayName
;
/**
* email
*/
private
String
email
;
public
String
getObjectClass
()
{
return
objectClass
;
}
public
void
setObjectClass
(
String
objectClass
)
{
this
.
objectClass
=
objectClass
;
}
public
String
getLoginId
()
{
return
loginId
;
}
public
void
setLoginId
(
String
loginId
)
{
this
.
loginId
=
loginId
;
}
public
String
getRdnKey
()
{
return
rdnKey
;
}
public
void
setRdnKey
(
String
rdnKey
)
{
this
.
rdnKey
=
rdnKey
;
}
public
String
getUserDisplayName
()
{
return
userDisplayName
;
}
public
void
setUserDisplayName
(
String
userDisplayName
)
{
this
.
userDisplayName
=
userDisplayName
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java
0 → 100644
View file @
1a5db6c5
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
ldap
;
import
com.ctrip.framework.apollo.portal.spi.configuration.LdapExtendProperties
;
import
org.springframework.ldap.core.DirContextOperations
;
import
org.springframework.security.authentication.BadCredentialsException
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.ldap.authentication.LdapAuthenticationProvider
;
import
org.springframework.security.ldap.authentication.LdapAuthenticator
;
import
org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* Inherited from LdapAuthenticationProvider and rewritten the authenticate method,
* modified the userId used by the previous user input,
* changed to use the userId in the LDAP system.
*
* @author wuzishu
*/
public
class
ApolloLdapAuthenticationProvider
extends
LdapAuthenticationProvider
{
private
LdapExtendProperties
properties
;
public
ApolloLdapAuthenticationProvider
(
LdapAuthenticator
authenticator
,
LdapAuthoritiesPopulator
authoritiesPopulator
)
{
super
(
authenticator
,
authoritiesPopulator
);
}
public
ApolloLdapAuthenticationProvider
(
LdapAuthenticator
authenticator
)
{
super
(
authenticator
);
}
public
ApolloLdapAuthenticationProvider
(
LdapAuthenticator
authenticator
,
LdapAuthoritiesPopulator
authoritiesPopulator
,
LdapExtendProperties
properties
)
{
super
(
authenticator
,
authoritiesPopulator
);
this
.
properties
=
properties
;
}
public
ApolloLdapAuthenticationProvider
(
LdapAuthenticator
authenticator
,
LdapExtendProperties
properties
)
{
super
(
authenticator
);
this
.
properties
=
properties
;
}
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
Assert
.
isInstanceOf
(
UsernamePasswordAuthenticationToken
.
class
,
authentication
,
this
.
messages
.
getMessage
(
"LdapAuthenticationProvider.onlySupports"
,
"Only UsernamePasswordAuthenticationToken is supported"
));
UsernamePasswordAuthenticationToken
userToken
=
(
UsernamePasswordAuthenticationToken
)
authentication
;
String
username
=
userToken
.
getName
();
String
password
=
(
String
)
authentication
.
getCredentials
();
if
(
this
.
logger
.
isDebugEnabled
())
{
this
.
logger
.
debug
(
"Processing authentication request for user: "
+
username
);
}
if
(!
StringUtils
.
hasLength
(
username
))
{
throw
new
BadCredentialsException
(
this
.
messages
.
getMessage
(
"LdapAuthenticationProvider.emptyUsername"
,
"Empty Username"
));
}
else
if
(!
StringUtils
.
hasLength
(
password
))
{
throw
new
BadCredentialsException
(
this
.
messages
.
getMessage
(
"AbstractLdapAuthenticationProvider.emptyPassword"
,
"Empty Password"
));
}
else
{
Assert
.
notNull
(
password
,
"Null password was supplied in authentication token"
);
DirContextOperations
userData
=
this
.
doAuthentication
(
userToken
);
String
loginId
=
userData
.
getStringAttribute
(
properties
.
getMapping
().
getLoginId
());
UserDetails
user
=
this
.
userDetailsContextMapper
.
mapUserFromContext
(
userData
,
loginId
,
this
.
loadUserAuthorities
(
userData
,
loginId
,
(
String
)
authentication
.
getCredentials
()));
return
this
.
createSuccessfulAuthentication
(
userToken
,
user
);
}
}
}
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