fixed null on token
This commit is contained in:
		| @@ -3,6 +3,8 @@ package de.jottyfan.bico.modules; | ||||
| import java.security.Principal; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.security.core.context.SecurityContextHolder; | ||||
| @@ -19,6 +21,8 @@ import de.jottyfan.bico.modules.profile.ProfileService; | ||||
|  */ | ||||
| public abstract class CommonController { | ||||
|  | ||||
| 	private static final Logger LOGGER = LogManager.getLogger(CommonController.class); | ||||
|  | ||||
| 	@Autowired | ||||
| 	private ProfileService profileService; | ||||
|  | ||||
| @@ -28,10 +32,15 @@ public abstract class CommonController { | ||||
| 	@ModelAttribute("hasBUrole") | ||||
| 	public Boolean hasBURole(Principal principal) { | ||||
| 		OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal; | ||||
| 		OAuth2User user = token.getPrincipal(); | ||||
| 		@SuppressWarnings("unchecked") | ||||
| 		List<String> roles = (List<String>) user.getAttributes().get("roles"); | ||||
| 		return roles.contains("Bibelunterricht"); | ||||
| 		if (token != null) { | ||||
| 			OAuth2User user = token.getPrincipal(); | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			List<String> roles = (List<String>) user.getAttributes().get("roles"); | ||||
| 			return roles.contains("Bibelunterricht"); | ||||
| 		} else { | ||||
| 			LOGGER.warn("token is null, no roles can be detected"); | ||||
| 			return false; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user