fixed null on token
This commit is contained in:
		| @@ -8,7 +8,7 @@ plugins { | |||||||
| } | } | ||||||
|  |  | ||||||
| group = 'de.jottyfan.bico' | group = 'de.jottyfan.bico' | ||||||
| version = '0.0.6' | version = '0.0.7' | ||||||
|  |  | ||||||
| description = """BibleClassOrganizer""" | description = """BibleClassOrganizer""" | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,8 @@ package de.jottyfan.bico.modules; | |||||||
| import java.security.Principal; | import java.security.Principal; | ||||||
| import java.util.List; | 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.Autowired; | ||||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||||
| import org.springframework.security.core.context.SecurityContextHolder; | import org.springframework.security.core.context.SecurityContextHolder; | ||||||
| @@ -19,6 +21,8 @@ import de.jottyfan.bico.modules.profile.ProfileService; | |||||||
|  */ |  */ | ||||||
| public abstract class CommonController { | public abstract class CommonController { | ||||||
|  |  | ||||||
|  | 	private static final Logger LOGGER = LogManager.getLogger(CommonController.class); | ||||||
|  |  | ||||||
| 	@Autowired | 	@Autowired | ||||||
| 	private ProfileService profileService; | 	private ProfileService profileService; | ||||||
|  |  | ||||||
| @@ -28,10 +32,15 @@ public abstract class CommonController { | |||||||
| 	@ModelAttribute("hasBUrole") | 	@ModelAttribute("hasBUrole") | ||||||
| 	public Boolean hasBURole(Principal principal) { | 	public Boolean hasBURole(Principal principal) { | ||||||
| 		OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal; | 		OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal; | ||||||
|  | 		if (token != null) { | ||||||
| 			OAuth2User user = token.getPrincipal(); | 			OAuth2User user = token.getPrincipal(); | ||||||
| 			@SuppressWarnings("unchecked") | 			@SuppressWarnings("unchecked") | ||||||
| 			List<String> roles = (List<String>) user.getAttributes().get("roles"); | 			List<String> roles = (List<String>) user.getAttributes().get("roles"); | ||||||
| 			return roles.contains("Bibelunterricht"); | 			return roles.contains("Bibelunterricht"); | ||||||
|  | 		} else { | ||||||
|  | 			LOGGER.warn("token is null, no roles can be detected"); | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
| @@ -9,9 +9,6 @@ spring.datasource.password = ${db.password} | |||||||
|  |  | ||||||
| server.servlet.context-path = ${my.context-path:/BiCO} | server.servlet.context-path = ${my.context-path:/BiCO} | ||||||
|  |  | ||||||
| # for development only |  | ||||||
| server.port = ${server.port} |  | ||||||
|  |  | ||||||
| # nextcloud open ID connection | # nextcloud open ID connection | ||||||
| spring.security.oauth2.client.provider.nextcloud.issuer-uri = ${nextcloud.issuer-uri} | spring.security.oauth2.client.provider.nextcloud.issuer-uri = ${nextcloud.issuer-uri} | ||||||
| spring.security.oauth2.client.registration.nextcloud.client-id = ${nextcloud.client-id} | spring.security.oauth2.client.registration.nextcloud.client-id = ${nextcloud.client-id} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user