Commit 2fe361df authored by Maxym Borodenko's avatar Maxym Borodenko

Drop all OAuth token related code

parent 981fe9d3
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.oauth.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Type;
/**
* OAuth AccessToken.
*/
@Entity
@Table(name = "oauthaccesstoken")
public class AccessToken implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -2254427722756061411L;
/** The token id. */
@Id
@Column(length = 100)
private String tokenId;
/** The authentication id. */
@Column(unique = true, length = 100)
private String authenticationId;
/** The token. */
@Lob
@Type(type = "org.hibernate.type.MaterializedBlobType")
private byte[] token;
/** The username. */
@Column(length = 100)
private String username;
/** The client id. */
@Column(length = 100)
private String clientId;
/** The authentication. */
@Lob
@Type(type = "org.hibernate.type.MaterializedBlobType")
private byte[] authentication;
/** The refresh token. */
@Column(length = 100)
private String refreshToken;
/** The expiration. */
@Temporal(TemporalType.TIMESTAMP)
private Date expiration;
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return tokenId;
}
/**
* Gets the authentication id.
*
* @return the authentication id
*/
public String getAuthenticationId() {
return authenticationId;
}
/**
* Sets the authentication id.
*
* @param authenticationId the new authentication id
*/
public void setAuthenticationId(final String authenticationId) {
this.authenticationId = authenticationId;
}
/**
* Gets the token id.
*
* @return the token id
*/
public String getTokenId() {
return tokenId;
}
/**
* Sets the token id.
*
* @param tokenId the new token id
*/
public void setTokenId(final String tokenId) {
this.tokenId = tokenId;
}
/**
* Gets the token.
*
* @return the token
*/
public byte[] getToken() {
return token;
}
/**
* Sets the token.
*
* @param token the new token
*/
public void setToken(final byte[] token) {
this.token = token;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(final String username) {
this.username = username;
}
/**
* Get the identifier of the user associated with this refresh token.
*
* @return Usually the UUID of the User
*/
public String getUsername() {
return username;
}
/**
* Sets the client id.
*
* @param clientId the new client id
*/
public void setClientId(final String clientId) {
this.clientId = clientId;
}
/**
* Get the clientId for which this token is issued.
*
* @return OAuth clientId
* @see OAuthClient#getClientId()
*/
public String getClientId() {
return clientId;
}
/**
* Sets the authentication.
*
* @param authentication the new authentication
*/
public void setAuthentication(final byte[] authentication) {
this.authentication = authentication;
}
/**
* Gets the authentication.
*
* @return the authentication
*/
public byte[] getAuthentication() {
return authentication;
}
/**
* Sets the refresh token.
*
* @param refreshToken the new refresh token
*/
public void setRefreshToken(final String refreshToken) {
this.refreshToken = refreshToken;
}
/**
* Gets the refresh token.
*
* @return the refresh token
*/
public String getRefreshToken() {
return refreshToken;
}
/**
* Sets the expiration.
*
* @param expiration the new expiration
*/
public void setExpiration(final Date expiration) {
this.expiration = expiration;
}
/**
* Gets the expiration.
*
* @return the expiration
*/
public Date getExpiration() {
return expiration;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.oauth.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Type;
/**
* OAuth RefreshToken.
*/
@Entity
@Table(name = "oauthrefreshtoken")
public class RefreshToken implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -9214518032613402956L;
/** The token id. */
@Id
@Column(length = 100)
private String tokenId;
/** The token. */
@Lob
@Type(type = "org.hibernate.type.MaterializedBlobType")
private byte[] token;
/** The authentication. */
@Lob
@Type(type = "org.hibernate.type.MaterializedBlobType")
private byte[] authentication;
/** The client id. */
@Column(length = 100, updatable = false)
private String clientId;
/** The username. */
@Column(length = 100, updatable = false)
private String username;
/** The expiration. */
@Temporal(TemporalType.TIMESTAMP)
private Date expiration;
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return tokenId;
}
/**
* Sets the token id.
*
* @param tokenId the new token id
*/
public void setTokenId(final String tokenId) {
this.tokenId = tokenId;
}
/**
* Gets the token id.
*
* @return the token id
*/
public String getTokenId() {
return tokenId;
}
/**
* Sets the token.
*
* @param token the new token
*/
public void setToken(final byte[] token) {
this.token = token;
}
/**
* Gets the token.
*
* @return the token
*/
public byte[] getToken() {
return token;
}
/**
* Sets the authentication.
*
* @param authentication the new authentication
*/
public void setAuthentication(final byte[] authentication) {
this.authentication = authentication;
}
/**
* Gets the authentication.
*
* @return the authentication
*/
public byte[] getAuthentication() {
return authentication;
}
/**
* Sets the client id.
*
* @param clientId the new client id
*/
public void setClientId(final String clientId) {
this.clientId = clientId;
}
/**
* Get the clientId for which this token is issued.
*
* @return OAuth clientId
* @see OAuthClient#getClientId()
*/
public String getClientId() {
return clientId;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(final String username) {
this.username = username;
}
/**
* Get the identifier of the user associated with this refresh token.
*
* @return Usually the UUID of the User
*/
public String getUsername() {
return username;
}
/**
* Sets the expiration.
*
* @param expiration the new expiration
*/
public void setExpiration(final Date expiration) {
this.expiration = expiration;
}
/**
* Gets the expiration.
*
* @return the expiration
*/
public Date getExpiration() {
return expiration;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.oauth.persistence;
import java.util.List;
import org.genesys.blocks.oauth.model.AccessToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* The Interface AccessTokenRepository.
*/
@Repository
public interface AccessTokenRepository extends JpaRepository<AccessToken, String>, QueryDslPredicateExecutor<AccessToken> {
/**
* Find by authentication id.
*
* @param key the key
* @return the access token
*/
AccessToken findByAuthenticationId(String key);
/**
* Delete by refresh token.
*
* @param refreshToken the refresh token
*/
@Modifying
@Query("delete from AccessToken at where at.refreshToken = ?1")
void deleteByRefreshToken(String refreshToken);
/**
* Find by client id.
*
* @param clientId the client id
* @return the list
*/
List<AccessToken> findByClientId(String clientId);
/**
* Find by client id and username.
*
* @param clientId the client id
* @param username the username
* @return the list
*/
List<AccessToken> findByClientIdAndUsername(String clientId, String username);
/**
* Delete by authentication id.
*
* @param key the key
*/
@Modifying
@Query("delete from AccessToken at where at.authenticationId = ?1")
void deleteByAuthenticationId(String key);
/**
* Find by username.
*
* @param uuid the uuid
* @return the list
*/
List<AccessToken> findByUsername(String uuid);
}
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.oauth.persistence;
import java.util.List;
import org.genesys.blocks.oauth.model.RefreshToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* The Interface RefreshTokenRepository.
*/
@Repository
public interface RefreshTokenRepository extends JpaRepository<RefreshToken, String>, QueryDslPredicateExecutor<RefreshToken> {
/**
* Find by client id.
*
* @param clientId the client id
* @return the list
*/
List<RefreshToken> findByClientId(String clientId);
}
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.oauth.service;
import java.util.List;
import org.genesys.blocks.oauth.model.AccessToken;
import org.genesys.blocks.oauth.model.RefreshToken;
import org.springframework.security.oauth2.provider.token.TokenStore;
/**
* The Interface OAuthTokenStoreService.
*/
public interface OAuthTokenStoreService extends TokenStore {
/**
* Find access tokens by client id.
*
* @param clientId the client id
* @return the list
*/
List<AccessToken> findAccessTokensByClientId(String clientId);
/**
* Removes the access token.
*
* @param tokenId the token id
*/
void removeAccessToken(String tokenId);
/**
* Find tokens by user uuid.
*
* @param uuid the uuid
* @return the list
*/
List<AccessToken> findTokensByUserUuid(String uuid);
/**
* Find refresh tokens by client id.
*
* @param clientId the client id
* @return the list
*/
List<RefreshToken> findRefreshTokensByClientId(String clientId);
/**
* Removes the refresh token.
*
* @param tokenId the token id
*/
void removeRefreshToken(String tokenId);
}
......@@ -45,6 +45,8 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.transaction.annotation.Transactional;
/**
......@@ -96,6 +98,16 @@ public class ApplicationConfig {
return new OAuthServiceImpl();
}
/**
* Token store.
*
* @return the token store
*/
@Bean
public TokenStore tokenStore() {
return new InMemoryTokenStore();
}
/**
* Test user service.
*
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -38,7 +38,6 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
private static final String APPLICATION_RESOURCE_ID = "app-blocks";
@Autowired
@Qualifier("oauthService")
private TokenStore tokenStore;
@Autowired
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,11 +15,8 @@
*/
package org.genesys.blocks.security.test;
import org.genesys.blocks.oauth.persistence.AccessTokenRepository;
import org.genesys.blocks.oauth.persistence.OAuthClientRepository;
import org.genesys.blocks.oauth.persistence.RefreshTokenRepository;
import org.genesys.blocks.oauth.service.OAuthClientDetailsService;
import org.genesys.blocks.oauth.service.OAuthTokenStoreService;
import org.genesys.blocks.security.config.ApplicationConfig;
import org.genesys.blocks.security.config.AuthorizationServerConfig;
import org.genesys.blocks.security.config.SecurityConfig;
......@@ -68,22 +65,10 @@ public abstract class BaseTest {
@Autowired
protected OAuthClientDetailsService oauthClientDetailsService;
/** The oauth token store service. */
@Autowired
protected OAuthTokenStoreService oauthTokenStoreService;
/** The o auth client repository. */
@Autowired
protected OAuthClientRepository oAuthClientRepository;
/** The access token repository. */
@Autowired
protected AccessTokenRepository accessTokenRepository;
/** The refresh token repository. */
@Autowired
protected RefreshTokenRepository refreshTokenRepository;
/** The test user repository. */
@Autowired
protected TestUserPersistence testUserRepository;
......@@ -113,11 +98,7 @@ public abstract class BaseTest {
LOG.trace("Deleting all from OAuth client repository");
oAuthClientRepository.deleteAll();
LOG.trace("Deleting all from access token repository");
accessTokenRepository.deleteAll();
LOG.trace("Deleting all from refresh token repository");
refreshTokenRepository.deleteAll();
LOG.trace("Deleting all from test user repository");
testUserRepository.deleteAll();
testUserRepository.deleteAll();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment