Skip to content

Commit

Permalink
Add check if device is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored and Coduz committed Nov 24, 2022
1 parent a372f90 commit b9b19cc
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
import org.eclipse.kapua.service.authentication.KapuaAuthenticationErrorCodes;
import org.eclipse.kapua.service.authentication.shiro.KapuaAuthenticationException;
import org.eclipse.kapua.service.authentication.token.AccessToken;
import org.eclipse.kapua.service.device.registry.Device;
import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
import org.eclipse.kapua.service.device.registry.DeviceStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -156,6 +159,8 @@ public class KapuaSecurityBrokerFilter extends BrokerFilter {
private AuthenticationService authenticationService = KapuaLocator.getInstance().getService(AuthenticationService.class);
private CredentialsFactory credentialsFactory = KapuaLocator.getInstance().getFactory(CredentialsFactory.class);
private AccountService accountService = KapuaLocator.getInstance().getService(AccountService.class);
private DeviceRegistryService
deviceRegistryService = KapuaLocator.getInstance().getService(DeviceRegistryService.class);

private Map<String, Object> options;

Expand Down Expand Up @@ -455,6 +460,16 @@ protected void addExternalConnection(ConnectionContext context, ConnectionInfo i
kapuaSecurityContext.updateOldConnectionId(CONNECTION_MAP.get(kapuaSecurityContext.getFullClientId()));
loginShiroLoginTimeContext.stop();

Device device = KapuaSecurityUtils.doPrivileged(() ->
deviceRegistryService.findByClientId(
accessToken.getScopeId(), info.getClientId()
)
);
if (DeviceStatus.DISABLED.equals(device.getStatus())) {
logger.warn("Device {} is disabled", info.getClientId());
throw new SecurityException("Device is disabled");
}

CONNECTION_MAP.put(kapuaSecurityContext.getFullClientId(), info.getConnectionId().getValue());

buildAuthorization(kapuaSecurityContext, authenticator.connect(kapuaSecurityContext));
Expand Down

0 comments on commit b9b19cc

Please sign in to comment.