### SSO Server Application Configuration (YAML) Source: https://github.com/longfeizheng/sso-merryyou/blob/master/README.md This YAML configuration file sets up the basic properties for the SSO server application. It defines the server's port (8082) and context path (/uaa), along with detailed FreeMarker template settings such as template location, caching, character encoding, and content type. ```YAML server: port: 8082 context-path: /uaa spring: freemarker: allow-request-override: false allow-session-override: false cache: true charset: UTF-8 check-template-location: true content-type: text/html enabled: true expose-request-attributes: false expose-session-attributes: false expose-spring-macro-helpers: true prefer-file-system-access: true suffix: .ftl template-loader-path: classpath:/templates/ ``` -------------------------------- ### SSO Client 1 Spring Boot Application Source: https://github.com/longfeizheng/sso-merryyou/blob/master/README.md This Java class defines the main Spring Boot application for SSO Client 1. It is annotated with @EnableOAuth2Sso to enable OAuth2 Single Sign-On capabilities and includes a @RestController with a /user endpoint that returns the authenticated user's Authentication object, demonstrating successful SSO integration. ```Java @SpringBootApplication @RestController @EnableOAuth2Sso public class SsoClient1Application { @GetMapping("/user") public Authentication user(Authentication user) { return user; } public static void main(String[] args) { SpringApplication.run(SsoClient1Application.class, args); } } ``` -------------------------------- ### SSO Client 1 OAuth2 Configuration (YAML) Source: https://github.com/longfeizheng/sso-merryyou/blob/master/README.md This YAML configuration file specifies the OAuth2 client settings for SSO Client 1. It defines the SSO server's base URL, the client's port (8083) and context path (/client1), and critical OAuth2 parameters such as client ID, client secret, user authorization URI, access token URI, and the JWT token key URI for token validation. ```YAML auth-server: http://localhost:8082/uaa # sso-server地址 server: context-path: /client1 port: 8083 security: oauth2: client: client-id: merryyou1 client-secret: merryyousecrect1 user-authorization-uri: ${auth-server}/oauth/authorize #请求认证的地址 access-token-uri: ${auth-server}/oauth/token #请求令牌的地址 resource: jwt: key-uri: ${auth-server}/oauth/token_key #解析jwt令牌所需要密钥的地址 ``` -------------------------------- ### Implement UserDetailsService for SSO Server Source: https://github.com/longfeizheng/sso-merryyou/blob/master/README.md This Java component implements Spring Security's UserDetailsService interface. It provides a custom implementation for loading user details by username, encoding a default password '123456' using BCryptPasswordEncoder and assigning the 'ROLE_USER' authority for demonstration purposes. ```Java @Component public class SsoUserDetailsService implements UserDetailsService { @Autowired private PasswordEncoder passwordEncoder; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return new User(username, passwordEncoder.encode("123456"), AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); } } ``` -------------------------------- ### Configure Spring Security for SSO Server Authentication Source: https://github.com/longfeizheng/sso-merryyou/blob/master/README.md This Java configuration class extends WebSecurityConfigurerAdapter to set up form-based login for the SSO server. It defines a BCryptPasswordEncoder for password hashing and configures request authorization, allowing public access to specific paths (e.g., login pages, static resources) while requiring authentication for all other requests. ```Java @Configuration public class SsoSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Override protected void configure(HttpSecurity http) throws Exception { http.formLogin().loginPage("/authentication/require") .loginProcessingUrl("/authentication/form") .and().authorizeRequests() .antMatchers("/authentication/require", "/authentication/form", "/**/*.js", "/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.woff2" ) .permitAll() .anyRequest().authenticated() .and() .csrf().disable(); // http.formLogin().and().authorizeRequests().anyRequest().authenticated(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.