Java Code Examples for org.springframework.security.oauth2.core.oidc.user.OidcUser#getEmail()

The following examples show how to use org.springframework.security.oauth2.core.oidc.user.OidcUser#getEmail() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDetailsFormatter.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
public static UserDetails getCurrentUser() {
    final SecurityContext context = (SecurityContext) VaadinService.getCurrentRequest().getWrappedSession()
            .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
    Authentication authentication = context.getAuthentication();
    if (authentication instanceof OAuth2AuthenticationToken) {
        OidcUser oidcUser = (OidcUser) authentication.getPrincipal();
        Object details = authentication.getDetails();
        String tenant = "DEFAULT";
        if (details instanceof TenantAwareAuthenticationDetails) {
            tenant = ((TenantAwareAuthenticationDetails) details).getTenant();
        }
        return new UserPrincipal(oidcUser.getPreferredUsername(), "***", oidcUser.getGivenName(),
                oidcUser.getFamilyName(), oidcUser.getPreferredUsername(), oidcUser.getEmail(), tenant,
                oidcUser.getAuthorities());
    } else {
        return (UserDetails) authentication.getPrincipal();
    }
}
 
Example 2
Source File: OidcUserMapperImpl.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void verifyOidcUser(OidcUser oidcUser) {
  if (oidcUser.getEmail() == null) {
    throw new OidcUserMissingEmailException(oidcUser);
  }
  Boolean emailVerified = oidcUser.getEmailVerified();
  if (emailVerified != null && !emailVerified) {
    throw new OidcUserEmailVerificationException(oidcUser);
  }
}
 
Example 3
Source File: RoleAwareOAuth2UserService.java    From ods-provisioning-app with Apache License 2.0 4 votes vote down vote up
public static String resolveUsername(OidcUser oidcUser, boolean useEmailClaimAsUserName) {
  Assert.notNull(oidcUser, "Parameter 'oidcUser' is null!");
  return useEmailClaimAsUserName ? oidcUser.getEmail() : oidcUser.getName();
}