Skip to content

Commit 396c532

Browse files
committed
[apache#2308] activedirectory: added Initialization test
1 parent 864f046 commit 396c532

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

core/src/test/java/org/apache/shiro/realm/activedirectory/ActiveDirectoryRealmTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.shiro.realm.activedirectory;
2020

2121
import org.apache.shiro.SecurityUtils;
22-
22+
import org.apache.shiro.UnavailableSecurityManagerException;
2323
import org.apache.shiro.authc.AuthenticationException;
2424
import org.apache.shiro.authc.AuthenticationInfo;
2525
import org.apache.shiro.authc.AuthenticationToken;
@@ -28,6 +28,9 @@
2828
import org.apache.shiro.authc.credential.CredentialsMatcher;
2929
import org.apache.shiro.authz.AuthorizationInfo;
3030
import org.apache.shiro.authz.SimpleAuthorizationInfo;
31+
import org.apache.shiro.ini.IniSecurityManagerFactory;
32+
import org.apache.shiro.lang.util.Factory;
33+
import org.apache.shiro.lang.util.LifecycleUtils;
3134
import org.apache.shiro.mgt.DefaultSecurityManager;
3235
import org.apache.shiro.mgt.SecurityManager;
3336
import org.apache.shiro.realm.AuthorizingRealm;
@@ -133,6 +136,21 @@ void testExistingUserSuffix() throws Exception {
133136
assertExistingUserSuffix(USERNAME + "@EXAMPLE.com", "[email protected]");
134137
}
135138

139+
@Test
140+
void testInitialization() {
141+
try {
142+
// Initialize AD Realm
143+
Factory<SecurityManager> factory = new IniSecurityManagerFactory(
144+
"classpath:org/apache/shiro/realm/activedirectory/AdRealm.withPrincipalSuffix.ini");
145+
SecurityUtils.setSecurityManager(factory.getInstance());
146+
// Destroy Realm
147+
SecurityManager securityManager = SecurityUtils.getSecurityManager();
148+
LifecycleUtils.destroy(securityManager);
149+
} catch (UnavailableSecurityManagerException e) {
150+
}
151+
SecurityUtils.setSecurityManager(null);
152+
}
153+
136154
public void assertExistingUserSuffix(String username, String expectedPrincipalName) throws Exception {
137155

138156
LdapContext ldapContext = createMock(LdapContext.class);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
[main]
21+
22+
ldapRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
23+
24+
ldapRealm.url = ldap://dc.example.com:389
25+
ldapRealm.systemUsername = systemuser
26+
ldapRealm.systemPassword = systempwd
27+
28+
ldapRealm.searchBase = "OU=Users,DC=example,DC=com"
29+
ldapRealm.principalSuffix = @example.com
30+
ldapRealm.searchFilter = (&(objectClass=*)(mail={0}))

0 commit comments

Comments
 (0)