-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from diging/develop
prepare for release
- Loading branch information
Showing
20 changed files
with
369 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
vspace/src/main/java/edu/asu/diging/vspace/core/services/ISetupManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package edu.asu.diging.vspace.core.services; | ||
|
||
import edu.asu.diging.simpleusers.core.exceptions.UserAlreadyExistsException; | ||
import edu.asu.diging.simpleusers.core.model.IUser; | ||
|
||
public interface ISetupManager { | ||
|
||
/** | ||
* This method checks if a user called "admin" exists. If not, we assume this | ||
* application has not yet been setup. | ||
* | ||
* @return | ||
*/ | ||
boolean isSetup(); | ||
|
||
IUser setupAdmin(String password) throws UserAlreadyExistsException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SetupManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.asu.diging.vspace.core.services.impl; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.transaction.Transactional; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
|
||
import edu.asu.diging.simpleusers.core.exceptions.UserAlreadyExistsException; | ||
import edu.asu.diging.simpleusers.core.model.IUser; | ||
import edu.asu.diging.simpleusers.core.model.Role; | ||
import edu.asu.diging.simpleusers.core.model.impl.User; | ||
import edu.asu.diging.simpleusers.core.service.IUserManager; | ||
import edu.asu.diging.vspace.core.services.ISetupManager; | ||
|
||
@Transactional | ||
@Service | ||
@PropertySource({"${appConfigFile:classpath:}/app.properties"}) | ||
public class SetupManager implements ISetupManager { | ||
|
||
@Autowired | ||
private Environment env; | ||
|
||
@Autowired | ||
private IUserManager userManager; | ||
|
||
private String adminUsername; | ||
|
||
@PostConstruct | ||
public void init() { | ||
adminUsername = env.getProperty("admin_username"); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.vspace.core.services.impl.ISetupManager#isSetup() | ||
*/ | ||
@Override | ||
public boolean isSetup() { | ||
IUser admin = userManager.findByUsername(adminUsername); | ||
if (admin != null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public IUser setupAdmin(String password) throws UserAlreadyExistsException { | ||
IUser user = new User(); | ||
user.setUsername(adminUsername); | ||
user.setPassword(password); | ||
userManager.create(user); | ||
userManager.approveAccount(adminUsername, adminUsername); | ||
userManager.addRole(adminUsername, adminUsername, Role.ADMIN); | ||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
vspace/src/main/java/edu/asu/diging/vspace/web/SetupAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.asu.diging.vspace.web; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
|
||
import edu.asu.diging.simpleusers.core.exceptions.UserAlreadyExistsException; | ||
import edu.asu.diging.simpleusers.core.model.IUser; | ||
import edu.asu.diging.vspace.core.services.ISetupManager; | ||
|
||
@Controller | ||
public class SetupAdminController { | ||
|
||
@Autowired | ||
private ISetupManager setupManager; | ||
|
||
@RequestMapping(value="/setup/admin", method=RequestMethod.POST) | ||
public String setup(@RequestParam("adminpw") String password, RedirectAttributes redirectAttrs, Model model) { | ||
if (setupManager.isSetup()) { | ||
redirectAttrs.addFlashAttribute("showAlert", true); | ||
redirectAttrs.addFlashAttribute("alertType", "warning"); | ||
redirectAttrs.addFlashAttribute("message", "Looks like the admin user has already been configured."); | ||
return "redirect:/"; | ||
} | ||
|
||
try { | ||
IUser user = setupManager.setupAdmin(password); | ||
model.addAttribute("adminUsername", user.getUsername()); | ||
} catch (UserAlreadyExistsException e) { | ||
redirectAttrs.addFlashAttribute("showAlert", true); | ||
redirectAttrs.addFlashAttribute("alertType", "warning"); | ||
redirectAttrs.addFlashAttribute("message", "Looks like the admin user has already been configured."); | ||
return "redirect:/"; | ||
} | ||
return "setup/complete"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
db_driver=${db.driver} | ||
db_url=${db.url} | ||
db_user=${db.user} | ||
db_password=${db.password} | ||
|
||
email_user=${email.user} | ||
email_password=${email.password} | ||
email_host=${email.host} | ||
email_port=${email.port} | ||
email_from=${email.from} | ||
app_url=${app.url} | ||
|
||
uploads_path=${uploaded.files.path} | ||
|
||
hibernate_show_sql=${hibernate.show_sql} | ||
admin_username=${admin.username} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.