diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java index f135bbbef20ac80855dadcc26c079cb01f98509a..2a1e8e391d95e6b4a0206875d166b0b0ac628b18 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java @@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.controller; import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; +import com.ctrip.framework.apollo.portal.entity.po.UserPO; import com.ctrip.framework.apollo.portal.spi.LogoutHandler; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserService; @@ -10,7 +11,6 @@ import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserSe import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.userdetails.User; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -38,7 +38,7 @@ public class UserInfoController { @PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @RequestMapping(value = "/users", method = RequestMethod.POST) - public void createOrUpdateUser(@RequestBody User user) { + public void createOrUpdateUser(@RequestBody UserPO user) { if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) { throw new BadRequestException("Username and password can not be empty."); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java index 7edf69ef308d46ce42edfce948b289953e15d2f6..83ee1d56664b0fa26278120ca9b18b912788d970 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java @@ -1,7 +1,6 @@ package com.ctrip.framework.apollo.portal.entity.bo; public class UserInfo { - public static final UserInfo DEFAULT_USER = new UserInfo("apollo"); private String userId; private String name; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java index 5734e197bbecf75cd7db065983fce7868064a0ee..ed4b8549931578f6c99e296baaab0031f4234b5d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java @@ -23,6 +23,8 @@ public class UserPO { private String username; @Column(name = "Password", nullable = false) private String password; + @Column(name = "Email", nullable = false) + private String email; @Column(name = "Enabled", nullable = false) private int enabled; @@ -42,6 +44,14 @@ public class UserPO { this.username = username; } + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + public String getPassword() { return password; } @@ -62,7 +72,7 @@ public class UserPO { UserInfo userInfo = new UserInfo(); userInfo.setName(this.getUsername()); userInfo.setUserId(this.getUsername()); - userInfo.setEmail(this.getUsername() + "@acme.com"); + userInfo.setEmail(this.getEmail()); return userInfo; } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java index d884a66c474a86df1212d456a9a4fbbfa3accc24..c71920dd2d4bcd89a9b1adac4a51e1fff0885142 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java @@ -15,6 +15,7 @@ import org.springframework.security.core.userdetails.User; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.JdbcUserDetailsManager; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -42,7 +43,8 @@ public class SpringSecurityUserService implements UserService { authorities.add(new SimpleGrantedAuthority("ROLE_user")); } - public void createOrUpdate(User user) { + @Transactional + public void createOrUpdate(UserPO user) { String username = user.getUsername(); User userDetails = new User(username, encoder.encode(user.getPassword()), authorities); @@ -53,6 +55,10 @@ public class SpringSecurityUserService implements UserService { userDetailsManager.createUser(userDetails); } + UserPO managedUser = userRepository.findByUsername(username); + managedUser.setEmail(user.getEmail()); + + userRepository.save(managedUser); } @Override diff --git a/apollo-portal/src/main/resources/static/user-manage.html b/apollo-portal/src/main/resources/static/user-manage.html index 199fe4e8b3fa59e81fa0c10a45765eba78fe05ea..9fab6ae55617282bb6369a7b5e7151653213c2bb 100644 --- a/apollo-portal/src/main/resources/static/user-manage.html +++ b/apollo-portal/src/main/resources/static/user-manage.html @@ -44,6 +44,14 @@ +
+ +
+ +
+
diff --git a/scripts/sql/apolloportaldb.sql b/scripts/sql/apolloportaldb.sql index 50690aab5021da697c741ca0bcdf79e202d21f54..93c014ac59346e5d7c14fd60fea578b1321eb269 100644 --- a/scripts/sql/apolloportaldb.sql +++ b/scripts/sql/apolloportaldb.sql @@ -284,6 +284,7 @@ CREATE TABLE `Users` ( `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户名', `Password` varchar(64) NOT NULL DEFAULT 'default' COMMENT '密码', + `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';