Removed unused ClientGeneratorFactory

pull/165/merge
Amanda Anganes 2012-08-08 12:00:47 -04:00
parent d6d80c3e60
commit cf348590b0
4 changed files with 2 additions and 127 deletions

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -27,10 +27,6 @@ public interface ClientDetailsEntityService extends ClientDetailsService {
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
public ClientDetailsEntity createClient(String clientId, String clientSecret, Set<String> scope, Set<String> grantTypes, String redirectUri, Set<GrantedAuthority> authorities, Set<String> resourceIds, String name, String description, boolean allowRefresh, Integer accessTokenTimeout, Integer refreshTokenTimeout, Set<String> contacts);
public ClientDetailsEntity createClient(ClientDetailsEntity client);
public void deleteClient(ClientDetailsEntity client);
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient);

View File

@ -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<String> scope, Set<String> grantTypes, String redirectUri, Set<GrantedAuthority> authorities,
Set<String> resourceIds,
String name, String description, boolean allowRefresh, Integer accessTokenTimeout,
Integer refreshTokenTimeout, Set<String> contacts) {
// TODO: check "owner" locally?
ClientDetailsEntity client = clientFactory.createClient(clientId, clientSecret);
client.setScope(scope);
client.setAuthorizedGrantTypes(grantTypes);
//client.setRegisteredRedirectUri(redirectUri);
Set<String> redirectUris = new HashSet<String>();
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);
}