Added repository and dao for OAuth2ClientRegistration
This commit is contained in:
parent
d7ff230bbd
commit
e8bf9b45ef
@ -99,6 +99,50 @@ public class OAuth2ClientRegistrationEntity extends BaseSqlEntity<OAuth2ClientRe
|
||||
super();
|
||||
}
|
||||
|
||||
public OAuth2ClientRegistrationEntity(OAuth2ClientRegistration clientRegistration) {
|
||||
if (clientRegistration.getId() != null) {
|
||||
this.setUuid(clientRegistration.getId().getId());
|
||||
}
|
||||
this.registrationId = clientRegistration.getRegistrationId();
|
||||
this.clientId = clientRegistration.getClientId();
|
||||
this.clientSecret = clientRegistration.getClientSecret();
|
||||
this.authorizationUri = clientRegistration.getAuthorizationUri();
|
||||
this.tokenUri = clientRegistration.getTokenUri();
|
||||
this.redirectUriTemplate = clientRegistration.getRedirectUriTemplate();
|
||||
this.scope = clientRegistration.getScope();
|
||||
this.authorizationGrantType = clientRegistration.getAuthorizationGrantType();
|
||||
this.userInfoUri = clientRegistration.getUserInfoUri();
|
||||
this.userNameAttribute = clientRegistration.getUserNameAttribute();
|
||||
this.jwkSetUri = clientRegistration.getJwkSetUri();
|
||||
this.clientAuthenticationMethod = clientRegistration.getClientAuthenticationMethod();
|
||||
this.clientName = clientRegistration.getClientName();
|
||||
this.loginButtonLabel = clientRegistration.getLoginButtonLabel();
|
||||
this.loginButtonIcon = clientRegistration.getLoginButtonIcon();
|
||||
OAuth2MapperConfig mapperConfig = clientRegistration.getMapperConfig();
|
||||
if (mapperConfig != null) {
|
||||
this.allowUserCreation = mapperConfig.isAllowUserCreation();
|
||||
this.activateUser = mapperConfig.isActivateUser();
|
||||
this.type = mapperConfig.getType();
|
||||
OAuth2BasicMapperConfig basicConfig = mapperConfig.getBasicConfig();
|
||||
if (basicConfig != null) {
|
||||
this.emailAttributeKey = basicConfig.getEmailAttributeKey();
|
||||
this.firstNameAttributeKey = basicConfig.getFirstNameAttributeKey();
|
||||
this.lastNameAttributeKey = basicConfig.getLastNameAttributeKey();
|
||||
this.tenantNameStrategy = basicConfig.getTenantNameStrategy();
|
||||
this.tenantNamePattern = basicConfig.getTenantNamePattern();
|
||||
this.customerNamePattern = basicConfig.getCustomerNamePattern();
|
||||
this.defaultDashboardName = basicConfig.getDefaultDashboardName();
|
||||
this.alwaysFullScreen = basicConfig.isAlwaysFullScreen();
|
||||
}
|
||||
OAuth2CustomMapperConfig customConfig = mapperConfig.getCustomConfig();
|
||||
if (customConfig != null){
|
||||
this.url = customConfig.getUrl();
|
||||
this.username = customConfig.getUsername();
|
||||
this.password = customConfig.getPassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2ClientRegistration toData() {
|
||||
return OAuth2ClientRegistration.builder()
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package org.thingsboard.server.dao.oauth2;
|
||||
|
||||
import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OAuth2ClientRegistrationDao {
|
||||
List<OAuth2ClientRegistration> find();
|
||||
|
||||
OAuth2ClientRegistration findById(String registrationId);
|
||||
|
||||
OAuth2ClientRegistration save(OAuth2ClientRegistration clientRegistration);
|
||||
|
||||
boolean removeById(String registrationId);
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright © 2016-2020 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.dao.sql.oauth2;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistration;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.DaoUtil;
|
||||
import org.thingsboard.server.dao.model.sql.OAuth2ClientRegistrationEntity;
|
||||
import org.thingsboard.server.dao.oauth2.OAuth2ClientRegistrationDao;
|
||||
import org.thingsboard.server.dao.sql.JpaAbstractDao;
|
||||
import org.thingsboard.server.dao.util.SqlDao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@SqlDao
|
||||
@RequiredArgsConstructor
|
||||
public class JpaOAuth2ClientRegistrationDao implements OAuth2ClientRegistrationDao {
|
||||
private final OAuth2ClientRegistrationRepository repository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OAuth2ClientRegistration save(OAuth2ClientRegistration clientRegistration) {
|
||||
OAuth2ClientRegistrationEntity entity;
|
||||
try {
|
||||
entity = new OAuth2ClientRegistrationEntity(clientRegistration);
|
||||
} catch (Exception e) {
|
||||
log.error("Can't create entity for domain object {}", clientRegistration, e);
|
||||
throw new IllegalArgumentException("Can't create entity for domain object {" + clientRegistration + "}", e);
|
||||
}
|
||||
log.debug("Saving entity {}", entity);
|
||||
entity = repository.save(entity);
|
||||
return DaoUtil.getData(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OAuth2ClientRegistration> find() {
|
||||
List<OAuth2ClientRegistrationEntity> entities = Lists.newArrayList(repository.findAll());
|
||||
return DaoUtil.convertDataList(entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2ClientRegistration findById(String registrationId) {
|
||||
log.debug("Get entity by registration id {}", registrationId);
|
||||
Optional<OAuth2ClientRegistrationEntity> entity = repository.findByRegistrationId(registrationId);
|
||||
return DaoUtil.getData(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeById(String registrationId) {
|
||||
repository.deleteByRegistrationId(registrationId);
|
||||
log.debug("Remove request: {}", registrationId);
|
||||
return !repository.existsByRegistrationId(registrationId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright © 2016-2020 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.dao.sql.oauth2;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.thingsboard.server.dao.model.sql.OAuth2ClientRegistrationEntity;
|
||||
import org.thingsboard.server.dao.util.SqlDao;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@SqlDao
|
||||
public interface OAuth2ClientRegistrationRepository extends CrudRepository<OAuth2ClientRegistrationEntity, String> {
|
||||
Optional<OAuth2ClientRegistrationEntity> findByRegistrationId(String registrationId);
|
||||
int deleteByRegistrationId(String registrationId);
|
||||
boolean existsByRegistrationId(String registrationId);
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user