0
0
Spring Bootframework~10 mins

Custom permission evaluator in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class that implements PermissionEvaluator.

Spring Boot
public class CustomPermissionEvaluator implements [1] { }
Drag options to blanks, or click blank then click option'
AGrantedAuthority
BPermissionEvaluator
CAuthenticationProvider
DUserDetailsService
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated interfaces like UserDetailsService.
Forgetting to implement PermissionEvaluator.
2fill in blank
medium

Complete the method signature to override the hasPermission method with target domain object.

Spring Boot
@Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, [1] permission) { return false; }
Drag options to blanks, or click blank then click option'
AString
BObject
Cint
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using Object or boolean instead of String for permission.
Mismatching method signature causing override errors.
3fill in blank
hard

Fix the error in the method to check if the user has the required permission string.

Spring Boot
public boolean hasPermission(Authentication authentication, Object targetDomainObject, String permission) {
    return authentication.getAuthorities().stream()
        .anyMatch(auth -> auth.getAuthority().[1](permission));
}
Drag options to blanks, or click blank then click option'
Aequals
Bcontains
CequalsIgnoreCase
DstartsWith
Attempts:
3 left
💡 Hint
Common Mistakes
Using contains or startsWith which may cause false positives.
Using equalsIgnoreCase which may not be desired for case-sensitive permissions.
4fill in blank
hard

Fill both blanks to implement the second hasPermission method that checks permission by target ID and type.

Spring Boot
@Override
public boolean hasPermission(Authentication authentication, Serializable targetId, [1] targetType, [2] permission) {
    // Custom logic here
    return false;
}
Drag options to blanks, or click blank then click option'
AString
BObject
CSerializable
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types like Object or Serializable for these parameters.
Confusing targetId type with targetType.
5fill in blank
hard

Fill all three blanks to create a map of permissions for a user with filtering by permission string.

Spring Boot
Map<String, Boolean> permissions = user.getRoles().stream()
    .flatMap(role -> role.getPermissions().stream())
    .filter(p -> p.getName().[1]([2]))
    .collect(Collectors.toMap(
        p -> p.getName(),
        p -> true
    ));

boolean hasAccess = permissions.getOrDefault([3], false);
Drag options to blanks, or click blank then click option'
Aequals
B"read"
C"write"
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using equals instead of contains for filtering.
Using wrong permission string in getOrDefault.