use of fi.otavanopisto.pyramus.util.OauthClientSecretGenerator 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);
}
Aggregations