Admin or user

Report a typo

The code below checks if the current user has the admin role or not. If the user is admin, the if block is executed, otherwise the else block is executed.

Your task is to find two mistakes and select all options that will fix the code.

Java
@GetMapping("/users")
public void users(UserDetails details) {
    String roleAdmin = "ROLE_ADMIN";

    if (details.getAuthorities().contains(roleAdmin)) {
        // admin related code
    } else {
        // user related code
    }
}
Kotlin
@GetMapping("/users")
fun users(details: UserDetails) {
    val roleAdmin = "ROLE_ADMIN"

    if (details.authorities.contains(roleAdmin)) {
        // admin related code
    } else {
        // user related code
    }
}
Select one or more options from the list
___

Create a free account to access the full topic