// Path: src/main/java/se/omegapoint/facepalm/client/security/DbAuthenticationProvider.java
// public class DbAuthenticationProvider implements AuthenticationProvider {
// 
//     private final UserRepository userRepository;
// 
//     public DbAuthenticationProvider(final UserRepository userRepository) {
//         this.userRepository = notNull(userRepository);
//     }
// 
//     @Override
//     public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
//         final UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
//         final String username = (String) token.getPrincipal();
//         final String password = (String) token.getCredentials();
// 
//         final Optional<User> user = userRepository.findByNameAndPassword(username, password);
// 
//         return user.map(u -> new UsernamePasswordAuthenticationToken(new AuthenticatedUser(u.username), null, emptyList()))
//                 .orElse(null);
//     }
// 
//     @Override
//     public boolean supports(final Class<?> authentication) {
//         return authentication.isAssignableFrom(UsernamePasswordAuthenticationToken.class);
//     }
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/domain/event/EventService.java
// public interface EventService {
//     void publish(ApplicationEvent event);
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/domain/repository/UserRepository.java
// public interface UserRepository {
//     Optional<User> findByUsername(final String username);
// 
//     Set<User> findFriendsFor(String username);
// 
//     Optional<User> findByNameAndPassword(final String username, final String password);
// 
//     List<User> findLike(String value);
// 
//     void addFriend(String user, String friend);
// 
//     void addUser(NewUserCredentials credentials);
// 
//     boolean usersAreFriends(String userA, String userB);
// }


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import se.omegapoint.facepalm.client.security.DbAuthenticationProvider;
import se.omegapoint.facepalm.domain.event.EventService;
import se.omegapoint.facepalm.domain.repository.UserRepository;
/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package se.omegapoint.facepalm.client.config;


@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
// Path: src/main/java/se/omegapoint/facepalm/client/security/DbAuthenticationProvider.java
// public class DbAuthenticationProvider implements AuthenticationProvider {
// 
//     private final UserRepository userRepository;
// 
//     public DbAuthenticationProvider(final UserRepository userRepository) {
//         this.userRepository = notNull(userRepository);
//     }
// 
//     @Override
//     public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
//         final UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
//         final String username = (String) token.getPrincipal();
//         final String password = (String) token.getCredentials();
// 
//         final Optional<User> user = userRepository.findByNameAndPassword(username, password);
// 
//         return user.map(u -> new UsernamePasswordAuthenticationToken(new AuthenticatedUser(u.username), null, emptyList()))
//                 .orElse(null);
//     }
// 
//     @Override
//     public boolean supports(final Class<?> authentication) {
//         return authentication.isAssignableFrom(UsernamePasswordAuthenticationToken.class);
//     }
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/domain/event/EventService.java
// public interface EventService {
//     void publish(ApplicationEvent event);
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/domain/repository/UserRepository.java
// public interface UserRepository {
//     Optional<User> findByUsername(final String username);
// 
//     Set<User> findFriendsFor(String username);
// 
//     Optional<User> findByNameAndPassword(final String username, final String password);
// 
//     List<User> findLike(String value);
// 
//     void addFriend(String user, String friend);
// 
//     void addUser(NewUserCredentials credentials);
// 
//     boolean usersAreFriends(String userA, String userB);
// }


// Path: src/main/java/se/omegapoint/facepalm/client/config/SecurityConfig.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import se.omegapoint.facepalm.client.security.DbAuthenticationProvider;
import se.omegapoint.facepalm.domain.event.EventService;
import se.omegapoint.facepalm.domain.repository.UserRepository;

/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package se.omegapoint.facepalm.client.config;


@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    UserRepository userRepository;