// Path: src/main/java/com/hillert/botanic/service/DefaultUserDetailsService.java
// public class DefaultUserDetailsService implements UserDetailsService {
// 	public static final String ROLE_ADMIN = "ADMIN";
// 	public static final String ROLE_USER = "USER";
// 
// 	@SuppressWarnings("serial")
// 	static class SimpleUserDetails implements UserDetails {
// 
// 		private String username;
// 		private String password;
// 		private boolean enabled = true;
// 		private Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
// 
// 		public SimpleUserDetails(String username, String pw, String... extraRoles) {
// 			this.username = username;
// 			this.password = pw;
// 
// 			// setup roles
// 			Set<String> roles = new HashSet<String>();
// 			roles.addAll(Arrays.<String>asList(null == extraRoles ? new String[0] : extraRoles));
// 
// 			// export them as part of authorities
// 			for (String r : roles) {
// 				authorities.add(new SimpleGrantedAuthority(role(r)));
// 			}
// 
// 		}
// 
// 		public String toString() {
// 			return "{enabled:" + isEnabled() + ", username:'" + getUsername() + "', password:'" + getPassword() + "'}";
// 		}
// 
// 		@Override
// 		public boolean isEnabled() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isCredentialsNonExpired() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isAccountNonLocked() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isAccountNonExpired() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public String getUsername() {
// 			return this.username;
// 		}
// 
// 		@Override
// 		public String getPassword() {
// 			return this.password;
// 		}
// 
// 		private String role(String i) {
// 			return "ROLE_" + i;
// 		}
// 
// 		@Override
// 		public Collection<? extends GrantedAuthority> getAuthorities() {
// 			return this.authorities;
// 		}
// 	}
// 
// 	List<UserDetails> details = Arrays.<UserDetails>asList(new SimpleUserDetails("user", "{noop}user", ROLE_USER), new SimpleUserDetails("admin", "{noop}admin", ROLE_USER, ROLE_ADMIN));
// 
// 	@Override
// 	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 		for (UserDetails details : this.details) {
// 			if (details.getUsername().equalsIgnoreCase(username)) {
// 				return details;
// 			}
// 		}
// 		throw new UsernameNotFoundException("No user found for username " + username);
// 	}
// }


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
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.core.userdetails.UserDetailsService;
import com.hillert.botanic.service.DefaultUserDetailsService;
/*
 * Copyright 2014 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 com.hillert.botanic.config;



/**
 *
 * @author Gunnar Hillert
 * @since 1.0
 *
 */
@EnableWebSecurity
@Configuration
@Order
class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Override
	protected void configure(HttpSecurity http) throws Exception {

		http
		//.addFilterBefore(sessionRepositoryFilter, ChannelProcessingFilter.class)
		.csrf().disable();
		//http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// Path: src/main/java/com/hillert/botanic/service/DefaultUserDetailsService.java
// public class DefaultUserDetailsService implements UserDetailsService {
// 	public static final String ROLE_ADMIN = "ADMIN";
// 	public static final String ROLE_USER = "USER";
// 
// 	@SuppressWarnings("serial")
// 	static class SimpleUserDetails implements UserDetails {
// 
// 		private String username;
// 		private String password;
// 		private boolean enabled = true;
// 		private Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
// 
// 		public SimpleUserDetails(String username, String pw, String... extraRoles) {
// 			this.username = username;
// 			this.password = pw;
// 
// 			// setup roles
// 			Set<String> roles = new HashSet<String>();
// 			roles.addAll(Arrays.<String>asList(null == extraRoles ? new String[0] : extraRoles));
// 
// 			// export them as part of authorities
// 			for (String r : roles) {
// 				authorities.add(new SimpleGrantedAuthority(role(r)));
// 			}
// 
// 		}
// 
// 		public String toString() {
// 			return "{enabled:" + isEnabled() + ", username:'" + getUsername() + "', password:'" + getPassword() + "'}";
// 		}
// 
// 		@Override
// 		public boolean isEnabled() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isCredentialsNonExpired() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isAccountNonLocked() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public boolean isAccountNonExpired() {
// 			return this.enabled;
// 		}
// 
// 		@Override
// 		public String getUsername() {
// 			return this.username;
// 		}
// 
// 		@Override
// 		public String getPassword() {
// 			return this.password;
// 		}
// 
// 		private String role(String i) {
// 			return "ROLE_" + i;
// 		}
// 
// 		@Override
// 		public Collection<? extends GrantedAuthority> getAuthorities() {
// 			return this.authorities;
// 		}
// 	}
// 
// 	List<UserDetails> details = Arrays.<UserDetails>asList(new SimpleUserDetails("user", "{noop}user", ROLE_USER), new SimpleUserDetails("admin", "{noop}admin", ROLE_USER, ROLE_ADMIN));
// 
// 	@Override
// 	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 		for (UserDetails details : this.details) {
// 			if (details.getUsername().equalsIgnoreCase(username)) {
// 				return details;
// 			}
// 		}
// 		throw new UsernameNotFoundException("No user found for username " + username);
// 	}
// }


// Path: src/main/java/com/hillert/botanic/config/SecurityConfig.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
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.core.userdetails.UserDetailsService;
import com.hillert.botanic.service.DefaultUserDetailsService;

/*
 * Copyright 2014 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 com.hillert.botanic.config;



/**
 *
 * @author Gunnar Hillert
 * @since 1.0
 *
 */
@EnableWebSecurity
@Configuration
@Order
class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Override
	protected void configure(HttpSecurity http) throws Exception {

		http
		//.addFilterBefore(sessionRepositoryFilter, ChannelProcessingFilter.class)
		.csrf().disable();
		//http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
		http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/info/**").hasRole(DefaultUserDetailsService.ROLE_USER);