Created
May 30, 2015 03:01
-
-
Save xenoterracide/dc6e14f93053717163c6 to your computer and use it in GitHub Desktop.
redis application
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
package com.xenoterracide; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.autoconfigure.security.SecurityProperties; | |
import org.springframework.context.annotation.Bean; | |
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.WebSecurityConfigurerAdapter; | |
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; | |
import org.springframework.session.web.http.HeaderHttpSessionStrategy; | |
import org.springframework.session.web.http.HttpSessionStrategy; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
@EnableRedisHttpSession | |
@SpringBootApplication | |
public class Application { | |
@RequestMapping( "/" ) | |
public String greeting() { | |
return "hello"; | |
} | |
@Configuration | |
@Order( SecurityProperties.ACCESS_OVERRIDE_ORDER ) | |
protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter { | |
@Bean | |
static HttpSessionStrategy httpSessionStrategy() { | |
return new HeaderHttpSessionStrategy(); | |
} | |
@Autowired | |
void globalUserDetails( final AuthenticationManagerBuilder auth ) throws Exception { | |
auth.inMemoryAuthentication().withUser( "admin" ).password( "admin" ).roles( "USER", "ADMIN" ); | |
} | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.httpBasic() | |
.and() | |
.authorizeRequests() | |
.anyRequest().authenticated(); | |
} | |
} | |
public static void main( final String[] args ) { | |
SpringApplication app = new SpringApplication( Application.class ); | |
app.setShowBanner( false ); | |
app.run( args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment