Search in sources :

Example 6 with OAuth2User

use of org.thingsboard.server.dao.oauth2.OAuth2User in project thingsboard by thingsboard.

the class BasicOAuth2ClientMapper method getOrCreateUserByClientPrincipal.

@Override
public SecurityUser getOrCreateUserByClientPrincipal(HttpServletRequest request, OAuth2AuthenticationToken token, String providerAccessToken, OAuth2Registration registration) {
    OAuth2MapperConfig config = registration.getMapperConfig();
    Map<String, Object> attributes = token.getPrincipal().getAttributes();
    String email = BasicMapperUtils.getStringAttributeByKey(attributes, config.getBasic().getEmailAttributeKey());
    OAuth2User oauth2User = BasicMapperUtils.getOAuth2User(email, attributes, config);
    return getOrCreateSecurityUserFromOAuth2User(oauth2User, registration);
}
Also used : OAuth2User(org.thingsboard.server.dao.oauth2.OAuth2User) OAuth2MapperConfig(org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)

Example 7 with OAuth2User

use of org.thingsboard.server.dao.oauth2.OAuth2User in project thingsboard by thingsboard.

the class CustomOAuth2ClientMapper method getOrCreateUserByClientPrincipal.

@Override
public SecurityUser getOrCreateUserByClientPrincipal(HttpServletRequest request, OAuth2AuthenticationToken token, String providerAccessToken, OAuth2Registration registration) {
    OAuth2MapperConfig config = registration.getMapperConfig();
    OAuth2User oauth2User = getOAuth2User(token, providerAccessToken, config.getCustom());
    return getOrCreateSecurityUserFromOAuth2User(oauth2User, registration);
}
Also used : OAuth2User(org.thingsboard.server.dao.oauth2.OAuth2User) OAuth2MapperConfig(org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)

Aggregations

OAuth2User (org.thingsboard.server.dao.oauth2.OAuth2User)7 OAuth2MapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ToString (lombok.ToString)1 StrSubstitutor (org.apache.commons.lang3.text.StrSubstitutor)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 RestTemplate (org.springframework.web.client.RestTemplate)1 User (org.thingsboard.server.common.data.User)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 DashboardId (org.thingsboard.server.common.data.id.DashboardId)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1 UserPrincipal (org.thingsboard.server.service.security.model.UserPrincipal)1