如何为Spring OAuth2使用自定义客户端表?

时间:2018-02-15 21:03:01

标签: java spring postgresql jpa spring-oauth2

Spring OAuth2使用this tutorial下的下一个数据库模式:

drop table if exists oauth_client_details;
create table oauth_client_details (
  client_id VARCHAR(255) PRIMARY KEY,
  resource_ids VARCHAR(255),
  client_secret VARCHAR(255),
  scope VARCHAR(255),
  authorized_grant_types VARCHAR(255),
  web_server_redirect_uri VARCHAR(255),
  authorities VARCHAR(255),
  access_token_validity INTEGER,
  refresh_token_validity INTEGER,
  additional_information VARCHAR(4096),
  autoapprove VARCHAR(255)
);

drop table if exists oauth_client_token;
create table oauth_client_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication_id VARCHAR(255) PRIMARY KEY,
  user_name VARCHAR(255),
  client_id VARCHAR(255)
);

drop table if exists oauth_access_token;
create table oauth_access_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication_id VARCHAR(255) PRIMARY KEY,
  user_name VARCHAR(255),
  client_id VARCHAR(255),
  authentication LONG VARBINARY,
  refresh_token VARCHAR(255)
);

drop table if exists oauth_refresh_token;
create table oauth_refresh_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication LONG VARBINARY
);

drop table if exists oauth_code;
create table oauth_code (
  code VARCHAR(255), authentication LONG VARBINARY
);

drop table if exists oauth_approvals;
create table oauth_approvals (
    userId VARCHAR(255),
    clientId VARCHAR(255),
    scope VARCHAR(255),
    status VARCHAR(10),
    expiresAt TIMESTAMP,
    lastModifiedAt TIMESTAMP
);

drop table if exists ClientDetails;
create table ClientDetails (
  appId VARCHAR(255) PRIMARY KEY,
  resourceIds VARCHAR(255),
  appSecret VARCHAR(255),
  scope VARCHAR(255),
  grantTypes VARCHAR(255),
  redirectUrl VARCHAR(255),
  authorities VARCHAR(255),
  access_token_validity INTEGER,
  refresh_token_validity INTEGER,
  additionalInformation VARCHAR(4096),
  autoApproveScopes VARCHAR(255)
);

我有几张桌子是由JPA生成的......我无法获得如何添加自定义字段来存储有关我网站用户的信息?以及如何将我的JPA生成的表与这些表链接起来? (如何仅在此脚本之后运行JPA?我可以使用哪些表和字段作为JPA表的外键?)
附:我是Spring OSuth2中的noobie,并尝试通过教程获取它,但无法找到如何将其与JPA表链接的信息...
ADDED 我需要存储信息,如(email,first_name,last_name,hash,salt,birthdate等),我需要JPA才能获取此信息以创建我的User类并将其存储回来。
我的用户表:

@Entity
@Table(name = UserKeys.TABLE_NAME, catalog = Database.NAME,
        uniqueConstraints = {
            @UniqueConstraint(columnNames = UserKeys.EMAIL)
        }
)
public class User implements Serializable {

    private static final long serialVersionUID = -8190974017668449062L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = UserKeys.ID, nullable = false)
    @Type(type="pg-uuid")
    private UUID mId; // How to change it to link with OAuth2 users
    @Column(name = UserKeys.FIRST_NAME, nullable = false)
    private String mFirstName;
    @Column(name = UserKeys.LAST_NAME, nullable = false)
    private String mLastName;
    @Column(name = UserKeys.EMAIL, nullable = false)
    private String mEmail;
    @Column(name = UserKeys.BIRTHDATE, nullable = false)
    @Type(type="date")
    private Date mBirthdate;
    @Column(name = UserKeys.SEX, nullable = false)
    @Enumerated(EnumType.STRING)
    private Sex mSex;
    @Column(name = UserKeys.ROLE, nullable = false)
    @Enumerated(EnumType.STRING)
    private Role mRole;
    @Column(name = UserKeys.HASH, nullable = false, length = 32)
    private String mHash;
    @Column(name = UserKeys.SALT, nullable = false, length = 20)
    private String mSalt;
}

0 个答案:

没有答案