This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mongoose = require('mongoose'); | |
| const bcrypt = require('bcrypt-nodejs'); | |
| var UserSchema = new mongoose.Schema({ | |
| username: { | |
| type: String, | |
| required: true, | |
| unique:false | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mongoose = require('mongoose'); | |
| let LinkSchema = new mongoose.Schema({ | |
| link: { | |
| type: String, | |
| required: true, | |
| trim: true | |
| }, | |
| name: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const passport = require("passport"); | |
| const LocalStrategy = require('passport-local').Strategy; | |
| const User = require("../models/User"); | |
| // Passport JS serialize user | |
| passport.serializeUser(function (user, done) { | |
| done(null, user.email); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require("express") | |
| const passport = require("../config/passport") | |
| const validUrl = require("valid-url") | |
| const Links = require("../models/Links"); | |
| const User = require("../models/User"); | |
| let router = express.Router() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require('dotenv').config(); | |
| const express = require("express"); | |
| const path = require('path') | |
| const app = express() | |
| const hbs = require("hbs") | |
| // auth related imports | |
| const session = require('express-session'); | |
| const mongoose = require('mongoose'); | |
| const mongodbStore = require('connect-mongo')(session); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| @ConditionalOnBean(name = DEFAULT_FILTER_NAME) | |
| public DelegatingFilterProxyRegistrationBean securityFilterChainRegistration( | |
| SecurityProperties securityProperties) { | |
| DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean( | |
| DEFAULT_FILTER_NAME); | |
| registration.setOrder(securityProperties.getFilter().getOrder()); | |
| registration.setDispatcherTypes(getDispatcherTypes(securityProperties)); | |
| return registration; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) | |
| throws ServletException, IOException { | |
| // Lazily initialize the delegate if necessary. | |
| Filter delegateToUse = this.delegate; | |
| if (delegateToUse == null) { | |
| synchronized (this.delegateMonitor) { | |
| delegateToUse = this.delegate; | |
| if (delegateToUse == null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @EnableWebSecurity(debug = true) | |
| public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ | |
| @Override | |
| protected void configure(HttpSecurity http) throws Exception { | |
| http.sessionManagement().disable(); | |
| http.cors().disable(); | |
| http.csrf().disable(); | |
| http.logout().disable(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean(name = AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) | |
| public Filter springSecurityFilterChain() throws Exception { | |
| boolean hasConfigurers = this.webSecurityConfigurers != null && !this.webSecurityConfigurers.isEmpty(); | |
| boolean hasFilterChain = !this.securityFilterChains.isEmpty(); | |
| Assert.state(!(hasConfigurers && hasFilterChain), | |
| "Found WebSecurityConfigurerAdapter as well as SecurityFilterChain. Please select just one."); | |
| if (!hasConfigurers && !hasFilterChain) { | |
| WebSecurityConfigurerAdapter adapter = this.objectObjectPostProcessor | |
| .postProcess(new WebSecurityConfigurerAdapter() { | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. FilterChainProxy -> doFilter Method | |
| private void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain) | |
| throws IOException, ServletException { | |
| FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest) request); | |
| HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse) response); | |
| List<Filter> filters = getFilters(firewallRequest); | |
| if (filters == null || filters.size() == 0) { | |
| if (logger.isTraceEnabled()) { | |
| logger.trace(LogMessage.of(() -> "No security for " + requestLine(firewallRequest))); |