Skip to content

Commit ddfb9c5

Browse files
committed
Implement customization of rolePrefix in LdapUserDetailsManager
1 parent fd3de41 commit ddfb9c5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
104104
/** The attribute which contains members of a group */
105105
private String groupMemberAttributeName = "uniquemember";
106106

107-
private final String rolePrefix = "ROLE_";
107+
private String rolePrefix = "ROLE_";
108108

109109
/** The pattern to be used for the user search. {0} is the user's DN */
110110
private String groupSearchFilter = "(uniquemember={0})";
@@ -403,6 +403,15 @@ public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy secur
403403
this.securityContextHolderStrategy = securityContextHolderStrategy;
404404
}
405405

406+
/**
407+
* Sets the role prefix used when converting authorities. The default value is "ROLE_"
408+
* @param rolePrefix role prefix
409+
* @since 6.3
410+
*/
411+
public void setRolePrefix(String rolePrefix) {
412+
this.rolePrefix = rolePrefix;
413+
}
414+
406415
private void changePasswordUsingAttributeModification(DistinguishedName userDn, String oldPassword,
407416
String newPassword) {
408417
ModificationItem[] passwordChange = new ModificationItem[] { new ModificationItem(DirContext.REPLACE_ATTRIBUTE,

0 commit comments

Comments
 (0)