Search in sources :

Example 1 with ApprovalStore

use of org.springframework.security.oauth2.provider.approval.ApprovalStore in project spring-security-oauth by spring-projects.

the class JwtTokenStoreTests method removeRefreshToken.

@Test
public void removeRefreshToken() throws Exception {
    tokenStore.setApprovalStore(approvalStore);
    approvalStore.addApprovals(Collections.singleton(new Approval("test", "id", "read", new Date(), ApprovalStatus.APPROVED)));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
    tokenStore.removeRefreshToken(new DefaultOAuth2RefreshToken(expectedOAuth2AccessToken.getValue()));
    assertEquals(0, approvalStore.getApprovals("test", "id").size());
}
Also used : DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) Approval(org.springframework.security.oauth2.provider.approval.Approval) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ApprovalStore

use of org.springframework.security.oauth2.provider.approval.ApprovalStore in project spring-security-oauth by spring-projects.

the class JwtTokenStoreTests method removeAccessTokenFromRefreshToken.

@Test
public void removeAccessTokenFromRefreshToken() throws Exception {
    tokenStore.setApprovalStore(approvalStore);
    approvalStore.addApprovals(Collections.singleton(new Approval("test", "id", "read", new Date(), ApprovalStatus.APPROVED)));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
    tokenStore.removeAccessTokenUsingRefreshToken(new DefaultOAuth2RefreshToken(expectedOAuth2AccessToken.getValue()));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
}
Also used : DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) Approval(org.springframework.security.oauth2.provider.approval.Approval) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ApprovalStore

use of org.springframework.security.oauth2.provider.approval.ApprovalStore in project spring-security-oauth by spring-projects.

the class JwtTokenStoreTests method testReadRefreshTokenForUnapprovedScope.

@Test
public void testReadRefreshTokenForUnapprovedScope() throws Exception {
    tokenStore.setApprovalStore(approvalStore);
    approvalStore.addApprovals(Collections.singleton(new Approval("test", "id", "write", new Date(), ApprovalStatus.APPROVED)));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
    assertEquals(null, tokenStore.readRefreshToken(expectedOAuth2RefreshToken.getValue()));
}
Also used : Approval(org.springframework.security.oauth2.provider.approval.Approval) Date(java.util.Date) Test(org.junit.Test)

Example 4 with ApprovalStore

use of org.springframework.security.oauth2.provider.approval.ApprovalStore in project spring-security-oauth by spring-projects.

the class JwtTokenStore method remove.

private void remove(String token) {
    if (approvalStore != null) {
        OAuth2Authentication auth = readAuthentication(token);
        String clientId = auth.getOAuth2Request().getClientId();
        Authentication user = auth.getUserAuthentication();
        if (user != null) {
            Collection<Approval> approvals = new ArrayList<Approval>();
            for (String scope : auth.getOAuth2Request().getScope()) {
                approvals.add(new Approval(user.getName(), clientId, scope, new Date(), ApprovalStatus.APPROVED));
            }
            approvalStore.revokeApprovals(approvals);
        }
    }
}
Also used : OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Approval(org.springframework.security.oauth2.provider.approval.Approval)

Example 5 with ApprovalStore

use of org.springframework.security.oauth2.provider.approval.ApprovalStore in project spring-security-oauth by spring-projects.

the class AbstractIntegrationTests method clear.

private void clear(ApprovalStore approvalStore) throws Exception {
    if (approvalStore instanceof Advised) {
        Advised advised = (Advised) tokenStore;
        ApprovalStore target = (ApprovalStore) advised.getTargetSource().getTarget();
        clear(target);
        return;
    }
    if (approvalStore instanceof InMemoryApprovalStore) {
        ((InMemoryApprovalStore) approvalStore).clear();
    }
    if (approvalStore instanceof JdbcApprovalStore) {
        JdbcTemplate template = new JdbcTemplate(dataSource);
        template.execute("delete from oauth_approvals");
    }
}
Also used : InMemoryApprovalStore(org.springframework.security.oauth2.provider.approval.InMemoryApprovalStore) Advised(org.springframework.aop.framework.Advised) InMemoryApprovalStore(org.springframework.security.oauth2.provider.approval.InMemoryApprovalStore) ApprovalStore(org.springframework.security.oauth2.provider.approval.ApprovalStore) JdbcApprovalStore(org.springframework.security.oauth2.provider.approval.JdbcApprovalStore) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) JdbcApprovalStore(org.springframework.security.oauth2.provider.approval.JdbcApprovalStore)

Aggregations

Approval (org.springframework.security.oauth2.provider.approval.Approval)6 Date (java.util.Date)4 Test (org.junit.Test)4 DefaultOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken)3 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 Advised (org.springframework.aop.framework.Advised)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 Authentication (org.springframework.security.core.Authentication)1 DefaultExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1 ApprovalStore (org.springframework.security.oauth2.provider.approval.ApprovalStore)1 ApprovalStoreUserApprovalHandler (org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler)1 InMemoryApprovalStore (org.springframework.security.oauth2.provider.approval.InMemoryApprovalStore)1 JdbcApprovalStore (org.springframework.security.oauth2.provider.approval.JdbcApprovalStore)1 TokenApprovalStore (org.springframework.security.oauth2.provider.approval.TokenApprovalStore)1 TokenStoreUserApprovalHandler (org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler)1