Skip to content

Commit

Permalink
adding XAuthConfigurer.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlong committed Jan 2, 2014
1 parent d112db1 commit e1e4319
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
15 changes: 4 additions & 11 deletions x-auth-security/src/main/java/example/Application.java
Expand Up @@ -4,7 +4,6 @@
import java.util.Arrays;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -23,12 +22,11 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import example.xauth.XAuthTokenFilter;
import example.xauth.XAuthTokenConfigurer;

@ComponentScan
@EnableAutoConfiguration
Expand All @@ -47,14 +45,9 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

XAuthTokenFilter customFilter = new XAuthTokenFilter(userDetailsServiceBean());



http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
http.authorizeRequests().antMatchers("/" + GreetingController.GREETING_NAME + "/**").hasRole(CustomUserDetailsService.ROLE_USER);
http.apply(new XAuthTokenConfigurer(userDetailsServiceBean()));
}

@Override
Expand Down Expand Up @@ -110,12 +103,12 @@ public boolean isAccountNonExpired() {

@Override
public String getUsername() {
return "mikey";
return "user";
}

@Override
public String getPassword() {
return "bear";
return "password";
}

private String role(String i) {
Expand Down
Expand Up @@ -5,7 +5,6 @@

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.codec.Hex;
import org.springframework.stereotype.Component;

class TokenUtils {

Expand Down

This file was deleted.

@@ -0,0 +1,23 @@
package example.xauth;

import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

public class XAuthTokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

private UserDetailsService detailsService;

public XAuthTokenConfigurer(UserDetailsService detailsService) {
this.detailsService = detailsService;
}

@Override
public void configure(HttpSecurity http) throws Exception {
XAuthTokenFilter customFilter = new XAuthTokenFilter(detailsService);
http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
}

}

0 comments on commit e1e4319

Please sign in to comment.