-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dataplane): integrate dataplane plugin for Device
fixes AM-4707 related-to AM-4569
- Loading branch information
Showing
23 changed files
with
395 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...ain/java/io/gravitee/am/gateway/handler/common/service/impl/DeviceGatewayServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* 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 io.gravitee.am.gateway.handler.common.service.impl; | ||
|
||
|
||
import io.gravitee.am.gateway.handler.common.service.DeviceGatewayService; | ||
import io.gravitee.am.model.Device; | ||
import io.gravitee.am.model.Domain; | ||
import io.gravitee.am.model.UserId; | ||
import io.gravitee.am.plugins.dataplane.core.DataPlaneRegistry; | ||
import io.gravitee.am.service.exception.TechnicalManagementException; | ||
import io.reactivex.rxjava3.core.Flowable; | ||
import io.reactivex.rxjava3.core.Single; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
import static io.gravitee.am.model.ReferenceType.DOMAIN; | ||
|
||
/** | ||
* @author Eric LELEU (eric.leleu at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@Slf4j | ||
@AllArgsConstructor | ||
public class DeviceGatewayServiceImpl implements DeviceGatewayService { | ||
//Ten hours | ||
private static final long DEFAULT_DEVICE_EXPIRATION_TIME_SECONDS = 10L * 60L * 60L; | ||
|
||
private DataPlaneRegistry dataPlaneRegistry; | ||
|
||
@Override | ||
public Flowable<Device> findByDomainAndUser(Domain domain, UserId userId) { | ||
return dataPlaneRegistry.getDeviceRepository(domain).findByDomainAndClientAndUser(domain.getId(), userId).onErrorResumeNext(ex -> { | ||
log.error("An error occurs while trying to find Devices by {} {}", domain, userId, ex); | ||
return Flowable.error(new TechnicalManagementException(String.format("An error occurs while trying to find Devices by %s %s", domain, userId), ex)); | ||
}); | ||
} | ||
|
||
@Override | ||
public Single<Boolean> deviceExists(Domain domain, String client, UserId user, String rememberDevice, String deviceId) { | ||
return dataPlaneRegistry.getDeviceRepository(domain).findByDomainAndClientAndUserAndDeviceIdentifierAndDeviceId(domain.getId(), client, user, rememberDevice, deviceId).isEmpty(); | ||
} | ||
|
||
@Override | ||
public Single<Device> create(Domain domain, String client, UserId user, String rememberDevice, String deviceType, Long timeExpirationSeconds, String deviceId) { | ||
long expiresAt = System.currentTimeMillis() + Optional.ofNullable(timeExpirationSeconds) | ||
.filter(time -> time > 0L) | ||
.orElse(DEFAULT_DEVICE_EXPIRATION_TIME_SECONDS) * 1000L; | ||
return dataPlaneRegistry.getDeviceRepository(domain).create(new Device() | ||
.setReferenceType(DOMAIN) | ||
.setReferenceId(domain.getId()) | ||
.setClient(client) | ||
.setUserId(user) | ||
.setDeviceIdentifierId(rememberDevice) | ||
.setType(deviceType) | ||
.setDeviceId(deviceId) | ||
.setCreatedAt(new Date()) | ||
.setExpiresAt(new Date(expiresAt)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.