diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntityFactory.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntityFactory.java deleted file mode 100644 index 7b21d9c58..000000000 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntityFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright 2012 The MITRE Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package org.mitre.oauth2.model; - - -public interface ClientDetailsEntityFactory { - - public ClientDetailsEntity createClient(String clientId, String clientSecret); - -} diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientGeneratorFactory.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientGeneratorFactory.java deleted file mode 100644 index 833692444..000000000 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientGeneratorFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright 2012 The MITRE Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package org.mitre.oauth2.model; - -import java.util.UUID; - -import org.apache.commons.codec.binary.Base64; -import org.mitre.oauth2.model.ClientDetailsEntity.ClientDetailsEntityBuilder; -import org.springframework.stereotype.Service; - -/** - * A factory for making OAuth2 clients with autogenerated IDs and secrets (as desired) - * @author jricher - * - */ -@Service -public class ClientGeneratorFactory implements ClientDetailsEntityFactory { - - @Override - public ClientDetailsEntity createClient(String clientId, String clientSecret) { - ClientDetailsEntityBuilder builder = ClientDetailsEntity.makeBuilder(); - if (clientId == null) { - clientId = UUID.randomUUID().toString(); - } - builder.setClientId(clientId); - if (clientSecret == null) { - clientSecret = Base64.encodeBase64((UUID.randomUUID().toString() + UUID.randomUUID().toString()).getBytes()).toString(); - } - builder.setClientSecret(clientSecret); - - return builder.finish(); - } - -} diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java b/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java index 514f4f373..cab7f4dd5 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java @@ -27,10 +27,6 @@ public interface ClientDetailsEntityService extends ClientDetailsService { public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception; - public ClientDetailsEntity createClient(String clientId, String clientSecret, Set scope, Set grantTypes, String redirectUri, Set authorities, Set resourceIds, String name, String description, boolean allowRefresh, Integer accessTokenTimeout, Integer refreshTokenTimeout, Set contacts); - - public ClientDetailsEntity createClient(ClientDetailsEntity client); - public void deleteClient(ClientDetailsEntity client); public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java index df9870e55..d4d835f10 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java @@ -16,24 +16,19 @@ package org.mitre.oauth2.service.impl; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; import java.util.UUID; import org.mitre.oauth2.model.ClientDetailsEntity; -import org.mitre.oauth2.model.ClientDetailsEntityFactory; import org.mitre.oauth2.repository.OAuth2ClientRepository; import org.mitre.oauth2.repository.OAuth2TokenRepository; import org.mitre.oauth2.service.ClientDetailsEntityService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.common.exceptions.InvalidClientException; import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.google.common.base.Strings; -import com.google.common.collect.Sets; @Service @Transactional @@ -45,18 +40,15 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt @Autowired private OAuth2TokenRepository tokenRepository; - @Autowired - private ClientDetailsEntityFactory clientFactory; public DefaultOAuth2ClientDetailsEntityService() { } public DefaultOAuth2ClientDetailsEntityService(OAuth2ClientRepository clientRepository, - OAuth2TokenRepository tokenRepository, ClientDetailsEntityFactory clientFactory) { + OAuth2TokenRepository tokenRepository) { this.clientRepository = clientRepository; this.tokenRepository = tokenRepository; - this.clientFactory = clientFactory; } /** @@ -77,49 +69,6 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt throw new IllegalArgumentException("Client id must not be empty!"); } - /** - * Create a new client with the appropriate fields filled in - */ - @Override - public ClientDetailsEntity createClient(String clientId, String clientSecret, - Set scope, Set grantTypes, String redirectUri, Set authorities, - Set resourceIds, - String name, String description, boolean allowRefresh, Integer accessTokenTimeout, - Integer refreshTokenTimeout, Set contacts) { - - // TODO: check "owner" locally? - - ClientDetailsEntity client = clientFactory.createClient(clientId, clientSecret); - client.setScope(scope); - client.setAuthorizedGrantTypes(grantTypes); - //client.setRegisteredRedirectUri(redirectUri); - Set redirectUris = new HashSet(); - redirectUris.add(redirectUri); - client.setRegisteredRedirectUri(redirectUris); - client.setAuthorities(authorities); - client.setApplicationName(name); - client.setClientDescription(description); - client.setAllowRefresh(allowRefresh); - client.setAccessTokenValiditySeconds(accessTokenTimeout); - client.setRefreshTokenValiditySeconds(refreshTokenTimeout); - client.setResourceIds(resourceIds); - client.setContacts(contacts); - - clientRepository.saveClient(client); - - return client; - - } - - @Override - public ClientDetailsEntity createClient(ClientDetailsEntity client) { - - clientRepository.saveClient(client); - - return client; - - } - /** * Delete a client and all its associated tokens */ @@ -166,7 +115,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt // assign it a new ID if (client.getClientId() == null || client.getClientId().equals("") || this.loadClientByClientId(client.getClientId()) == null) { client.setClientId(UUID.randomUUID().toString()); - return this.createClient(client); + return clientRepository.saveClient(client); } else { return clientRepository.updateClient(client.getClientId(), client); }