user model modified
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package io.bluemoon.authorizationserver.config;
|
package io.bluemoon.authorizationserver.config;
|
||||||
|
|
||||||
|
import io.bluemoon.authorizationserver.domain.social.ClientResources;
|
||||||
import io.bluemoon.authorizationserver.service.user.CustomUserDetailsServiceImpl;
|
import io.bluemoon.authorizationserver.service.user.CustomUserDetailsServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
@@ -11,15 +13,20 @@ import org.springframework.security.authentication.AuthenticationManager;
|
|||||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||||
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.builders.HttpSecurity;
|
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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||||
import org.springframework.security.oauth2.client.OAuth2ClientContext;
|
import org.springframework.security.oauth2.client.OAuth2ClientContext;
|
||||||
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
|
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
|
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
|
||||||
|
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
||||||
|
import org.springframework.security.web.csrf.CsrfFilter;
|
||||||
|
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
//@Order(SecurityProperties.BASIC_AUTH_ORDER - 6)
|
//@Order(SecurityProperties.BASIC_AUTH_ORDER - 6)
|
||||||
@EnableOAuth2Client
|
@EnableOAuth2Client
|
||||||
@Order(-1)
|
@Order(-1)
|
||||||
@@ -27,12 +34,15 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
private CustomUserDetailsServiceImpl customUserDetailsService;
|
private CustomUserDetailsServiceImpl customUserDetailsService;
|
||||||
|
|
||||||
|
@Qualifier("oauth2ClientContext")
|
||||||
|
@Autowired
|
||||||
|
private OAuth2ClientContext oAuth2ClientContext;
|
||||||
|
|
||||||
public WebSecurityConfig(
|
public WebSecurityConfig(
|
||||||
CustomUserDetailsServiceImpl customUserDetailsService
|
CustomUserDetailsServiceImpl customUserDetailsService
|
||||||
) {
|
) {
|
||||||
this.customUserDetailsService = customUserDetailsService;
|
this.customUserDetailsService = customUserDetailsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authentication processing
|
* authentication processing
|
||||||
* if success -> Authentication in info object return
|
* if success -> Authentication in info object return
|
||||||
@@ -49,11 +59,32 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.formLogin().loginPage("/login").permitAll()
|
CharacterEncodingFilter filter = new CharacterEncodingFilter();
|
||||||
|
http
|
||||||
|
.authorizeRequests()
|
||||||
|
.antMatchers("/", "/login/**", "/css/**", "/images/**", "/js/**",
|
||||||
|
"/console/**").permitAll()
|
||||||
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.requestMatchers().antMatchers("/login", "/logout", "/oauth/authorize", "/oauth/confirm_access")
|
.headers().frameOptions().disable()
|
||||||
.and()
|
.and()
|
||||||
.authorizeRequests().anyRequest().authenticated();
|
.exceptionHandling()
|
||||||
|
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"))
|
||||||
|
.and()
|
||||||
|
.formLogin().loginPage("/login")
|
||||||
|
.and()
|
||||||
|
.logout()
|
||||||
|
.logoutUrl("/logout")
|
||||||
|
.deleteCookies("JSESSSIONID")
|
||||||
|
.invalidateHttpSession(true)
|
||||||
|
.and()
|
||||||
|
.addFilterBefore(filter, CsrfFilter.class)
|
||||||
|
.csrf().disable();
|
||||||
|
// http.formLogin().loginPage("/login").permitAll()
|
||||||
|
// .and()
|
||||||
|
// .requestMatchers().antMatchers("/login", "/logout", "/oauth/authorize", "/oauth/confirm_access")
|
||||||
|
// .and()
|
||||||
|
// .authorizeRequests().anyRequest().authenticated();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,4 +119,14 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
|
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// social login
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("facebook")
|
||||||
|
public ClientResources facebook() {
|
||||||
|
return new ClientResources();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.bluemoon.authorizationserver.domain.social;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
|
||||||
|
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
||||||
|
|
||||||
|
public class ClientResources {
|
||||||
|
|
||||||
|
@NestedConfigurationProperty
|
||||||
|
private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();
|
||||||
|
|
||||||
|
@NestedConfigurationProperty
|
||||||
|
private ResourceServerProperties resource = new ResourceServerProperties();
|
||||||
|
|
||||||
|
public AuthorizationCodeResourceDetails getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceServerProperties getResource() {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.bluemoon.authorizationserver.domain.social;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public enum SocialType {
|
||||||
|
FACEBOOK("facebook"),
|
||||||
|
GOOGLE("google"),
|
||||||
|
KAKAO("kakao");
|
||||||
|
|
||||||
|
private final String ROLE_PREFIX = "ROLE_";
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
SocialType(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleType() {
|
||||||
|
return ROLE_PREFIX + name.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVaule() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEquals(String authority) {
|
||||||
|
return this.getRoleType().equals(authority);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,63 @@
|
|||||||
package io.bluemoon.authorizationserver.domain.user;
|
package io.bluemoon.authorizationserver.domain.user;
|
||||||
|
|
||||||
|
import io.bluemoon.authorizationserver.domain.social.SocialType;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(length = 20, nullable = false, unique = true)
|
@Column
|
||||||
private String userName;
|
private String username;
|
||||||
|
|
||||||
@Column(length = 100, nullable = false)
|
@Column
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
//1:수퍼관리자, 2:관리자, 3:사용자
|
@Column
|
||||||
@Column(length = 1, nullable = false)
|
private String email;
|
||||||
private String userType;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
private String principal;
|
||||||
private Date regDate = new Date();
|
|
||||||
|
@Column
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private SocialType socialType;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //1:수퍼관리자, 2:관리자, 3:사용자
|
||||||
|
// @Column
|
||||||
|
// private String userType;
|
||||||
|
|
||||||
|
// @Column
|
||||||
|
// @Temporal(TemporalType.TIMESTAMP)
|
||||||
|
// private Date regDate = new Date();
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public User(String username, String password, String email, String principal,
|
||||||
|
SocialType socialType, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
this.principal = principal;
|
||||||
|
this.socialType = socialType;
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user