use of org.broadleafcommerce.common.security.BroadleafExternalAuthenticationUserDetails in project BroadleafCommerce by BroadleafCommerce.
the class AdminExternalLoginStateFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
if (request.getSession(true).getAttribute(BLC_ADMIN_PROVISION_USER_CHECK) == null) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
if (authentication.getPrincipal() instanceof UserDetails) {
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
if (userDetails != null && userDetails.getUsername() != null) {
AdminUser user = adminSecurityService.readAdminUserByUserName(userDetails.getUsername());
if (userDetails instanceof BroadleafExternalAuthenticationUserDetails) {
BroadleafExternalAuthenticationUserDetails broadleafUser = (BroadleafExternalAuthenticationUserDetails) userDetails;
if (user == null) {
// Provision a new user...
user = (AdminUser) entityConfiguration.createEntityInstance(AdminUser.class.getName());
}
saveAdminUser(broadleafUser, user);
request.getSession().setAttribute(BLC_ADMIN_PROVISION_USER_CHECK, Boolean.TRUE);
}
}
}
}
}
filterChain.doFilter(servletRequest, servletResponse);
}
use of org.broadleafcommerce.common.security.BroadleafExternalAuthenticationUserDetails in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafActiveDirectoryUserDetailsMapper method mapUserFromContext.
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
Collection<GrantedAuthority> newAuthorities = new HashSet<GrantedAuthority>();
if (roleNameSubstitutions != null && !roleNameSubstitutions.isEmpty()) {
for (GrantedAuthority authority : authorities) {
if (roleNameSubstitutions.containsKey(authority.getAuthority())) {
String[] roles = roleNameSubstitutions.get(authority.getAuthority());
for (String role : roles) {
newAuthorities.add(new SimpleGrantedAuthority(role.trim()));
}
if (additiveRoleNameSubstitutions) {
newAuthorities.add(authority);
}
} else {
newAuthorities.add(authority);
}
}
} else {
newAuthorities.addAll(authorities);
}
String email = (String) ctx.getObjectAttribute("mail");
UserDetails userDetails = null;
if (useEmailAddressAsUsername) {
if (email != null) {
userDetails = super.mapUserFromContext(ctx, email, newAuthorities);
}
}
if (userDetails == null) {
userDetails = super.mapUserFromContext(ctx, username, newAuthorities);
}
String password = userDetails.getPassword();
if (password == null) {
password = userDetails.getUsername();
}
BroadleafExternalAuthenticationUserDetails broadleafUser = new BroadleafExternalAuthenticationUserDetails(userDetails.getUsername(), password, userDetails.getAuthorities());
broadleafUser.setFirstName((String) ctx.getObjectAttribute("givenName"));
broadleafUser.setLastName((String) ctx.getObjectAttribute("sn"));
broadleafUser.setEmail(email);
return broadleafUser;
}
use of org.broadleafcommerce.common.security.BroadleafExternalAuthenticationUserDetails in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminLdapUserDetailsMapper method mapUserFromContext.
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
String email = (String) ctx.getObjectAttribute("mail");
String firstName = (String) ctx.getObjectAttribute("givenName");
String lastName = (String) ctx.getObjectAttribute("sn");
BroadleafExternalAuthenticationUserDetails details = new BroadleafExternalAuthenticationUserDetails(username, "", authorities);
details.setEmail(email);
details.setFirstName(firstName);
details.setLastName(lastName);
details.setSite(determineSite(ctx, username, authorities));
return provisioningService.provisionAdminUser(details);
}
Aggregations