<commit_before>package org.ossim.omar

import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserDetailsService
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.security.core.authority.GrantedAuthorityImpl
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils

class CustomUserDetailsService implements GrailsUserDetailsService
{

  static transactional = true
  private static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]

  UserDetails loadUserByUsername(String username, boolean loadRoles)
  {
    return loadUserByUsername(username)
  }

  UserDetails loadUserByUsername(String username)
  {
    SecUser.withTransaction { status ->

      SecUser user = SecUser.findByUsername(username)

      if ( !user ) throw new UsernameNotFoundException('User not found', username)

      def authorities = user.authorities.collect {new GrantedAuthorityImpl(it.authority)}

      return new CustomUserDetails(user.username, user.password, user.enabled,
              !user.accountExpired, !user.passwordExpired,
              !user.accountLocked, authorities ?: NO_ROLES, user.id,
              "${user.userRealName} ${user.email}")
    }
  }
}<commit_msg>Made ROLE_USER the default for newly created users.<commit_after>package org.ossim.omar

import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserDetailsService
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.security.core.authority.GrantedAuthorityImpl
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.springframework.security.core.GrantedAuthority

class CustomUserDetailsService implements GrailsUserDetailsService
{

  static transactional = true
  private static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]
  private static final List USER_ROLE =[new GrantedAuthorityImpl("ROLE_USER")] as GrantedAuthority[]

  UserDetails loadUserByUsername(String username, boolean loadRoles)
  {
    return loadUserByUsername(username)
  }

  UserDetails loadUserByUsername(String username)
  {
    SecUser.withTransaction { status ->

      SecUser user = SecUser.findByUsername(username)

      if ( !user ) throw new UsernameNotFoundException('User not found', username)

      def authorities = user.authorities.collect {new GrantedAuthorityImpl(it.authority)}

      return new CustomUserDetails(user.username, user.password, user.enabled,
              !user.accountExpired, !user.passwordExpired,
              !user.accountLocked, authorities ?: USER_ROLE, user.id,
              "${user.userRealName} ${user.email}")
    }
  }
}
{'fraction_non_alphanumeric': 0.0808362369337979, 'fraction_numerical': 0.0, 'mean_word_length': 4.907407407407407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3026043', 'n_tokens_mistral': 791, 'n_tokens_neox': 774, 'n_words': 152}