Как изменить данные аутентификации сеанса в Spring Security и Google OAuth - PullRequest
0 голосов
/ 05 февраля 2020

Я новичок в Spring-Security. Допустим, я настроил аутентификацию с помощью Google oauth-провайдера. Каждый раз, когда я хочу получить детали, я не хочу, например, user как myUser, но с некоторыми ха sh, такими как: myUser54h4gh45h4. Я не спрашиваю, как использовать хеширование, но где в конфигурации мне нужно передать его. Как добиться этого в конфигурации только один раз и не менять принципала пользователя каждый раз при получении подробностей. Причина в том, что я не могу вставить необработанные данные Google в базу данных.

@Configuration
@EnableOAuth2Sso
@EnableWebSecurity
public class WebSecurityConfig  extends WebSecurityConfigurerAdapter{

protected void configure(HttpSecurity http) throws Exception {

    http
         .cors()
         .and()
           .authorizeRequests()
           .antMatchers("/login**", "/webjars/**", "/error**")
         .permitAll()
         .and()
           .authorizeRequests().anyRequest().authenticated()
         .and()
            .logout()
            .logoutSuccessUrl("/")
            .permitAll()
            .clearAuthentication(true)
            .deleteCookies("JSESSIONID")
            .invalidateHttpSession(true)
        .and()
        .csrf()
       .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
}
@GetMapping("/messages")
    public String process3(OAuth2Authentication oauth, Model model) {

        List<Person> list = new ArrayList<>();
        try {
        // i want this to be 'myUser8383bkbhk4' not 'myUser'
        String username = oauth.getPrincipal().toString();  


        Person person = personRepository.getSinglePerson(username);
        list = personRepository.getDistinctRecipient(person.getId());
        list.remove(person);

        model.addAttribute("counts", list);
        model.addAttribute("username", username);
        } catch (Exception e) {
            //
        }

        return "list";
    }
security.oauth2.client.client-id=XXXXXX
security.oauth2.client.client-secret=jXXXXXXXX

security.oauth2.client.access-token-uri=https://oauth2.googleapis.com/token
security.oauth2.client.user-authorization-uri=https://accounts.google.com/o/oauth2/v2/auth
security.oauth2.resource.user-info-uri=https://openidconnect.googleapis.com/v1/userinfo
security.oauth2.client.scope=openid, email, profile
...