package com.javaeye.jert.action.setup;
import com.javaeye.jert.service.SecurityService;
import com.javaeye.user.DuplicatePartyException;
import com.javaeye.user.Group;
import com.javaeye.user.User;
import com.javaeye.user.UserManager;
/**
* @author Quake Wang
* @since 2004-12-20
* @version $Revision: 1.5 $
*/
public class CreateAdminAccount extends BaseSetupAction {
private User admin;
private UserManager userManager;
public String execute() throws Exception {
Group adminGroup = getAdminGroup();
admin.addToGroup(adminGroup);
try {
userManager.store(admin);
} catch (DuplicatePartyException e) {
addFieldError("admin.name", getText("error.duplicate.party"));
return INPUT;
}
return SUCCESS;
}
private Group getAdminGroup() throws DuplicatePartyException {
Group adminGroup = userManager.getGroup(SecurityService.ADMIN);
if(adminGroup == null){
adminGroup = userManager.newGroup();
adminGroup.setName(SecurityService.ADMIN);
userManager.store(adminGroup);
}
return adminGroup;
}
public User getAdmin() {
if (admin == null)
admin = userManager.newUser();
return admin;
}
public UserManager getUserManager() {
return userManager;
}
public void setAdmin(User admin) {
this.admin = admin;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
}