use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.
the class AuthorizationGrant method asTokenLdap.
public TokenLdap asTokenLdap(AbstractToken p_token) {
final String id = GrantService.generateGrantId();
final TokenLdap result = new TokenLdap();
result.setDn(grantService.buildDn(id, getGrantId(), getClientId()));
result.setId(id);
result.setGrantId(getGrantId());
result.setCreationDate(p_token.getCreationDate());
result.setExpirationDate(p_token.getExpirationDate());
result.setTokenCode(TokenHashUtil.getHashedToken(p_token.getCode()));
result.setUserId(getUserId());
result.setClientId(getClientId());
result.setScope(getScopesAsString());
result.setAuthMode(p_token.getAuthMode());
result.setSessionDn(p_token.getSessionDn());
result.setAuthenticationTime(getAuthenticationTime());
final AuthorizationGrantType grantType = getAuthorizationGrantType();
if (grantType != null) {
result.setGrantType(grantType.getParamName());
}
final AuthorizationCode authorizationCode = getAuthorizationCode();
if (authorizationCode != null) {
result.setAuthorizationCode(TokenHashUtil.getHashedToken(authorizationCode.getCode()));
}
final String nonce = getNonce();
if (nonce != null) {
result.setNonce(nonce);
}
final JwtAuthorizationRequest jwtRequest = getJwtAuthorizationRequest();
if (jwtRequest != null && StringUtils.isNotBlank(jwtRequest.getEncodedJwt())) {
result.setJwtRequest(jwtRequest.getEncodedJwt());
}
return result;
}
use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.
the class GrantService method auditLogging.
private void auditLogging(Collection<TokenLdap> entries) {
for (TokenLdap tokenLdap : entries) {
OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(null, Action.SESSION_DESTROYED);
oAuth2AuditLog.setSuccess(true);
oAuth2AuditLog.setClientId(tokenLdap.getClientId());
oAuth2AuditLog.setScope(tokenLdap.getScope());
oAuth2AuditLog.setUsername(tokenLdap.getUserId());
applicationAuditLogger.sendMessage(oAuth2AuditLog);
}
}
use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.
the class GrantService method cleanUp.
public void cleanUp() {
// Cleaning oxAuthToken
BatchOperation<TokenLdap> tokenBatchService = new BatchOperation<TokenLdap>(ldapEntryManager) {
@Override
protected List<TokenLdap> getChunkOrNull(int chunkSize) {
return ldapEntryManager.findEntries(baseDn(), TokenLdap.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
}
@Override
protected void performAction(List<TokenLdap> entries) {
auditLogging(entries);
remove(entries);
}
private Filter getFilter() {
try {
return Filter.create(String.format("(oxAuthExpiration<=%s)", StaticUtils.encodeGeneralizedTime(new Date())));
} catch (LDAPException e) {
log.trace(e.getMessage(), e);
return Filter.createPresenceFilter("oxAuthExpiration");
}
}
};
tokenBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
// Cleaning oxAuthGrant
BatchOperation<Grant> grantBatchService = new BatchOperation<Grant>(ldapEntryManager) {
@Override
protected List<Grant> getChunkOrNull(int chunkSize) {
return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
}
@Override
protected void performAction(List<Grant> entries) {
removeGrants(entries);
}
private Filter getFilter() {
try {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 60);
return Filter.create(String.format("(&(oxAuthCreation<=%s)(|(numsubordinates=0)(hasSubordinates=FALSE)))", StaticUtils.encodeGeneralizedTime(calendar.getTime())));
} catch (LDAPException e) {
log.trace(e.getMessage(), e);
return Filter.createPresenceFilter("oxAuthCreation");
}
}
};
grantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
// Cleaning old oxAuthGrant
// Note: This block should be removed, it is used only to delete old legacy data.
BatchOperation<Grant> oldGrantBatchService = new BatchOperation<Grant>(ldapEntryManager) {
@Override
protected List<Grant> getChunkOrNull(int chunkSize) {
return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
}
@Override
protected void performAction(List<Grant> entries) {
removeGrants(entries);
}
private Filter getFilter() {
try {
return Filter.create("(&(!(oxAuthCreation=*))(|(numsubordinates=0)(hasSubordinates=FALSE)))");
} catch (LDAPException e) {
log.trace(e.getMessage(), e);
return Filter.createPresenceFilter("oxAuthCreation");
}
}
};
oldGrantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
}
use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.
the class GrantService method removeByCode.
/**
* Removes grant with particular code.
*
* @param p_code code
*/
public void removeByCode(String p_code, String p_clientId) {
final TokenLdap t = getGrantsByCodeAndClient(p_code, p_clientId);
if (t != null) {
removeSilently(t);
}
cacheService.remove(null, MemcachedGrant.cacheKey(p_clientId, p_code));
}
use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.
the class AuthorizationGrant method asToken.
public TokenLdap asToken(IdToken p_token) {
final TokenLdap result = asTokenLdap(p_token);
result.setTokenTypeEnum(org.xdi.oxauth.model.ldap.TokenType.ID_TOKEN);
return result;
}
Aggregations