Remove PermissionService - unused (#1717)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.im.authentication.SpRole;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareUserProperties;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareUserProperties.User;
|
||||
import org.eclipse.hawkbit.im.authentication.PermissionService;
|
||||
import org.eclipse.hawkbit.security.DdiSecurityProperties;
|
||||
import org.eclipse.hawkbit.security.InMemoryUserAuthoritiesResolver;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
@@ -99,16 +98,6 @@ public class SecurityAutoConfiguration {
|
||||
return new InMemoryUserAuthoritiesResolver(usersToPermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return permission service to check if current user has the necessary
|
||||
* permissions.
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public PermissionService permissionService() {
|
||||
return new PermissionService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the auditor aware.
|
||||
*
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.im.authentication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
/**
|
||||
* Service to check permissions.
|
||||
*
|
||||
*/
|
||||
public class PermissionService {
|
||||
|
||||
/**
|
||||
* Checks if the given {@code permission} contains in the. In case no
|
||||
* {@code context} is available {@code false} will be returned.
|
||||
*
|
||||
* @param permission
|
||||
* the permission to check against the
|
||||
* @return {@code true} if a is available and contains the given
|
||||
* {@code permission}, otherwise {@code false}.
|
||||
* @see SpPermission
|
||||
*/
|
||||
public boolean hasPermission(final String permission) {
|
||||
final SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
final Authentication authentication = context.getAuthentication();
|
||||
if (authentication == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final GrantedAuthority authority : authentication.getAuthorities()) {
|
||||
if (authority.getAuthority().equals(permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getAllPermission() {
|
||||
final List<String> permissions = new ArrayList<>();
|
||||
final SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context == null) {
|
||||
return permissions;
|
||||
}
|
||||
final Authentication authentication = context.getAuthentication();
|
||||
if (authentication == null) {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
authentication.getAuthorities().stream().forEach(authority -> permissions.add(authority.getAuthority()));
|
||||
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least on permission of the given {@code permissions}
|
||||
* contains in the . In case no {@code context} is available {@code false}
|
||||
* will be returned.
|
||||
*
|
||||
* @param permissions
|
||||
* the permissions to check against the
|
||||
* @return {@code true} if a is available and contains the given
|
||||
* {@code permission}, otherwise {@code false}.
|
||||
* @see SpPermission
|
||||
*/
|
||||
public boolean hasAtLeastOnePermission(final List<String> permissions) {
|
||||
final SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Authentication authentication = context.getAuthentication();
|
||||
if (authentication == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final GrantedAuthority authority : authentication.getAuthorities()) {
|
||||
for (final String permission : permissions) {
|
||||
if (authority.getAuthority().equals(permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user