Commit 614a14e2 authored by Spiros Koulouzis's avatar Spiros Koulouzis

implemented simpe auth

parent 02eeeb97
...@@ -15,77 +15,24 @@ ...@@ -15,77 +15,24 @@
*/ */
package nl.uva.sne.drip.api.conf; package nl.uva.sne.drip.api.conf;
import nl.uva.sne.drip.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/** /**
* *
* @author S. Koulouzis * @author alogo
*/ */
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@ComponentScan("nl.uva.sne.drip")
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig extends WebSecurityConfigurerAdapter {
// @Autowired @Autowired
// private UserService userService; public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
// @Autowired .inMemoryAuthentication()
// private AuthenticationFailureHandlerImpl authFailureHandler; .withUser("user").password("pwd").roles("USER");
//
// @Autowired
// private AuthenticationSuccessHandlerImpl authSuccessHandler;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth
// .userDetailsService(userService).passwordEncoder(passwordEncoder());
auth.inMemoryAuthentication().withUser("mkyong").password("123456").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("123456").roles("ADMIN");
auth.inMemoryAuthentication().withUser("dba").password("123456").roles("DBA");
} }
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http
// .sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// .and()
// .exceptionHandling()
// .authenticationEntryPoint(authenticationEntryPoint())
// .accessDeniedHandler(accessDeniedHandler())
// .and();
// }
//
// @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
// @Override
// public AuthenticationManager authenticationManagerBean() throws Exception {
// return super.authenticationManagerBean();
// }
////
// @Bean
// public PasswordEncoder passwordEncoder() {
// PasswordEncoder encoder = new BCryptPasswordEncoder();
// return encoder;
// }
////
// @Bean
// public AuthenticationEntryPoint authenticationEntryPoint() {
// AuthenticationEntryPoint authEp = new LoginUrlAuthenticationEntryPoint("/login.jsp");
// return authEp;
// }
//
// @Bean
// public AccessDeniedHandler accessDeniedHandler() {
// AccessDeniedHandler accessDenied = new org.springframework.security.web.access.AccessDeniedHandlerImpl();
// return accessDenied;
// }
} }
...@@ -15,21 +15,8 @@ ...@@ -15,21 +15,8 @@
*/ */
package nl.uva.sne.drip.api.conf; package nl.uva.sne.drip.api.conf;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
@EnableWebSecurity
public class HelloWebSecurityConfiguration
extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
} }
...@@ -27,7 +27,7 @@ public class WebAppInitializer implements WebApplicationInitializer { ...@@ -27,7 +27,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(MultipartConfig.class); ctx.register(MultipartConfig.class);
ctx.register(MongoConfig.class); ctx.register(MongoConfig.class);
// ctx.register(SecurityConfig.class); ctx.register(SecurityConfig.class);
ctx.setServletContext(servletContext); ctx.setServletContext(servletContext);
......
...@@ -26,15 +26,13 @@ import org.springframework.stereotype.Service; ...@@ -26,15 +26,13 @@ import org.springframework.stereotype.Service;
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
@Service //@Service
public class UserService implements UserDetailsService { public class UserService {// implements UserDetailsService {
@Autowired
UserDao dao;
@Override
public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// @Autowired
// UserDao dao;
// @Override
// public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
// }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment