From d35d32b1d618deeb9746e0be6a628b5daf39db0f Mon Sep 17 00:00:00 2001 From: itning Date: Thu, 24 Jan 2019 23:23:21 +0800 Subject: [PATCH] fix bug --- .../config/impl/ConfigServiceImpl.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/top/yunshu/shw/server/service/config/impl/ConfigServiceImpl.java b/src/main/java/top/yunshu/shw/server/service/config/impl/ConfigServiceImpl.java index 955965b..89da6ec 100644 --- a/src/main/java/top/yunshu/shw/server/service/config/impl/ConfigServiceImpl.java +++ b/src/main/java/top/yunshu/shw/server/service/config/impl/ConfigServiceImpl.java @@ -29,31 +29,46 @@ public ConfigServiceImpl(ConfigDao configDao, CasProperties casProperties) { } private void init() { - if (!configDao.existsById(Config.ConfigKey.CAS_SERVER_URL.getKey())) { + Optional casServerUrl = configDao.findById(Config.ConfigKey.CAS_SERVER_URL.getKey()); + if (casServerUrl.isPresent()) { + casProperties.setServerUrl(URI.create(casServerUrl.get().getValue())); + } else { Config config = new Config(); config.setName(Config.ConfigKey.CAS_SERVER_URL.getKey()); config.setValue(casProperties.getServerUrl().toString()); configDao.saveAndFlush(config); } - if (!configDao.existsById(Config.ConfigKey.CAS_LOGIN_URL.getKey())) { + Optional casLoginUrl = configDao.findById(Config.ConfigKey.CAS_LOGIN_URL.getKey()); + if (casLoginUrl.isPresent()) { + casProperties.setLoginUrl(URI.create(casLoginUrl.get().getValue())); + } else { Config config = new Config(); config.setName(Config.ConfigKey.CAS_LOGIN_URL.getKey()); config.setValue(casProperties.getLoginUrl().toString()); configDao.saveAndFlush(config); } - if (!configDao.existsById(Config.ConfigKey.CAS_LOGOUT_URL.getKey())) { + Optional casLogoutUrl = configDao.findById(Config.ConfigKey.CAS_LOGOUT_URL.getKey()); + if (casLogoutUrl.isPresent()) { + casProperties.setLogoutUrl(URI.create(casLogoutUrl.get().getValue())); + } else { Config config = new Config(); config.setName(Config.ConfigKey.CAS_LOGOUT_URL.getKey()); config.setValue(casProperties.getLogoutUrl().toString()); configDao.saveAndFlush(config); } - if (!configDao.existsById(Config.ConfigKey.LOGIN_SUCCESS_URL.getKey())) { + Optional loginSuccessUrl = configDao.findById(Config.ConfigKey.LOGIN_SUCCESS_URL.getKey()); + if (loginSuccessUrl.isPresent()) { + casProperties.setLoginSuccessUrl(URI.create(loginSuccessUrl.get().getValue())); + } else { Config config = new Config(); config.setName(Config.ConfigKey.LOGIN_SUCCESS_URL.getKey()); config.setValue(casProperties.getLoginSuccessUrl().toString()); configDao.saveAndFlush(config); } - if (!configDao.existsById(Config.ConfigKey.LOCAL_SERVER_URL.getKey())) { + Optional localServerUrl = configDao.findById(Config.ConfigKey.LOCAL_SERVER_URL.getKey()); + if (localServerUrl.isPresent()) { + casProperties.setLocalServerUrl(URI.create(localServerUrl.get().getValue())); + } else { Config config = new Config(); config.setName(Config.ConfigKey.LOCAL_SERVER_URL.getKey()); config.setValue(casProperties.getLocalServerUrl().toString());