diff --git a/pom.xml b/pom.xml index f077d647b..f14493cb3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.support-project knowledge - 1.9.1-SNAPSHOT + 1.10.0-SNAPSHOT war knowledge @@ -59,7 +59,7 @@ org.support-project web - 1.9.0 + 1.10.0-SNAPSHOT diff --git a/src/main/java/org/support/project/knowledge/control/admin/LdapControl.java b/src/main/java/org/support/project/knowledge/control/admin/LdapControl.java index 10650b84f..8b123d597 100644 --- a/src/main/java/org/support/project/knowledge/control/admin/LdapControl.java +++ b/src/main/java/org/support/project/knowledge/control/admin/LdapControl.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -13,8 +14,12 @@ import org.apache.directory.api.ldap.model.exception.LdapException; import org.support.project.common.bean.ValidateError; import org.support.project.common.config.INT_FLAG; +import org.support.project.common.log.Log; +import org.support.project.common.log.LogFactory; import org.support.project.common.util.PasswordUtil; import org.support.project.common.util.StringUtils; +import org.support.project.common.validate.Validator; +import org.support.project.common.validate.ValidatorFactory; import org.support.project.di.DI; import org.support.project.di.Instance; import org.support.project.knowledge.config.AppConfig; @@ -22,10 +27,14 @@ import org.support.project.web.annotation.Auth; import org.support.project.web.bean.LdapInfo; import org.support.project.web.boundary.Boundary; +import org.support.project.web.common.HttpStatus; +import org.support.project.web.config.WebConfig; import org.support.project.web.control.service.Get; import org.support.project.web.control.service.Post; import org.support.project.web.dao.LdapConfigsDao; +import org.support.project.web.dao.SystemConfigsDao; import org.support.project.web.entity.LdapConfigsEntity; +import org.support.project.web.entity.SystemConfigsEntity; import org.support.project.web.exception.InvalidParamException; import org.support.project.web.logic.LdapLogic; @@ -33,33 +42,60 @@ @DI(instance = Instance.Prototype) public class LdapControl extends Control { + /** ログ */ + private static final Log LOG = LogFactory.getLog(LdapControl.class); private static final String CONFIG_TYPE2 = "config2"; private static final String CONFIG_TYPE1 = "config1"; private static final String NO_CHANGE_PASSWORD = "NO_CHANGE_PASSWORD-fXLSJ_V-ZJ2E-X6c2_iGCpkE"; // パスワードを更新しなかったことを表すパスワード - + + /** + * Ldap設定の一覧を表示 + * @return + */ + @Get(publishToken = "admin") + @Auth(roles = "admin") + public Boundary list() { + List configs = LdapConfigsDao.get().selectAll(); + setAttribute("configs", configs); + return forward("list.jsp"); + } + /** * 設定画面を表示 - * * @return */ @Get(publishToken = "admin") @Auth(roles = "admin") public Boundary config() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + key = ""; + } + return config(key); + } + /** + * 設定画面を表示 + * @param key + * @return + */ + private Boundary config(String key) { + setAttribute("key", key); LdapConfigsDao dao = LdapConfigsDao.get(); - LdapConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName()); - String configType = CONFIG_TYPE1; + LdapConfigsEntity entity = dao.selectOnKey(key); + String configType = CONFIG_TYPE2; if (entity == null) { entity = new LdapConfigsEntity(); } else { entity.setBindPassword(NO_CHANGE_PASSWORD); entity.setSalt(""); - - if (entity.getAuthType().intValue() == LdapConfigsEntity.AUTH_TYPE_LDAP_2) { - configType = CONFIG_TYPE2; + if (entity.getAuthType().intValue() == LdapConfigsEntity.AUTH_TYPE_LDAP) { + configType = CONFIG_TYPE1; + } else if (entity.getAuthType().intValue() == LdapConfigsEntity.AUTH_TYPE_BOTH) { + configType = CONFIG_TYPE1; + } else if (entity.getAuthType().intValue() == LdapConfigsEntity.AUTH_TYPE_LDAP_2) { entity.setAuthType(LdapConfigsEntity.AUTH_TYPE_LDAP); } else if (entity.getAuthType().intValue() == LdapConfigsEntity.AUTH_TYPE_BOTH_2) { - configType = CONFIG_TYPE2; entity.setAuthType(LdapConfigsEntity.AUTH_TYPE_BOTH); } } @@ -80,7 +116,7 @@ public Boundary config() { return forward("config.jsp"); } - + /** * リクエストの情報からLdapの設定情報を抽出(共通処理) * @@ -95,10 +131,11 @@ public Boundary config() { * @throws IllegalBlockSizeException * @throws BadPaddingException */ - private LdapConfigsEntity loadLdapConfig() throws InstantiationException, IllegalAccessException, IOException, InvalidParamException, + private LdapConfigsEntity loadLdapConfig(String key) throws InstantiationException, IllegalAccessException, IOException, InvalidParamException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { LdapConfigsDao dao = LdapConfigsDao.get(); LdapConfigsEntity entity = super.getParamOnProperty(LdapConfigsEntity.class); + entity.setAuthType(LdapConfigsEntity.AUTH_TYPE_BOTH); String security = getParam("security"); if (!StringUtils.isEmpty(security)) { if (security.toLowerCase().equals("usessl")) { @@ -116,6 +153,7 @@ private LdapConfigsEntity loadLdapConfig() throws InstantiationException, Illega entity.setAuthType(LdapConfigsEntity.AUTH_TYPE_BOTH_2); } + entity.setDescription(getParam("description2")); entity.setHost(getParam("host2")); entity.setPort(getParam("port2", Integer.class)); security = getParam("security2"); @@ -139,7 +177,7 @@ private LdapConfigsEntity loadLdapConfig() throws InstantiationException, Illega String password = entity.getBindPassword(); if (password.equals(NO_CHANGE_PASSWORD)) { - LdapConfigsEntity saved = dao.selectOnKey(AppConfig.get().getSystemName()); + LdapConfigsEntity saved = dao.selectOnKey(key); if (saved != null) { String encPass = saved.getBindPassword(); String salt = saved.getSalt(); @@ -147,7 +185,6 @@ private LdapConfigsEntity loadLdapConfig() throws InstantiationException, Illega entity.setBindPassword(password); } } - return entity; } @@ -171,9 +208,14 @@ private LdapConfigsEntity loadLdapConfig() throws InstantiationException, Illega @Auth(roles = "admin") public Boundary check() throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException, LdapException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + addMsgWarn("knowledge.ldap.msg.connect.error"); + return config(); + } LdapConfigsDao dao = LdapConfigsDao.get(); - LdapConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName()); - String configType = CONFIG_TYPE1; + LdapConfigsEntity entity = dao.selectOnKey(key); + String configType = CONFIG_TYPE2; if (entity == null) { addMsgWarn("knowledge.ldap.msg.connect.error"); return forward("config.jsp"); @@ -184,27 +226,31 @@ public Boundary check() throws InstantiationException, IllegalAccessException, J configType = CONFIG_TYPE2; } } - - LdapLogic ldapLogic = LdapLogic.get(); - if (CONFIG_TYPE2.equals(configType)) { - boolean check = ldapLogic.check(entity); - if (!check) { - addMsgWarn("knowledge.ldap.msg.connect.error"); - } else { - addMsgSuccess("knowledge.ldap.msg.connect.success2"); - } - } else { - String pass = entity.getBindPassword(); - if (StringUtils.isNotEmpty(entity.getSalt())) { - pass = PasswordUtil.decrypt(pass, entity.getSalt()); - } - LdapInfo result = ldapLogic.auth(entity, entity.getBindDn(), pass); - if (result == null) { - addMsgWarn("knowledge.ldap.msg.connect.error"); + try { + LdapLogic ldapLogic = LdapLogic.get(); + if (CONFIG_TYPE2.equals(configType)) { + boolean check = ldapLogic.check(entity); + if (!check) { + addMsgWarn("knowledge.ldap.msg.connect.error"); + } else { + addMsgSuccess("knowledge.ldap.msg.connect.success2"); + } } else { - addMsgSuccess("knowledge.ldap.msg.connect.success", result.getId(), result.getName(), result.getMail(), - String.valueOf(result.isAdmin())); + String pass = entity.getBindPassword(); + if (StringUtils.isNotEmpty(entity.getSalt())) { + pass = PasswordUtil.decrypt(pass, entity.getSalt()); + } + LdapInfo result = ldapLogic.auth(entity, entity.getBindDn(), pass); + if (result == null) { + addMsgWarn("knowledge.ldap.msg.connect.error"); + } else { + addMsgSuccess("knowledge.ldap.msg.connect.success", result.getId(), result.getName(), result.getMail(), + String.valueOf(result.isAdmin())); + } } + } catch (Exception e) { + LOG.warn(e); + addMsgWarn("knowledge.ldap.msg.connect.error"); } return config(); } @@ -229,18 +275,30 @@ public Boundary check() throws InstantiationException, IllegalAccessException, J @Auth(roles = "admin") public Boundary save() throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException, LdapException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { + String key = getParam("key"); Map params = getParams(); String configType = getParam("configType"); if (CONFIG_TYPE2.equals(configType)) { params.put("host", params.get("host2")); params.put("port", params.get("port2")); + params.put("description", params.get("description2")); } + params.put("authType", "" + LdapConfigsEntity.AUTH_TYPE_BOTH); List errors = LdapConfigsEntity.get().validate(params); + Validator validator = ValidatorFactory.getInstance(Validator.REQUIRED); + ValidateError error = validator.validate(params.get("description"), getResource("knowledge.ldap.label.description")); + if (error != null) { + if (errors == null) { + errors = new ArrayList<>(); + } + errors.add(error); + } if (errors != null && !errors.isEmpty()) { super.setResult("", errors); return forward("config.jsp"); } - LdapConfigsEntity entity = loadLdapConfig(); + LdapConfigsEntity entity = loadLdapConfig(key); + /* LdapLogic ldapLogic = LdapLogic.get(); boolean check = false; if (CONFIG_TYPE2.equals(configType)) { @@ -259,23 +317,33 @@ public Boundary save() throws InstantiationException, IllegalAccessException, JS check = true; } } + */ + boolean check = true; // 保存時の接続チェックをやめた(別途ボタンでチェック) if (!check) { addMsgWarn("knowledge.ldap.msg.save.error"); } else { // Ldap設定を保存 LdapConfigsDao dao = LdapConfigsDao.get(); - entity.setSystemName(AppConfig.get().getSystemName()); + + if (StringUtils.isEmpty(key)) { + int count = dao.selectCountAll(); + count++; + key = "Ldap" + "-" + count; + } + + entity.setSystemName(key); String salt = PasswordUtil.getSalt(); String passHash = PasswordUtil.encrypt(entity.getBindPassword(), salt); entity.setBindPassword(passHash); entity.setSalt(salt); dao.save(entity); - + entity.setBindPassword(NO_CHANGE_PASSWORD); setAttributeOnProperty(entity); addMsgSuccess("knowledge.ldap.msg.save.success"); + setAttribute("key", key); } - return config(); + return config(key); } /** @@ -286,18 +354,33 @@ public Boundary save() throws InstantiationException, IllegalAccessException, JS @Post(subscribeToken = "admin") @Auth(roles = "admin") public Boundary delete() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } LdapConfigsDao dao = LdapConfigsDao.get(); - LdapConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName()); + LdapConfigsEntity entity = dao.selectOnKey(key); if (entity != null) { - dao.physicalDelete(AppConfig.get().getSystemName()); + dao.physicalDelete(key); } entity = new LdapConfigsEntity(); - entity.setSystemName(AppConfig.get().getSystemName()); + entity.setSystemName(key); setAttributeOnProperty(entity); - + + SystemConfigsEntity config = SystemConfigsDao.get().selectOnKey(WebConfig.KEY_LDAP_CONFIG, AppConfig.get().getSystemName()); + if (config != null) { + if (config.getConfigValue().indexOf(key) != -1) { + if (config.getConfigValue().indexOf(key) == 0) { + key = config.getConfigValue().substring(config.getConfigValue().indexOf(key)); + } else { + key = config.getConfigValue().substring(0, config.getConfigValue().indexOf(key) -1).concat(key.substring(config.getConfigValue().indexOf(key) + key.length())); + } + config.setConfigValue(key); + SystemConfigsDao.get().save(config); + } + } addMsgInfo("message.success.delete.target", getResource("knowledge.ldap.title")); - - return config(); + return list(); } } diff --git a/src/main/java/org/support/project/knowledge/control/protect/ConfigControl.java b/src/main/java/org/support/project/knowledge/control/protect/ConfigControl.java index 5f540f10f..d4362923a 100644 --- a/src/main/java/org/support/project/knowledge/control/protect/ConfigControl.java +++ b/src/main/java/org/support/project/knowledge/control/protect/ConfigControl.java @@ -1,16 +1,23 @@ package org.support.project.knowledge.control.protect; +import java.util.List; + import org.support.project.di.DI; import org.support.project.di.Instance; import org.support.project.knowledge.control.Control; import org.support.project.web.boundary.Boundary; import org.support.project.web.control.service.Get; +import org.support.project.web.dao.LdapConfigsDao; +import org.support.project.web.entity.LdapConfigsEntity; @DI(instance = Instance.Prototype) public class ConfigControl extends Control { @Get public Boundary index() { + List ldapConfigs = LdapConfigsDao.get().selectAll(); + Boolean ldapExists = ldapConfigs.size() > 0; + setAttribute("ldapExists", ldapExists); return forward("index.jsp"); } } diff --git a/src/main/java/org/support/project/knowledge/control/protect/ConnectControl.java b/src/main/java/org/support/project/knowledge/control/protect/ConnectControl.java new file mode 100644 index 000000000..b5c189bef --- /dev/null +++ b/src/main/java/org/support/project/knowledge/control/protect/ConnectControl.java @@ -0,0 +1,198 @@ +package org.support.project.knowledge.control.protect; + +import java.io.IOException; +import java.util.List; + +import org.apache.directory.api.ldap.model.exception.LdapException; +import org.support.project.common.config.INT_FLAG; +import org.support.project.common.util.StringUtils; +import org.support.project.knowledge.control.Control; +import org.support.project.web.bean.LdapInfo; +import org.support.project.web.boundary.Boundary; +import org.support.project.web.common.HttpStatus; +import org.support.project.web.control.service.Get; +import org.support.project.web.control.service.Post; +import org.support.project.web.dao.LdapConfigsDao; +import org.support.project.web.dao.UserAliasDao; +import org.support.project.web.dao.UsersDao; +import org.support.project.web.entity.LdapConfigsEntity; +import org.support.project.web.entity.UserAliasEntity; +import org.support.project.web.entity.UsersEntity; +import org.support.project.web.logic.LdapLogic; + +/** + * Ldapなどの外部サービスを使った認証の接続設定 + * @author koda + */ +public class ConnectControl extends Control { + @Get + public Boundary index() { + List ldapConfigs = LdapConfigsDao.get().selectAll(); + setAttribute("ldapConfigs", ldapConfigs); + + List alias = UserAliasDao.get().selectOnUserId(getLoginUserId()); + setAttribute("alias", alias); + + return forward("index.jsp"); + } + + /** + * 指定のユーザのLdap認証設定を設定する + * @return + */ + @Get + public Boundary config() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + LdapConfigsEntity config = LdapConfigsDao.get().selectOnKey(key); + if (config == null) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + setAttribute("config", config); + + UserAliasEntity alias = UserAliasDao.get().selectOnKey(key, getLoginUserId()); + setAttribute("alias", alias); + + if (alias != null) { + List aliases = UserAliasDao.get().selectOnUserId(getLoginUserId()); + if (aliases.size() == 1) { + setAttribute("onlyone", Boolean.TRUE); + } else { + setAttribute("onlyone", Boolean.FALSE); + } + } + + return forward("config.jsp"); + } + + @Post + public Boundary connect() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + LdapConfigsEntity config = LdapConfigsDao.get().selectOnKey(key); + if (config == null) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + String id = getParam("username"); + String password = getParam("password"); + if (StringUtils.isEmpty(id) || StringUtils.isEmpty(password)) { + super.addMsgWarn("message.login.error"); + return config(); + } + String userInfoUpdate = getParam("userInfoUpdate"); + if (StringUtils.isEmpty(userInfoUpdate)) { + userInfoUpdate = "0"; + } + try { + int update = Integer.parseInt(userInfoUpdate); + + UserAliasEntity exists = UserAliasDao.get().selectOnAliasKey(key, id); + if (exists != null) { + super.addMsgWarn("errors.exist", getResource("knowledge.connect.label.account")); + return config(); + } + + // LdapAuth + LdapLogic ldapLogic = LdapLogic.get(); + LdapInfo ldapInfo = ldapLogic.auth(config, id, password); + if (ldapInfo == null) { + super.addMsgWarn("message.login.error"); + return config(); + } + + UserAliasEntity alias = new UserAliasEntity(); + alias.setAuthKey(key); + alias.setUserId(getLoginUserId()); + alias.setAliasKey(id); + alias.setAliasName(ldapInfo.getName().toLowerCase()); + alias.setAliasMail(ldapInfo.getMail()); + alias.setUserInfoUpdate(update); + UserAliasDao.get().save(alias); + + if (update == 1) { + // ユーザの情報を更新する + UsersEntity user = UsersDao.get().selectOnKey(getLoginUserId()); + if (StringUtils.isNotEmpty(ldapInfo.getName())) { + user.setUserName(ldapInfo.getName()); + } + if (StringUtils.isNotEmpty(ldapInfo.getMail())) { + user.setMailAddress(ldapInfo.getMail()); + } + UsersDao.get().save(user); + } + return config(); + } catch (IOException | LdapException e) { + super.addMsgWarn("message.login.error"); + return config(); + } catch (NumberFormatException e) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + } + + @Post + public Boundary disconnect() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + LdapConfigsEntity config = LdapConfigsDao.get().selectOnKey(key); + if (config == null) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + UserAliasEntity exists = UserAliasDao.get().selectOnKey(key, getLoginUserId()); + if (exists == null) { + super.addMsgWarn("errors.noexist", getResource("knowledge.connect.label.account")); + return index(); + } + UserAliasDao.get().physicalDelete(exists); + super.addMsgInfo("message.success.delete"); + return index(); + } + + @Post + public Boundary update() { + String key = getParam("key"); + if (StringUtils.isEmpty(key)) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + LdapConfigsEntity config = LdapConfigsDao.get().selectOnKey(key); + if (config == null) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + String userInfoUpdate = getParam("userInfoUpdate"); + if (StringUtils.isEmpty(userInfoUpdate)) { + userInfoUpdate = "0"; + } + try { + int update = Integer.parseInt(userInfoUpdate); + + UserAliasEntity exists = UserAliasDao.get().selectOnKey(key, getLoginUserId()); + if (exists == null) { + super.addMsgWarn("errors.noexist", getResource("knowledge.connect.label.account")); + return index(); + } + exists.setUserInfoUpdate(update); + UserAliasDao.get().save(exists); + + if (update == INT_FLAG.ON.getValue()) { + UsersEntity user = UsersDao.get().selectOnKey(getLoginUserId()); + user.setUserName(exists.getAliasName()); + user.setMailAddress(exists.getAliasMail()); + UsersDao.get().save(user); + } + + super.addMsgInfo("message.success.update"); + return config(); + } catch (NumberFormatException e) { + return sendError(HttpStatus.SC_400_BAD_REQUEST, "BAD_REQUEST"); + } + } + + + + +} diff --git a/src/main/java/org/support/project/knowledge/deploy/InitDB.java b/src/main/java/org/support/project/knowledge/deploy/InitDB.java index f41e58b8d..5768e831b 100644 --- a/src/main/java/org/support/project/knowledge/deploy/InitDB.java +++ b/src/main/java/org/support/project/knowledge/deploy/InitDB.java @@ -17,6 +17,7 @@ import org.support.project.knowledge.deploy.v0_6_0pre2.Migrate_0_6_0pre2; import org.support.project.knowledge.deploy.v0_6_0pre4.Migrate_0_6_0pre4; import org.support.project.knowledge.deploy.v0_8_0pre1.Migrate_0_8_0pre1; +import org.support.project.knowledge.deploy.v1_10_0.Migrate_1_10_0; import org.support.project.knowledge.deploy.v1_1_0pre1.Migrate_1_1_0pre1; import org.support.project.knowledge.deploy.v1_4_0.Migrate_1_4_0; import org.support.project.knowledge.deploy.v1_5_0.Migrate_1_5_0; @@ -41,7 +42,7 @@ public class InitDB { private static final Map MAP = new LinkedHashMap<>(); private static final Migrate INIT = InitializeSystem.get(); - public static final String CURRENT = "1.8.5"; + public static final String CURRENT = "1.10.0"; public InitDB() { super(); @@ -68,6 +69,7 @@ public InitDB() { MAP.put("1.8.3", Migrate_1_8_3.get()); MAP.put("1.8.4", Migrate_1_8_4.get()); MAP.put("1.8.5", Migrate_1_8_5.get()); + MAP.put("1.10.0", Migrate_1_10_0.get()); } public static void main(String[] args) throws Exception { diff --git a/src/main/java/org/support/project/knowledge/deploy/v1_10_0/Migrate_1_10_0.java b/src/main/java/org/support/project/knowledge/deploy/v1_10_0/Migrate_1_10_0.java new file mode 100644 index 000000000..f3dce3ded --- /dev/null +++ b/src/main/java/org/support/project/knowledge/deploy/v1_10_0/Migrate_1_10_0.java @@ -0,0 +1,52 @@ +package org.support.project.knowledge.deploy.v1_10_0; + +import java.util.List; + +import org.support.project.common.config.INT_FLAG; +import org.support.project.common.util.Compare; +import org.support.project.knowledge.config.AppConfig; +import org.support.project.knowledge.deploy.Migrate; +import org.support.project.ormapping.tool.dao.InitializeDao; +import org.support.project.web.dao.LdapConfigsDao; +import org.support.project.web.dao.UserAliasDao; +import org.support.project.web.dao.UsersDao; +import org.support.project.web.entity.LdapConfigsEntity; +import org.support.project.web.entity.UserAliasEntity; +import org.support.project.web.entity.UsersEntity; + +public class Migrate_1_10_0 implements Migrate { + + public static Migrate_1_10_0 get() { + return org.support.project.di.Container.getComp(Migrate_1_10_0.class); + } + + @Override + public boolean doMigrate() throws Exception { + InitializeDao initializeDao = InitializeDao.get(); + String[] sqlpaths = { + "/org/support/project/knowledge/deploy/v1_10_0/migrate.sql", + }; + initializeDao.initializeDatabase(sqlpaths); + + // 既にLdapを使っている人の情報をAliasに入れる + LdapConfigsEntity entity = LdapConfigsDao.get().selectOnKey(AppConfig.get().getSystemName()); + if (entity != null) { + // Descriptionに初期値をセット + entity.setDescription("LDAP"); + LdapConfigsDao.get().save(entity); + // あまりに多くのユーザだと問題だけど、ユーザなのでたぶん1000件以下なので一気にロード + List users = UsersDao.get().selectAll(); + for (UsersEntity user : users) { + if (Compare.equal(user.getAuthLdap(), INT_FLAG.ON.getValue())) { + UserAliasEntity alias = new UserAliasEntity(AppConfig.get().getSystemName(), user.getUserId()); + alias.setAliasKey(user.getUserKey()); + alias.setAliasMail(user.getMailAddress()); + alias.setAliasName(user.getUserName()); + alias.setUserInfoUpdate(INT_FLAG.ON.getValue()); + UserAliasDao.get().save(alias); + } + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/resources/appresource.properties b/src/main/resources/appresource.properties index af8c52235..68e20fc17 100644 --- a/src/main/resources/appresource.properties +++ b/src/main/resources/appresource.properties @@ -601,6 +601,7 @@ knowledge.sample.markdown.502=- [GitHub Flavored Markdown](https://help.github.c knowledge.sample.markdown.preview=Preview this sample knowledge.ldap.title=Ldap config +knowledge.ldap.label.description=Name knowledge.ldap.label.host=Host knowledge.ldap.label.port=Port knowledge.ldap.label.security=Security @@ -805,4 +806,15 @@ knowledge.survey.msg.survey.notfound=survey data is not found knowledge.survey.msg.copy.select=Please select a survey for copy. knowledge.survey.msg.copy.confirm=Do you want to copy the survey? This contents are overwritten with the contents to be copied. +knowledge.connect.title=Link to other accounts (ex Ldap account) +knowledge.connect.msg=You will be able to SignIn with a linked account. +knowledge.connect.linked=Linked +knowledge.connect.unlinked=Unlinked +knowledge.connect.link=Link +knowledge.connect.unlink=Unlink +knowledge.connect.info.link=If you want to connect to {1}, enter ID / password and execute "{2}" +knowledge.connect.update.me=Update your account information with linked information +knowledge.connect.disable.unlink=Your account use Ldap sign in, and this is the only linked ldap.
You can not be unlink, because you can not sign in if you unlink this ldap. +knowledge.connect.label.account=This account + diff --git a/src/main/resources/appresource_ja.properties b/src/main/resources/appresource_ja.properties index 485e56848..197720102 100644 --- a/src/main/resources/appresource_ja.properties +++ b/src/main/resources/appresource_ja.properties @@ -601,6 +601,7 @@ knowledge.sample.markdown.502=- [GitHub Flavored Markdown](https://help.github.c knowledge.sample.markdown.preview=Sampleで確認 knowledge.ldap.title=Ldap 設定 +knowledge.ldap.label.description=設定名 knowledge.ldap.label.host=Host knowledge.ldap.label.port=Port knowledge.ldap.label.security=Security @@ -805,3 +806,13 @@ knowledge.survey.msg.survey.notfound=取得できるアンケートが存在し knowledge.survey.msg.copy.select=コピーするアンケートを選択してください knowledge.survey.msg.copy.confirm=アンケートをコピーしますか?編集中の内容はコピーされる内容で上書きされます。 +knowledge.connect.title=他アカウントの連携(Ldapのアカウントとの連携) +knowledge.connect.msg=連携したアカウントでログインできるようになります。 +knowledge.connect.linked=連携済 +knowledge.connect.unlinked=未連携 +knowledge.connect.link=連携する +knowledge.connect.unlink=連携を解除する +knowledge.connect.info.link={1}に接続したい場合、ID/パスワードを入力し、「{2}」を実行してください +knowledge.connect.update.me=連携した情報でアカウントの情報を更新する +knowledge.connect.disable.unlink=Ldapログイン利用アカウントで、連携しているアカウントはこれだけです。
連携解除するとログインできなくなるため、解除できません。 +knowledge.connect.label.account=指定のアカウント diff --git a/src/main/resources/org/support/project/knowledge/deploy/v1_10_0/migrate.sql b/src/main/resources/org/support/project/knowledge/deploy/v1_10_0/migrate.sql new file mode 100644 index 000000000..3395fea29 --- /dev/null +++ b/src/main/resources/org/support/project/knowledge/deploy/v1_10_0/migrate.sql @@ -0,0 +1,45 @@ +-- ユーザのエイリアス +drop table if exists USER_ALIAS cascade; + +create table USER_ALIAS ( + USER_ID INTEGER not null + , AUTH_KEY character varying(64) not null + , ALIAS_KEY character varying(256) not null + , ALIAS_NAME character varying(256) not null + , ALIAS_MAIL character varying(256) + , USER_INFO_UPDATE integer + , ROW_ID character varying(64) + , INSERT_USER integer + , INSERT_DATETIME timestamp + , UPDATE_USER integer + , UPDATE_DATETIME timestamp + , DELETE_FLAG integer + , constraint USER_ALIAS_PKC primary key (USER_ID,AUTH_KEY) +) ; + +create unique index USER_ALIAS_IX1 + on USER_ALIAS(AUTH_KEY,ALIAS_KEY); + +comment on table USER_ALIAS is 'ユーザのエイリアス'; +comment on column USER_ALIAS.USER_ID is 'ユーザID'; +comment on column USER_ALIAS.AUTH_KEY is '認証設定キー'; +comment on column USER_ALIAS.ALIAS_KEY is 'エイリアスのキー'; +comment on column USER_ALIAS.ALIAS_NAME is 'エイリアスの表示名'; +comment on column USER_ALIAS.ALIAS_MAIL is 'メールアドレス'; +comment on column USER_ALIAS.USER_INFO_UPDATE is 'アカウント情報更新フラグ'; +comment on column USER_ALIAS.ROW_ID is '行ID'; +comment on column USER_ALIAS.INSERT_USER is '登録ユーザ'; +comment on column USER_ALIAS.INSERT_DATETIME is '登録日時'; +comment on column USER_ALIAS.UPDATE_USER is '更新ユーザ'; +comment on column USER_ALIAS.UPDATE_DATETIME is '更新日時'; +comment on column USER_ALIAS.DELETE_FLAG is '削除フラグ'; + +-- LDAP_CONFIGS へ DESCRIPTION を追加 +ALTER TABLE LDAP_CONFIGS DROP COLUMN IF EXISTS DESCRIPTION; +ALTER TABLE LDAP_CONFIGS ADD COLUMN DESCRIPTION character varying(64); +comment on column LDAP_CONFIGS.SYSTEM_NAME is '設定名'; +comment on column LDAP_CONFIGS.DESCRIPTION is 'DESCRIPTION'; + + + + diff --git a/src/main/webapp/WEB-INF/views/admin/ldap/config.jsp b/src/main/webapp/WEB-INF/views/admin/ldap/config.jsp index 0bd18ee3c..efcc3d28d 100644 --- a/src/main/webapp/WEB-INF/views/admin/ldap/config.jsp +++ b/src/main/webapp/WEB-INF/views/admin/ldap/config.jsp @@ -16,29 +16,29 @@ @@ -51,206 +51,199 @@ $('#myTabs #myTabLdapConfig2').click(function (e) {

<%= jspUtil.label("knowledge.ldap.title") %>

- -
-
-
-
- -
- - - - -
+ " /> + + +
-
- - - -
- - " /> -
-
- - " /> -
- -
-
- - - -
- -
- - " /> -
-
- - " /> -
-
- - " /> -
-
- - " /> -
- - -
- - " /> -
-
- - " /> -
-
- - " value="<%= jspUtil.out("adminCheckFilter") %>" /> -
-
+
+ + +
+ + " value="<%= jspUtil.out("description") %>" /> +
+
+ + " /> +
+
+ + " /> +
+ +
+
+ + + +
+ +
+ + " /> +
+
+ + " /> +
+
+ + " /> +
+
+ + " /> +
+ + +
+ + " /> +
+
+ + " /> +
+
+ + " value="<%= jspUtil.out("adminCheckFilter") %>" /> +
+
-
- - -
- - " /> -
-
- - " /> -
- -
-
- - - -
-
- - " /> -
-
- - " /> -
- -
- - " /> -
-
- - " /> -
- -
- - " /> -
-
- - " /> -
-
- - " /> -
- -
- - " value="<%= jspUtil.out("adminCheckFilter") %>" /> -
- -
-
- - - " /> - - " /> - - - - +
+ + +
+ + " value="<%= jspUtil.out("description") %>" /> +
+
+ + " /> +
+
+ + " /> +
+ +
+
+ + + +
+
+ + " /> +
+
+ + " /> +
+ +
+ + " /> +
+
+ + " /> +
+ +
+ + " /> +
+
+ + " /> +
+
+ + " /> +
+ +
+ + " value="<%= jspUtil.out("adminCheckFilter") %>" /> +
+ +
+
+ + + " /> + + " /> + + + + +  <%= jspUtil.label("label.backlist") %> + +
diff --git a/src/main/webapp/WEB-INF/views/admin/ldap/list.jsp b/src/main/webapp/WEB-INF/views/admin/ldap/list.jsp new file mode 100644 index 000000000..f395af43c --- /dev/null +++ b/src/main/webapp/WEB-INF/views/admin/ldap/list.jsp @@ -0,0 +1,41 @@ +<%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + +<%@page import="java.util.List"%> +<%@page import="org.support.project.common.util.HtmlUtils"%> +<%@page import="org.support.project.common.config.INT_FLAG"%> +<%@page import="org.support.project.web.util.JspUtil"%> +<%@page import="org.support.project.web.entity.LdapConfigsEntity"%> + +<% JspUtil jspUtil = new JspUtil(request, pageContext); %> + + + + + + + + + + + +

<%= jspUtil.label("knowledge.ldap.title") %>

+ +  + <%= jspUtil.label("label.add") %> + + +
+<% List configs = (List) request.getAttribute("configs"); %> +<% for (LdapConfigsEntity ldapConfig : configs) { %> + + <%= ldapConfig.getDescription() %> + +<% } %> +
+ +
+
+ diff --git a/src/main/webapp/WEB-INF/views/admin/systemconfig/index.jsp b/src/main/webapp/WEB-INF/views/admin/systemconfig/index.jsp index 2f0b81ef0..b42b95965 100644 --- a/src/main/webapp/WEB-INF/views/admin/systemconfig/index.jsp +++ b/src/main/webapp/WEB-INF/views/admin/systemconfig/index.jsp @@ -70,7 +70,7 @@
  •  <%=jspUtil.label("knowledge.navbar.config.system.mail")%>
  • -
  • +
  •  <%=jspUtil.label("knowledge.ldap.title")%>
  • diff --git a/src/main/webapp/WEB-INF/views/protect/config/index.jsp b/src/main/webapp/WEB-INF/views/protect/config/index.jsp index 163d1e472..6748e724a 100644 --- a/src/main/webapp/WEB-INF/views/protect/config/index.jsp +++ b/src/main/webapp/WEB-INF/views/protect/config/index.jsp @@ -1,11 +1,12 @@ -<%@page import="org.support.project.common.config.INT_FLAG"%> -<%@page import="org.support.project.knowledge.vo.Roles"%> -<%@page import="org.support.project.web.util.JspUtil"%> <%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> +<%@page import="org.support.project.common.config.INT_FLAG"%> +<%@page import="org.support.project.knowledge.vo.Roles"%> +<%@page import="org.support.project.web.util.JspUtil"%> + <% JspUtil jspUtil = new JspUtil(request, pageContext); %> @@ -27,6 +28,13 @@
  •  <%=jspUtil.label("knowledge.navbar.account.myaccount")%>
  • + + <% if (jspUtil.is(Boolean.TRUE, "ldapExists")) { %> +
  • +  <%=jspUtil.label("knowledge.connect.title")%> +
  • + <% } %> +
  •  <%=jspUtil.label("knowledge.navbar.account.notify")%>
  • diff --git a/src/main/webapp/WEB-INF/views/protect/connect/config.jsp b/src/main/webapp/WEB-INF/views/protect/connect/config.jsp new file mode 100644 index 000000000..e38c45aa3 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/protect/connect/config.jsp @@ -0,0 +1,116 @@ +<%@page import="javax.swing.JSplitPane"%> +<%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + +<%@page import="java.util.List"%> +<%@page import="org.support.project.web.util.JspUtil"%> +<%@page import="org.support.project.web.entity.UserAliasEntity"%> +<%@page import="org.support.project.web.entity.LdapConfigsEntity"%> +<% JspUtil jspUtil = new JspUtil(request, pageContext); %> + + + + + + + + + + + + + +

    <%=jspUtil.label("knowledge.connect.title")%>

    + +

    + <%=jspUtil.out("config.description")%> + + [<%=jspUtil.label("knowledge.connect.linked")%>] + + + [<%=jspUtil.label("knowledge.connect.unlinked")%>] + +

    + +
    + " /> + + + <%= jspUtil.label("") %> +
    + + " + placeholder="<%= jspUtil.label("knowledge.auth.label.id") %>" autofocus> +
    +
    + + " + placeholder="<%= jspUtil.label("knowledge.auth.label.password") %>"> +
    +
    + +
    + + +
    + + + <% if (jspUtil.is(Boolean.TRUE, "onlyone")) { %> + + <% } %> +
    +
    Key
    +
    <%= jspUtil.out("alias.aliasKey") %>
    +
    +
    +
    Name
    +
    <%= jspUtil.out("alias.aliasName") %>
    +
    +
    +
    Mail
    +
    <%= jspUtil.out("alias.aliasMail") %>
    +
    +
    + +
    + + + + +
    + + +  <%= jspUtil.label("label.backlist") %> + + +
    + + +
    + +
    + +
    diff --git a/src/main/webapp/WEB-INF/views/protect/connect/index.jsp b/src/main/webapp/WEB-INF/views/protect/connect/index.jsp new file mode 100644 index 000000000..5c8ec2c22 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/protect/connect/index.jsp @@ -0,0 +1,56 @@ +<%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + +<%@page import="java.util.List"%> +<%@page import="org.support.project.web.util.JspUtil"%> +<%@page import="org.support.project.web.entity.UserAliasEntity"%> +<%@page import="org.support.project.web.entity.LdapConfigsEntity"%> +<% JspUtil jspUtil = new JspUtil(request, pageContext); %> + + + + + + + + + + + +

    <%=jspUtil.label("knowledge.connect.title")%>

    + + + + + +
    + +
    diff --git a/src/main/webapp/js/connect.js b/src/main/webapp/js/connect.js new file mode 100644 index 000000000..07a67ed7f --- /dev/null +++ b/src/main/webapp/js/connect.js @@ -0,0 +1,13 @@ +$(document).ready(function() { + $('#disconnect').click(function() { + $('#form').attr('action', _CONTEXT + '/protect.connect/disconnect'); + $('#form').attr('method', 'POST'); + $('#form').submit(); + }); + + $('#update').click(function() { + $('#form').attr('action', _CONTEXT + '/protect.connect/update'); + $('#form').attr('method', 'POST'); + $('#form').submit(); + }); +});