|
|
@ -72,7 +72,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isUserAuthorized(DeviceIdentifier deviceIdentifier, String username, String permission)
|
|
|
|
public boolean isUserAuthorized(DeviceIdentifier deviceIdentifier, String username, String[] groupPermissions)
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
@ -84,10 +84,16 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//check for group permissions
|
|
|
|
//check for group permissions
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (permission == null || permission.isEmpty()) {
|
|
|
|
if (groupPermissions == null || groupPermissions.length == 0) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return checkGroupsPermission(username, tenantId, permission);
|
|
|
|
for (String groupPermission : groupPermissions) {
|
|
|
|
|
|
|
|
if (!checkGroupsPermission(username, tenantId, groupPermission)) {
|
|
|
|
|
|
|
|
//if at least one fails, authorization fails
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (GroupManagementException | UserStoreException e) {
|
|
|
|
} catch (GroupManagementException | UserStoreException e) {
|
|
|
|
throw new DeviceAccessAuthorizationException("Unable to authorize the access to device : " +
|
|
|
|
throw new DeviceAccessAuthorizationException("Unable to authorize the access to device : " +
|
|
|
|
deviceIdentifier.getId() + " for the user : " +
|
|
|
|
deviceIdentifier.getId() + " for the user : " +
|
|
|
@ -101,6 +107,12 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
return isUserAuthorized(deviceIdentifier, username, null);
|
|
|
|
return isUserAuthorized(deviceIdentifier, username, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isUserAuthorized(DeviceIdentifier deviceIdentifier, String[] groupPermissions)
|
|
|
|
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
|
|
|
|
return isUserAuthorized(deviceIdentifier, this.getUserName(), groupPermissions);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isUserAuthorized(DeviceIdentifier deviceIdentifier) throws DeviceAccessAuthorizationException {
|
|
|
|
public boolean isUserAuthorized(DeviceIdentifier deviceIdentifier) throws DeviceAccessAuthorizationException {
|
|
|
|
return isUserAuthorized(deviceIdentifier, this.getUserName(), null);
|
|
|
|
return isUserAuthorized(deviceIdentifier, this.getUserName(), null);
|
|
|
@ -108,7 +120,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public DeviceAuthorizationResult isUserAuthorized(List<DeviceIdentifier> deviceIdentifiers, String username,
|
|
|
|
public DeviceAuthorizationResult isUserAuthorized(List<DeviceIdentifier> deviceIdentifiers, String username,
|
|
|
|
String permission)
|
|
|
|
String[] groupPermissions)
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
@ -121,11 +133,19 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
deviceAuthorizationResult.addAuthorizedDevice(deviceIdentifier);
|
|
|
|
deviceAuthorizationResult.addAuthorizedDevice(deviceIdentifier);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (permission == null || permission.isEmpty()) {
|
|
|
|
if (groupPermissions == null || groupPermissions.length == 0) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//check for group permissions
|
|
|
|
//check for group permissions
|
|
|
|
if (checkGroupsPermission(username, tenantId, permission)) {
|
|
|
|
boolean isAuthorized = true;
|
|
|
|
|
|
|
|
for (String groupPermission : groupPermissions) {
|
|
|
|
|
|
|
|
if (!checkGroupsPermission(username, tenantId, groupPermission)) {
|
|
|
|
|
|
|
|
//if at least one failed, authorizations fails and break the loop
|
|
|
|
|
|
|
|
isAuthorized = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAuthorized) {
|
|
|
|
deviceAuthorizationResult.addAuthorizedDevice(deviceIdentifier);
|
|
|
|
deviceAuthorizationResult.addAuthorizedDevice(deviceIdentifier);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
deviceAuthorizationResult.addUnauthorizedDevice(deviceIdentifier);
|
|
|
|
deviceAuthorizationResult.addUnauthorizedDevice(deviceIdentifier);
|
|
|
@ -152,6 +172,12 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
return isUserAuthorized(deviceIdentifiers, this.getUserName(), null);
|
|
|
|
return isUserAuthorized(deviceIdentifiers, this.getUserName(), null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public DeviceAuthorizationResult isUserAuthorized(List<DeviceIdentifier> deviceIdentifiers, String[] groupPermissions)
|
|
|
|
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
|
|
|
|
return isUserAuthorized(deviceIdentifiers, this.getUserName(), groupPermissions);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isAdminOrDeviceOwner(String username, int tenantId, DeviceIdentifier deviceIdentifier)
|
|
|
|
private boolean isAdminOrDeviceOwner(String username, int tenantId, DeviceIdentifier deviceIdentifier)
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
throws DeviceAccessAuthorizationException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -165,11 +191,11 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkGroupsPermission(String username, int tenantId, String permission)
|
|
|
|
private boolean checkGroupsPermission(String username, int tenantId, String groupPermission)
|
|
|
|
throws GroupManagementException, UserStoreException {
|
|
|
|
throws GroupManagementException, UserStoreException {
|
|
|
|
List<DeviceGroup> groups =
|
|
|
|
List<DeviceGroup> groups =
|
|
|
|
DeviceManagementDataHolder.getInstance().getGroupManagementProviderService().getGroups(username,
|
|
|
|
DeviceManagementDataHolder.getInstance().getGroupManagementProviderService().getGroups(username,
|
|
|
|
permission);
|
|
|
|
groupPermission);
|
|
|
|
UserRealm userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
UserRealm userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
if (userRealm != null && userRealm.getAuthorizationManager() != null) {
|
|
|
|
if (userRealm != null && userRealm.getAuthorizationManager() != null) {
|
|
|
|
Iterator<DeviceGroup> groupIterator = groups.iterator();
|
|
|
|
Iterator<DeviceGroup> groupIterator = groups.iterator();
|
|
|
@ -179,7 +205,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
while (rolesIterator.hasNext()) {
|
|
|
|
while (rolesIterator.hasNext()) {
|
|
|
|
String role = rolesIterator.next();
|
|
|
|
String role = rolesIterator.next();
|
|
|
|
if (userRealm.getAuthorizationManager().isRoleAuthorized(
|
|
|
|
if (userRealm.getAuthorizationManager().isRoleAuthorized(
|
|
|
|
"Internal/group-" + deviceGroup.getId() + "-" + role, permission,
|
|
|
|
"Internal/group-" + deviceGroup.getId() + "-" + role, groupPermission,
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|