Skip to content

Commit

Permalink
Merge pull request #106 from diging/develop
Browse files Browse the repository at this point in the history
prepare for release
  • Loading branch information
jdamerow authored Mar 12, 2020
2 parents 9ba6a21 + 074ade5 commit ef7fe2d
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 28 deletions.
3 changes: 2 additions & 1 deletion vspace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
<spring-security-version>4.1.5.RELEASE</spring-security-version>
<javers.version>3.10.1</javers.version>
<simple-users-version>0.5</simple-users-version>
<admin.username>admin</admin.username>
<admin.password>$2a$04$ug2wdYfAW8Ey/DwjUdPuLufgrMqbhNnTmr1QEUNZnoWF1xGitSBae</admin.password>
<staff.password>$2a$04$QhdsxRoZPJw/G06aDkP6COLARKtbdTxVvxtKPZUE0dFlNKFMZsXRe</staff.password>

<log.level>debug</log.level>

<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://localhost:3306/vspace</db.url>
<db.url>jdbc:mysql://localhost:3306/vspace?serverTimezone=UTC</db.url>
<db.user>vspace</db.user>
<db.password>vspace</db.password>
<uploaded.files.path></uploaded.files.path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@Configuration
@EnableTransactionManagement
@PropertySource("classpath:config.properties")
@PropertySource({"classpath:config.properties", "${appConfigFile:classpath:}/app.properties"})
public class PersistenceJPAConfig {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests()
// Anyone can access the urls
.antMatchers("/", "/exhibit/**", "/api/**", "/resources/**", "/login",
"/logout", "/register", "/reset/**").permitAll()
"/logout", "/register", "/reset/**", "/setup/admin").permitAll()
// The rest of the our application is protected.
.antMatchers("/users/**", "/admin/**", "/staff/user/**").hasRole("ADMIN")
.antMatchers("/staff/**").hasAnyRole("STAFF", "ADMIN")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import edu.asu.diging.simpleusers.core.config.SimpleUsersConfiguration;

@Configuration
@PropertySource("classpath:/config.properties")
@PropertySource({"classpath:config.properties", "${appConfigFile:classpath:}/app.properties"})
public class SimpleUserConfig implements SimpleUsersConfiguration {

@Value("${email_user}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Configuration
@EnableAspectJAutoProxy
@PropertySource("classpath:/config.properties")
@PropertySource({"classpath:config.properties", "${appConfigFile:classpath:}/app.properties"})
public class VSpaceConfig {

@Value("${max_upload_size}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import edu.asu.diging.vspace.core.model.IVSImage;

@Component
@PropertySource("classpath:/config.properties")
@PropertySource({"classpath:config.properties", "${appConfigFile:classpath:}/app.properties"})
public class StorageEngine implements IStorageEngine {

@Value("${uploads_path}")
Expand Down
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public ImageData getImageDimensions(IVSImage image, int width, int height) {
@Override
public List<IVSImage > getImages(int pageNo) {
pageNo = validatePageNumber(pageNo);
Pageable sortByRequestedField = PageRequest.of(pageNo-1, pageSize, Sort.by(SortByField.CREATION_DATE.getValue()));
Pageable sortByRequestedField = PageRequest.of(pageNo-1, pageSize, Sort.by(SortByField.CREATION_DATE.getValue()).descending());
Page<VSImage> images = imageRepo.findAll(sortByRequestedField);
List<IVSImage> results = new ArrayList<>();
images.getContent().forEach(i -> results.add(i));
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

import edu.asu.diging.vspace.core.model.IExhibition;
import edu.asu.diging.vspace.core.services.IExhibitionManager;
import edu.asu.diging.vspace.core.services.ISetupManager;

@Controller
public class HomeController {

@Autowired
private IExhibitionManager exhibitionManager;


@Autowired
private ISetupManager setupManager;

@RequestMapping(value = "/")
public String home(Model model) {
if (!setupManager.isSetup()) {
return "setup";
}

IExhibition exhibition = exhibitionManager.getStartExhibition();
if (exhibition != null && exhibition.getStartSpace() != null) {
return "redirect:/exhibit/space/" + exhibition.getStartSpace().getId();
Expand Down
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";
}
}
16 changes: 16 additions & 0 deletions vspace/src/main/resources/app.properties
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}
15 changes: 0 additions & 15 deletions vspace/src/main/resources/config.properties
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
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}

max_upload_size=-1

uploads_path=${uploaded.files.path}
bg_image_suffix=_background
bg_image_max_width=800
bg_image_max_height=1000


hibernate_show_sql=${hibernate.show_sql}
page_size=10

image_category_SPACE_BACKGROUND_IMAGE=Space Background Image
Expand Down
11 changes: 9 additions & 2 deletions vspace/src/main/webapp/WEB-INF/spring/root-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@
<aop:aspectj-autoproxy
proxy-target-class="true" />

<bean
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="propertiesArray">
<array>
<ref bean="configFile" />
</array>
</property>
</bean>

<util:properties id="configFile"
location="classpath:config.properties" />
<context:property-placeholder
properties-ref="configFile" />

</beans>
17 changes: 17 additions & 0 deletions vspace/src/main/webapp/WEB-INF/tiles-defs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
<put-attribute name="currentPage" value="home" />
<put-attribute name="sidemenu" value="" />
</definition>
<definition name="base.definition.no.menu" template="/WEB-INF/tiles/skeleton_exhibition_no_menu.jsp">
<put-attribute name="title" value="" />
<put-attribute name="navigation" value="" />
<put-attribute name="content" value="" />
<put-attribute name="header" value="" />
<put-attribute name="pageName" value="" />
<put-attribute name="currentPage" value="home" />
<put-attribute name="sidemenu" value="" />
</definition>
<definition name="base.definition.bt4" template="/WEB-INF/tiles/skeleton_bt4.jsp">
<put-attribute name="title" value="" />
<put-attribute name="navigation" value="" />
Expand All @@ -31,6 +40,14 @@
<definition name="login" extends="base.definition">
<put-attribute name="content" value="/WEB-INF/views/login.jsp" />
</definition>

<definition name="setup" extends="base.definition.no.menu">
<put-attribute name="content" value="/WEB-INF/views/setup.jsp" />
</definition>

<definition name="setup/complete" extends="base.definition">
<put-attribute name="content" value="/WEB-INF/views/setupComplete.jsp" />
</definition>

<!-- Exhibition -->
<definition name="space" extends="base.definition">
Expand Down
5 changes: 5 additions & 0 deletions vspace/src/main/webapp/WEB-INF/tiles/skeleton_exhibition2.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@

<!-- Begin page content -->
<main role="main" class="flex-shrink-0" style="padding-top: 20px;">
<c:if test="${showAlert eq true}">
<div id="errorMsg" class="alert alert-${alertType}">
${message}
</div>
</c:if>
<tiles:insertAttribute name="content" />
</main>
</div>
Expand Down
Loading

0 comments on commit ef7fe2d

Please sign in to comment.