Index: trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtAuthenticationFilter.java
===================================================================
--- trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtAuthenticationFilter.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
+++ trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtAuthenticationFilter.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
@@ -0,0 +1,66 @@
+package finki.diplomska.tripplanner.security;
+
+import finki.diplomska.tripplanner.models.User;
+import finki.diplomska.tripplanner.service.impl.CustomUserDetailsServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
+import org.springframework.util.StringUtils;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+
+public class JwtAuthenticationFilter extends OncePerRequestFilter {
+    @Autowired
+    private JwtTokenProvider tokenProvider;
+
+    @Autowired
+    private CustomUserDetailsServiceImpl customUserDetailsService;
+
+    @Override
+    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
+                                    FilterChain filterChain) throws ServletException, IOException {
+
+        try {
+
+            String jwt = getJWTFromRequest(httpServletRequest);
+
+            if(StringUtils.hasText(jwt)&& tokenProvider.validateToken(jwt)){
+                Long userId = tokenProvider.getUserIdFromJWT(jwt);
+                User userDetails = customUserDetailsService.loadUserById(userId);
+
+                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
+                        userDetails, null, Collections.emptyList());
+
+                authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
+                SecurityContextHolder.getContext().setAuthentication(authentication);
+
+            }
+
+        }catch (Exception ex){
+            logger.error("Could not set user authentication in security context", ex);
+        }
+
+
+        filterChain.doFilter(httpServletRequest, httpServletResponse);
+
+    }
+
+
+
+    private String getJWTFromRequest(HttpServletRequest request){
+        String bearerToken = request.getHeader(SecurityConstants.HEADER_STRING);
+
+        if(StringUtils.hasText(bearerToken)&&bearerToken.startsWith(SecurityConstants.TOKEN_PREFIX)){
+            return bearerToken.substring(7, bearerToken.length());
+        }
+
+        return null;
+    }
+}
Index: trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtTokenProvider.java
===================================================================
--- trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtTokenProvider.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
+++ trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtTokenProvider.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
@@ -0,0 +1,63 @@
+package finki.diplomska.tripplanner.security;
+
+import finki.diplomska.tripplanner.models.User;
+import io.jsonwebtoken.*;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class JwtTokenProvider {
+    //Generate the token
+
+    public String generateToken(Authentication authentication){
+        User user = (User)authentication.getPrincipal();
+        Date now = new Date(System.currentTimeMillis());
+
+        Date expiryDate = new Date(now.getTime()+SecurityConstants.EXPIRATION_TIME);
+
+        String userId = Long.toString(user.getId());
+
+        Map<String,Object> claims = new HashMap<>();
+        claims.put("id", (Long.toString(user.getId())));
+        claims.put("username", user.getUsername());
+        claims.put("fullName", user.getFullName());
+
+        return Jwts.builder()
+                .setSubject(userId)
+                .setClaims(claims)
+                .setIssuedAt(now)
+                .setExpiration(expiryDate)
+                .signWith(SignatureAlgorithm.HS512, SecurityConstants.SECRET)
+                .compact();
+    }
+
+    //Validate the token
+    public boolean validateToken(String token){
+        try{
+            Jwts.parser().setSigningKey(SecurityConstants.SECRET).parseClaimsJws(token);
+            return true;
+        }catch (SignatureException ex){
+            System.out.println("Invalid JWT Signature");
+        }catch (MalformedJwtException ex){
+            System.out.println("Invalid JWT Token");
+        }catch (ExpiredJwtException ex){
+            System.out.println("Expired JWT token");
+        }catch (UnsupportedJwtException ex){
+            System.out.println("Unsupported JWT token");
+        }catch (IllegalArgumentException ex){
+            System.out.println("JWT claims string is empty");
+        }
+        return false;
+    }
+    //Get user Id from token
+    public Long getUserIdFromJWT(String token){
+        Claims claims = Jwts.parser().setSigningKey(SecurityConstants.SECRET).parseClaimsJws(token).getBody();
+        String id = (String)claims.get("id");
+
+        return Long.parseLong(id);
+    }
+}
Index: trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java
===================================================================
--- trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java	(revision 1ad8e64a349fcc7c996155279b16efc2cfe001dd)
+++ trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
@@ -2,6 +2,11 @@
 
 
+import finki.diplomska.tripplanner.service.impl.CustomUserDetailsServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.BeanIds;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -9,4 +14,9 @@
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+
+import static finki.diplomska.tripplanner.security.SecurityConstants.MARIADB_URL;
+import static finki.diplomska.tripplanner.security.SecurityConstants.SIGN_UP_URLS;
 
 @Configuration
@@ -21,4 +31,25 @@
     @Autowired
     private JwtAuthenticationEntryPoint unauthorizedHandler;
+
+    @Autowired
+    private CustomUserDetailsServiceImpl customUserDetailsService;
+
+    @Bean
+    public JwtAuthenticationFilter jwtAuthenticationFilter() {return  new JwtAuthenticationFilter();}
+
+
+    @Autowired
+    private BCryptPasswordEncoder bCryptPasswordEncoder;
+
+    @Override
+    protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
+        authenticationManagerBuilder.userDetailsService(customUserDetailsService).passwordEncoder(bCryptPasswordEncoder);
+    }
+
+    @Override
+    @Bean(BeanIds.AUTHENTICATION_MANAGER)
+    protected AuthenticationManager authenticationManager() throws Exception {
+        return super.authenticationManager();
+    }
 
     @Override
@@ -43,6 +74,9 @@
                         "/**/*.js"
                 ).permitAll()
-                .antMatchers("/api/users/**").permitAll()
+                .antMatchers(SIGN_UP_URLS).permitAll()
+                .antMatchers(MARIADB_URL).permitAll()
                 .anyRequest().authenticated();
+        http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
+
     }
 }
Index: trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConstants.java
===================================================================
--- trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConstants.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
+++ trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConstants.java	(revision 84d0fbb56bfbe319ba63e3327f1777ac5d841f83)
@@ -0,0 +1,10 @@
+package finki.diplomska.tripplanner.security;
+
+public class SecurityConstants {
+    public static final String SIGN_UP_URLS = "/api/users/**";
+    public static final String MARIADB_URL = "jdbc:mariadb://127.0.0.1:3306/tripplanner";
+    public static final String SECRET ="SecretKeyToGenJWTs";
+    public static final String TOKEN_PREFIX= "Bearer ";
+    public static final String HEADER_STRING = "Authorization";
+    public static final long EXPIRATION_TIME = 3000_000; //30 seconds
+}
