Search in sources :

Example 6 with RedisConnection

use of org.maxkey.persistence.redis.RedisConnection in project MaxKey by dromara.

the class RedisRemeberMeService method remove.

@Override
public void remove(String username) {
    RedisConnection conn = connectionFactory.getConnection();
    conn.delete(PREFIX + username);
    conn.close();
}
Also used : RedisConnection(org.maxkey.persistence.redis.RedisConnection)

Example 7 with RedisConnection

use of org.maxkey.persistence.redis.RedisConnection in project MaxKey by dromara.

the class RedisRemeberMeService method update.

@Override
public void update(RemeberMe remeberMe) {
    RedisConnection conn = connectionFactory.getConnection();
    conn.setexObject(PREFIX + remeberMe.getUsername(), serviceTicketValiditySeconds, remeberMe);
    conn.close();
}
Also used : RedisConnection(org.maxkey.persistence.redis.RedisConnection)

Example 8 with RedisConnection

use of org.maxkey.persistence.redis.RedisConnection in project MaxKey by dromara.

the class RedisTokenStore method storeRefreshToken.

@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
    String refreshKey = (REFRESH + refreshToken.getValue());
    String refreshAuthKey = (REFRESH_AUTH + refreshToken.getValue());
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.setObject(refreshKey, refreshToken);
        conn.setObject(refreshAuthKey, authentication);
        if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken;
            Date expiration = expiringRefreshToken.getExpiration();
            if (expiration != null) {
                int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue();
                conn.expire(refreshKey, seconds);
                conn.expire(refreshAuthKey, seconds);
            }
        }
        conn.closePipeline();
    } finally {
        conn.close();
    }
}
Also used : Date(java.util.Date) RedisConnection(org.maxkey.persistence.redis.RedisConnection) ExpiringOAuth2RefreshToken(org.maxkey.authz.oauth2.common.ExpiringOAuth2RefreshToken)

Example 9 with RedisConnection

use of org.maxkey.persistence.redis.RedisConnection in project MaxKey by dromara.

the class RedisTokenStore method findTokensByClientId.

@Override
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
    String key = (CLIENT_ID_TO_ACCESS + clientId);
    _logger.trace("TokensByClientId  " + key);
    List<String> stringList = null;
    RedisConnection conn = getConnection();
    try {
        stringList = conn.lRange(key, 0, -1);
    } finally {
        conn.close();
    }
    if (stringList == null || stringList.size() == 0) {
        return Collections.<OAuth2AccessToken>emptySet();
    }
    List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(stringList.size());
    for (String str : stringList) {
        OAuth2AccessToken accessToken = conn.getObject(str);
        accessTokens.add(accessToken);
    }
    return Collections.<OAuth2AccessToken>unmodifiableCollection(accessTokens);
}
Also used : OAuth2AccessToken(org.maxkey.authz.oauth2.common.OAuth2AccessToken) ArrayList(java.util.ArrayList) RedisConnection(org.maxkey.persistence.redis.RedisConnection)

Example 10 with RedisConnection

use of org.maxkey.persistence.redis.RedisConnection in project MaxKey by dromara.

the class RedisTokenStore method readAuthentication.

@Override
public OAuth2Authentication readAuthentication(String token) {
    _logger.trace("read Authentication by token " + token + " , token key " + AUTH + token);
    RedisConnection conn = getConnection();
    try {
        OAuth2Authentication auth = conn.getObject(AUTH + token);
        return auth;
    } finally {
        conn.close();
    }
}
Also used : OAuth2Authentication(org.maxkey.authz.oauth2.provider.OAuth2Authentication) RedisConnection(org.maxkey.persistence.redis.RedisConnection)

Aggregations

RedisConnection (org.maxkey.persistence.redis.RedisConnection)31 Ticket (org.maxkey.authz.cas.endpoint.ticket.Ticket)6 OAuth2AccessToken (org.maxkey.authz.oauth2.common.OAuth2AccessToken)4 ExpiringOAuth2RefreshToken (org.maxkey.authz.oauth2.common.ExpiringOAuth2RefreshToken)3 OAuth2Authentication (org.maxkey.authz.oauth2.provider.OAuth2Authentication)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 OAuth2RefreshToken (org.maxkey.authz.oauth2.common.OAuth2RefreshToken)2 OneTimePassword (org.maxkey.password.onetimepwd.OneTimePassword)2 DateTime (org.joda.time.DateTime)1