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"); + } + +} + +