use of org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl in project BroadleafCommerce by BroadleafCommerce.
the class AdminUserDataProvider method createAdminUser.
@DataProvider(name = "setupAdminUser")
public static Object[][] createAdminUser() {
AdminUser adminUser = new AdminUserImpl();
adminUser.setName("TestAdminUserName");
adminUser.setLogin("TestAdminUserLogin");
adminUser.setEmail("TestAdminUserEmail@broadleafcommerce.org");
adminUser.setPassword("TestAdminUserPassword");
return new Object[][] { new Object[] { adminUser } };
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl in project BroadleafCommerce by BroadleafCommerce.
the class AdminUserProvisioningServiceImpl method provisionAdminUser.
@Override
public AdminUserDetails provisionAdminUser(BroadleafExternalAuthenticationUserDetails details) {
HashSet<String> parsedRoleNames = parseRolesFromUserDetails(details);
HashSet<AdminRole> parsedRoles = new HashSet<AdminRole>();
List<AdminRole> adminRoles = securityService.readAllAdminRoles();
if (adminRoles != null) {
for (AdminRole role : adminRoles) {
if (parsedRoleNames.contains(role.getName())) {
parsedRoles.add(role);
}
}
}
Set<SimpleGrantedAuthority> adminUserAuthorities = extractAdminUserAuthorities(parsedRoles);
AdminUser adminUser = securityService.readAdminUserByUserName(details.getUsername());
if (adminUser == null) {
adminUser = new AdminUserImpl();
adminUser.setLogin(details.getUsername());
}
if (StringUtils.isNotBlank(details.getEmail())) {
adminUser.setEmail(details.getEmail());
}
StringBuilder name = new StringBuilder();
if (StringUtils.isNotBlank(details.getFirstName())) {
name.append(details.getFirstName()).append(" ");
}
if (StringUtils.isNotBlank(details.getLastName())) {
name.append(details.getLastName());
}
String fullName = name.toString();
if (StringUtils.isNotBlank(fullName)) {
adminUser.setName(fullName);
} else {
adminUser.setName(details.getUsername());
}
// set the roles for the admin user to our new set of roles
adminUser.setAllRoles(new HashSet<>(parsedRoles));
// Add optional support for things like Multi-Tenant, etc...
adminExternalLoginExtensionManager.getProxy().performAdditionalAuthenticationTasks(adminUser, details);
// Save the user data and all of the roles...
adminUser = securityService.saveAdminUser(adminUser);
return new AdminUserDetails(adminUser.getId(), details.getUsername(), "", true, true, true, true, adminUserAuthorities);
}
Aggregations