Skip to content

Commit

Permalink
SHIBUI-975 address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Nov 14, 2018
1 parent 97314fe commit 1aba1fc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,4 @@ void showMetadataResolversResourceIds(ApplicationStartedEvent e) {
.forEach(it -> System.out.println(String.format("MetadataResolver [%s: %s]", it.getName(), it.getResourceId())));
}
}

@Component
@Profile("dev")
public static class SampleAdminUsersCreator {

@Autowired
AdminUserRepository adminUserRepository;

@Transactional
@EventListener
void createSampleAdminUsers(ApplicationStartedEvent e) {
if(adminUserRepository.count() == 0L) {
AdminRole role = new AdminRole();
role.setName("ROLE_ADMIN");
AdminUser user = new AdminUser();
user.setUsername("admin");
user.setPassword("{noop}adminpass");

//The complexity of managing bi-directional many-to-many. TODO: encapsulate this association
//managing logic into domain model itself
role.getAdmins().add(user);
user.getRoles().add(role);

adminUserRepository.save(user);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.internet2.tier.shibboleth.admin.ui.configuration.auto;

import edu.internet2.tier.shibboleth.admin.ui.security.DefaultAuditorAware;
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminRole;
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminUser;
import edu.internet2.tier.shibboleth.admin.ui.security.repository.AdminUserRepository;
import edu.internet2.tier.shibboleth.admin.ui.security.springsecurity.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -22,10 +24,14 @@
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;

/**
* Web security configuration.
*
* <p>
* Workaround for slashes in URL from [https://stackoverflow.com/questions/48453980/spring-5-0-3-requestrejectedexception-the-request-was-rejected-because-the-url]
*/
@Configuration
Expand Down Expand Up @@ -75,7 +81,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password(passwordEncoder.encode(defaultPassword))
.password(defaultPassword)
.roles("USER");
} else {
auth.userDetailsService(adminUserService(adminUserRepository)).passwordEncoder(passwordEncoder);
Expand Down Expand Up @@ -119,4 +125,32 @@ public void configure(WebSecurity web) throws Exception {
}
};
}

@Component
@Profile("dev")
public static class SampleAdminUsersCreator {

@Autowired
AdminUserRepository adminUserRepository;

@Transactional
@PostConstruct
public void createSampleAdminUsers() {
if (adminUserRepository.count() == 0L) {
AdminRole role = new AdminRole();
role.setName("ROLE_ADMIN");
AdminUser user = new AdminUser();
user.setUsername("admin");
user.setPassword("{noop}adminpass");

//The complexity of managing bi-directional many-to-many. TODO: encapsulate this association
//managing logic into domain model itself
role.getAdmins().add(user);
user.getRoles().add(role);

adminUserRepository.save(user);
}
}
}
}

4 changes: 2 additions & 2 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Logging Configuration
#logging.config=classpath:log4j2.xml

#logging.level.org.springframework.security=DEBUG
#logging.level.org.springframework.security=INFO
logging.level.org.springframework=INFO
logging.level.edu.internet2.tier.shibboleth.admin.ui=INFO

Expand Down Expand Up @@ -49,7 +49,7 @@ shibui.logout-url=/dashboard

# spring.profiles.active=default

#shibui.default-password=pass
#shibui.default-password={noop}pass

shibui.metadata-sources-ui-schema-location=classpath:metadata-sources-ui-schema.json
shibui.entity-attributes-filters-ui-schema-location=classpath:entity-attributes-filters-ui-schema.json
Expand Down

0 comments on commit 1aba1fc

Please sign in to comment.