From 2a525f31361520e9bb9de5c88536f74a06e92b32 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Tue, 6 Oct 2020 15:27:19 +0300 Subject: [PATCH] Implement BookStoreAuthorities class Signed-off-by: Pekka Helenius --- .../service/session/BookStoreAuthorities.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAuthorities.java diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAuthorities.java b/bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAuthorities.java new file mode 100644 index 0000000..3df78fa --- /dev/null +++ b/bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAuthorities.java @@ -0,0 +1,41 @@ +//Pekka Helenius , Fjordtek 2020 + +package com.fjordtek.bookstore.service.session; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +/** +* +* This class gets Spring Environment key property values from +* Spring property sources and inserts them into publicly +* accessible class attributes. +*

+* The attribute values of this class are primarily used, +* for instance, within @PreAuthorize annotations. +* +* @author Pekka Helenius +*/ + +@Component("BookAuth") +public class BookStoreAuthorities { + + @Autowired + private Environment env; + + public String ADMIN, HELPDESK, SALES, USER; + + @PostConstruct + private void constructAuthorities() { + this.ADMIN = env.getProperty("auth.authority.admin"); + this.HELPDESK = env.getProperty("auth.authority.helpdesk"); + this.SALES = env.getProperty("auth.authority.sales"); + this.USER = env.getProperty("auth.authority.user"); + } + +} + +