xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
// assignable from same class as configured
UserManager um = umc.getUserManager(UserManagerImpl.class, new Class[] {
SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
assertNotNull(um);
assertTrue(um instanceof UserManagerImpl);
assertTrue(um.isAutoSave());
try {
um.autoSave(false);
fail("must not be allowed");
} catch (RepositoryException e) {
// success
}
// derived class expected -> must fail
xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
try {
um = umc.getUserManager(UserPerWorkspaceUserManager.class, new Class[] {
SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
fail("UserManagerImpl is not assignable from derived class");
} catch (ConfigurationException e) {
// success
}
// passing invalid parameter types
xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
try {
um = umc.getUserManager(UserManagerImpl.class, new Class[] {
Session.class}, (SessionImpl) superuser, "admin");
fail("Invalid parameter types -> must fail.");
} catch (ConfigurationException e) {
// success
}
// passing wrong arguments
xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
try {
um = umc.getUserManager(UserManagerImpl.class, new Class[] {
SessionImpl.class, String.class}, superuser, 21);
fail("Invalid init args -> must fail.");
} catch (ConfigurationException e) {
// success
}
xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_DERIVED)), true);
umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
// assignable from defines base class
um = umc.getUserManager(UserManagerImpl.class, new Class[] {
SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
assertNotNull(um);
assertTrue(um instanceof UserPerWorkspaceUserManager);
// but: configured class creates a umgr that requires session.save
assertTrue(um.isAutoSave());
// changing autosave behavior must succeed.
um.autoSave(false);
}