@@ -154,7 +154,9 @@ void testInitialization() {
154154
155155 @ Test
156156 void testUsernameForAuthenticationWithDn () {
157- ActiveDirectoryRealm activeDirectoryRealm = new ActiveDirectoryRealm ();
157+ ActiveDirectoryRealm activeDirectoryRealm = new ActiveDirectoryRealm () {{
158+ this .principalSuffix = "@example.com" ;
159+ }};
158160
159161 String dn = "CN=my_name,OU=Development,OU=Special Accounts,DC=mycompany,DC=com" ;
160162
@@ -172,7 +174,9 @@ void testUsernameForAuthenticationWithUsername() {
172174
173175 @ Test
174176 void testAuthenticationUsesDnWithoutEscaping () throws Exception {
175- ActiveDirectoryRealm activeDirectoryRealm = new ActiveDirectoryRealm ();
177+ ActiveDirectoryRealm activeDirectoryRealm = new ActiveDirectoryRealm () {{
178+ this .principalSuffix = "@example.com" ;
179+ }};
176180 LdapContextFactory factory = createMock (LdapContextFactory .class );
177181 LdapContext ldapContext = createNiceMock (LdapContext .class );
178182
@@ -188,6 +192,37 @@ void testAuthenticationUsesDnWithoutEscaping() throws Exception {
188192 verify (factory );
189193 }
190194
195+ @ Test
196+ void testAuthorizationUsesDnWithoutEscaping () throws Exception {
197+ ActiveDirectoryRealm activeDirectoryRealm = new ActiveDirectoryRealm () {{
198+ this .principalSuffix = "@example.com" ;
199+ }};
200+
201+ LdapContext ldapContext = createNiceMock (LdapContext .class );
202+ NamingEnumeration <SearchResult > results = createNiceMock (NamingEnumeration .class );
203+
204+ String dn = "CN=my_name,OU=Development,OU=Special Accounts,DC=mycompany,DC=com" ;
205+
206+ Capture <Object []> captureArgs = Capture .newInstance (CaptureType .ALL );
207+
208+ expect (ldapContext .search (
209+ anyString (),
210+ anyString (),
211+ capture (captureArgs ),
212+ anyObject (SearchControls .class )))
213+ .andReturn (results );
214+
215+ replay (ldapContext );
216+
217+ activeDirectoryRealm .getRoleNamesForUser (dn , ldapContext );
218+
219+ Object [] searchArguments = captureArgs .getValue ();
220+
221+ assertThat (searchArguments [0 ]).isEqualTo (dn );
222+
223+ verify (ldapContext );
224+ }
225+
191226 public void assertExistingUserSuffix (String username , String expectedPrincipalName ) throws Exception {
192227
193228 LdapContext ldapContext = createMock (LdapContext .class );
0 commit comments