use of fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken in project pyramus by otavanopisto.
the class ClientApplicationTokenCleaner method removeExpiredTokens.
@Schedule(dayOfWeek = "*", hour = "6", persistent = false)
private void removeExpiredTokens() {
int removed = 0;
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, -1);
long threshold = calendar.getTimeInMillis() / 1000;
List<ClientApplicationAccessToken> tokens = clientApplicationAccessTokenDAO.listByExpired(threshold, BATCH_SIZE);
if (tokens.size() == BATCH_SIZE) {
logger.warning("Client application access tokens possibly piling up");
}
for (ClientApplicationAccessToken token : tokens) {
ClientApplicationAuthorizationCode authCode = token.getClientApplicationAuthorizationCode();
if (authCode.getUser().getRole() == Role.TRUSTED_SYSTEM) {
continue;
}
clientApplicationAccessTokenDAO.delete(token);
clientApplicationAuthorizationCodeDAO.delete(authCode);
removed++;
}
if (removed > 0) {
logger.info(String.format("Removed %d expired client application access tokens", removed));
}
}
use of fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken in project pyramus by otavanopisto.
the class ClientApplicationsViewController method processSend.
@Override
public void processSend(PageRequestContext requestContext) {
ClientApplicationDAO clientApplicationDAO = DAOFactory.getInstance().getClientApplicationDAO();
ClientApplicationAuthorizationCodeDAO clientApplicationAuthorizationCodeDAO = DAOFactory.getInstance().getClientApplicationAuthorizationCodeDAO();
ClientApplicationAccessTokenDAO clientApplicationAccessTokenDAO = DAOFactory.getInstance().getClientApplicationAccessTokenDAO();
Long clientApplicationsRowCount = requestContext.getLong("clientApplicationsTable.rowCount");
for (int i = 0; i < clientApplicationsRowCount; i++) {
String colPrefix = "clientApplicationsTable." + i;
Long id = requestContext.getLong(colPrefix + ".id");
Boolean remove = "1".equals(requestContext.getString(colPrefix + ".remove"));
Boolean regenerateSecret = "1".equals(requestContext.getString(colPrefix + ".regenerateSecret"));
Boolean skipPrompt = "1".equals(requestContext.getString(colPrefix + ".skipPrompt"));
String clientName = requestContext.getString(colPrefix + ".appName");
String clientId = requestContext.getString(colPrefix + ".appId");
String clientSecret = requestContext.getString(colPrefix + ".appSecret");
if (id == null && !remove) {
clientId = UUID.randomUUID().toString();
clientSecret = new OauthClientSecretGenerator(80).nextString();
clientApplicationDAO.create(clientName, clientId, clientSecret, skipPrompt);
} else if (id != null) {
ClientApplication clientApplication = clientApplicationDAO.findById(id);
if (remove) {
List<ClientApplicationAuthorizationCode> authCodes = clientApplicationAuthorizationCodeDAO.listByClientApplication(clientApplication);
for (ClientApplicationAuthorizationCode clientApplicationAuthorizationCode : authCodes) {
ClientApplicationAccessToken clientApplicationAccessToken = clientApplicationAccessTokenDAO.findByAuthCode(clientApplicationAuthorizationCode);
if (clientApplicationAccessToken != null) {
clientApplicationAccessTokenDAO.delete(clientApplicationAccessToken);
}
clientApplicationAuthorizationCodeDAO.delete(clientApplicationAuthorizationCode);
}
clientApplicationDAO.delete(clientApplication);
} else {
if (regenerateSecret) {
clientSecret = new OauthClientSecretGenerator(80).nextString();
clientApplicationDAO.updateClientSecret(clientApplication, clientSecret);
}
clientApplicationDAO.updateName(clientApplication, clientName);
clientApplicationDAO.updateSkipPrompt(clientApplication, skipPrompt);
}
}
}
processForm(requestContext);
}
use of fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken in project pyramus by otavanopisto.
the class ClientApplicationController method getClientApplication.
public ClientApplication getClientApplication() {
try {
OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(httpRequest, ParameterStyle.HEADER);
String accessToken = oauthRequest.getAccessToken();
ClientApplicationAccessToken clientApplicationAccessToken = oauthController.findByAccessToken(accessToken);
return clientApplicationAccessToken.getClientApplication();
} catch (Exception ex) {
return null;
}
}
use of fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken in project pyramus by otavanopisto.
the class SecurityFilter method hasOAuthApiAccess.
private boolean hasOAuthApiAccess() {
try {
OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request, ParameterStyle.HEADER);
String accessToken = oauthRequest.getAccessToken();
ClientApplicationAccessToken clientApplicationAccessToken = oauthController.findByAccessToken(accessToken);
if (clientApplicationAccessToken == null) {
return false;
} else {
Long currentTime = System.currentTimeMillis() / 1000L;
if (currentTime > clientApplicationAccessToken.getExpires()) {
return false;
} else {
return true;
}
}
} catch (OAuthProblemException e) {
return false;
} catch (OAuthSystemException e) {
return false;
}
}
use of fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken in project pyramus by otavanopisto.
the class ClientApplicationAccessTokenDAO method create.
public ClientApplicationAccessToken create(String accessToken, String refreshToken, Long expires, ClientApplication clientApplication, ClientApplicationAuthorizationCode clientApplicationAuthorizationCode) {
EntityManager entityManager = getEntityManager();
ClientApplicationAccessToken clientApplicationAccessToken = new ClientApplicationAccessToken();
clientApplicationAccessToken.setAccessToken(accessToken);
clientApplicationAccessToken.setRefreshToken(refreshToken);
clientApplicationAccessToken.setClientApplication(clientApplication);
clientApplicationAccessToken.setExpires(expires);
clientApplicationAccessToken.setClientApplicationAuthorizationCode(clientApplicationAuthorizationCode);
entityManager.persist(clientApplicationAccessToken);
return clientApplicationAccessToken;
}
Aggregations