Search in sources :

Example 1 with OauthClientSecretGenerator

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);
}
Also used : ClientApplicationAccessTokenDAO(fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationAccessTokenDAO) ClientApplicationAuthorizationCodeDAO(fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationAuthorizationCodeDAO) ClientApplication(fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplication) ClientApplicationDAO(fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationDAO) ClientApplicationAccessToken(fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken) List(java.util.List) ClientApplicationAuthorizationCode(fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAuthorizationCode) OauthClientSecretGenerator(fi.otavanopisto.pyramus.util.OauthClientSecretGenerator)

Aggregations

ClientApplicationAccessTokenDAO (fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationAccessTokenDAO)1 ClientApplicationAuthorizationCodeDAO (fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationAuthorizationCodeDAO)1 ClientApplicationDAO (fi.otavanopisto.pyramus.dao.clientapplications.ClientApplicationDAO)1 ClientApplication (fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplication)1 ClientApplicationAccessToken (fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAccessToken)1 ClientApplicationAuthorizationCode (fi.otavanopisto.pyramus.domainmodel.clientapplications.ClientApplicationAuthorizationCode)1 OauthClientSecretGenerator (fi.otavanopisto.pyramus.util.OauthClientSecretGenerator)1 List (java.util.List)1