Ignore:
Timestamp:
03/13/23 00:58:07 (16 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
9050790
Parents:
2b0a4db
Message:

Add admin page initial work.

Location:
src/main/java/edu/gjoko/schedlr/config
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/config/AppFilter.java

    r2b0a4db r46fd0c7  
    44import org.springframework.security.core.context.SecurityContextImpl;
    55import org.springframework.security.core.userdetails.UserDetails;
     6import org.springframework.util.StringUtils;
    67import org.springframework.web.filter.GenericFilterBean;
    78
     
    2324        HttpSession session = httpServletRequest.getSession(false);
    2425
     26        if(httpServletRequest.getRequestURI().endsWith(".js") || httpServletRequest.getRequestURI().endsWith(".css")) {
     27            filterChain.doFilter(servletRequest, servletResponse);
     28            return;
     29        }
    2530        if(session != null) {
    2631            Map<String, String> roleTargetUrlMap = new HashMap<>();
    27             roleTargetUrlMap.put("ADMIN", "/date");
    28             roleTargetUrlMap.put("CUSTOMER", "/number");
    29             roleTargetUrlMap.put("BUSINESS_OWNER", "");
     32            roleTargetUrlMap.put("ADMIN", "/admin");
     33            roleTargetUrlMap.put("CUSTOMER", "/homepage");
     34            roleTargetUrlMap.put("BUSINESS_OWNER", "/business_homepage");
    3035            SecurityContextImpl sci = (SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT");
    3136            if(sci != null) {
     
    3439                for (final GrantedAuthority grantedAuthority : authorities) {
    3540                    String authorityName = grantedAuthority.getAuthority();
    36                     if("DATE".equalsIgnoreCase(authorityName)) {
    37                         servletRequest.getRequestDispatcher("date").forward(servletRequest, servletResponse);
    38                         return;
    39                     } else if("GUESS_NUMBER".equalsIgnoreCase(authorityName)) {
    40                         try {
    41                             servletRequest.getRequestDispatcher("number").forward(servletRequest, servletResponse);
    42                         } catch (Exception e) {
    43                             e.printStackTrace();
    44                         }
    45 
     41                    String page = "";
     42                    switch (authorityName) {
     43                        case "ADMIN":
     44                            page = "/admin";
     45                            break;
     46                        case "CUSTOMER":
     47                        case "BUSINESS_OWNER":
     48                            page = "/homepage";
     49                            break;
     50                        default:
     51                            break;
     52                    }
     53                    if(page != null && !page.trim().isEmpty()) {
     54                        servletRequest.getRequestDispatcher(page).forward(servletRequest, servletResponse);
    4655                        return;
    4756                    }
  • src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java

    r2b0a4db r46fd0c7  
    6060                .antMatchers("/register_business").permitAll()
    6161                .antMatchers("/api/nomenclatures/*").permitAll()
     62                .antMatchers("/api/business").permitAll()
    6263                .antMatchers("/homepage").permitAll()
    6364                .antMatchers("/css/**").permitAll()
  • src/main/java/edu/gjoko/schedlr/config/MvcConfig.java

    r2b0a4db r46fd0c7  
    22
    33import org.springframework.context.annotation.Configuration;
     4import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    45import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    56import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
     
    1415        registry.addViewController("/register_business").setViewName("register_business");
    1516        registry.addViewController("/homepage").setViewName("homepage");
     17        registry.addViewController("/admin").setViewName("admin");
    1618    }
    1719
    18 
     20    @Override
     21    public void addResourceHandlers(ResourceHandlerRegistry registry) {
     22        registry.addResourceHandler("/resources/**")
     23                .addResourceLocations("/resources/");
     24    }
    1925}
Note: See TracChangeset for help on using the changeset viewer.