(151) - 数据添加Ehcache缓存支持

0.6
LSZ 2016-07-23 00:35:18 +08:00
parent b6cf1fcd91
commit 0db70daa4e
4 changed files with 75 additions and 17 deletions

View File

@ -1,9 +1,16 @@
package com.monkeyk.sos.domain.oauth;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import javax.sql.DataSource;
import static com.monkeyk.sos.infrastructure.CacheConstants.CLIENT_DETAILS_CACHE;
/**
* Add <i>archived = 0</i> condition
*
@ -22,4 +29,28 @@ public class CustomJdbcClientDetailsService extends JdbcClientDetailsService {
}
@Override
@Cacheable(value = CLIENT_DETAILS_CACHE, key = "#clientId")
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
return super.loadClientByClientId(clientId);
}
@Override
@CacheEvict(value = CLIENT_DETAILS_CACHE, key = "#clientDetails.getClientId()")
public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
super.updateClientDetails(clientDetails);
}
@Override
@CacheEvict(value = CLIENT_DETAILS_CACHE, key = "#clientId")
public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
super.updateClientSecret(clientId, secret);
}
@Override
@CacheEvict(value = CLIENT_DETAILS_CACHE, key = "#clientId")
public void removeClientDetails(String clientId) throws NoSuchClientException {
super.removeClientDetails(clientId);
}
}

View File

@ -1,29 +1,16 @@
/*
* Copyright (c) 2015 MONKEYK Information Technology Co. Ltd
* www.monkeyk.com
* All rights reserved.
*
* This software is the confidential and proprietary information of
* MONKEYK Information Technology Co. Ltd ("Confidential Information").
* You shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement you
* entered into with MONKEYK Information Technology Co. Ltd.
*/
package com.monkeyk.sos.infrastructure.jdbc;
import com.monkeyk.sos.domain.oauth.OauthClientDetails;
import com.monkeyk.sos.domain.oauth.OauthRepository;
import static com.monkeyk.sos.infrastructure.CacheConstants.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
import static com.monkeyk.sos.infrastructure.CacheConstants.CLIENT_DETAILS_CACHE;
/**
* 2015/11/16
*
@ -41,7 +28,6 @@ public class OauthRepositoryJdbc implements OauthRepository {
@Override
@Cacheable(value = CLIENT_DETAILS_CACHE, key = "#clientId")
public OauthClientDetails findOauthClientDetails(String clientId) {
final String sql = " select * from oauth_client_details where client_id = ? ";
final List<OauthClientDetails> list = this.jdbcTemplate.query(sql, new Object[]{clientId}, oauthClientDetailsRowMapper);

View File

@ -0,0 +1,37 @@
package com.monkeyk.sos.infrastructure.jdbc;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;
import javax.sql.DataSource;
import static com.monkeyk.sos.infrastructure.CacheConstants.AUTHORIZATION_CODE_CACHE;
import static com.monkeyk.sos.infrastructure.CacheConstants.CLIENT_DETAILS_CACHE;
/**
* 2016/7/23
*
* @author Shengzhao Li
*/
public class SOSAuthorizationCodeServices extends JdbcAuthorizationCodeServices {
public SOSAuthorizationCodeServices(DataSource dataSource) {
super(dataSource);
}
@Override
@Cacheable(value = AUTHORIZATION_CODE_CACHE, key = "#code")
protected void store(String code, OAuth2Authentication authentication) {
super.store(code, authentication);
}
@Override
@CacheEvict(value = AUTHORIZATION_CODE_CACHE, key = "#code")
public OAuth2Authentication remove(String code) {
return super.remove(code);
}
}

View File

@ -123,8 +123,12 @@
</beans:bean>
<!--<beans:bean id="jdbcAuthorizationCodeServices"-->
<!--class="org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices">-->
<!--<beans:constructor-arg index="0" ref="dataSource"/>-->
<!--</beans:bean>-->
<beans:bean id="jdbcAuthorizationCodeServices"
class="org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices">
class="com.monkeyk.sos.infrastructure.jdbc.SOSAuthorizationCodeServices">
<beans:constructor-arg index="0" ref="dataSource"/>
</beans:bean>