moved client details service, fixed authorities mapper

pull/263/head
Justin Richer 2012-12-10 09:49:07 -05:00
parent 2a206654b6
commit f072aba3f5
1 changed files with 24 additions and 14 deletions

View File

@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
******************************************************************************/ ******************************************************************************/
package org.mitre.openid.connect.service; package org.mitre.oauth2.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -36,28 +37,37 @@ import org.springframework.stereotype.Service;
* @author AANGANES * @author AANGANES
* *
*/ */
@Service @Service("clientUserDetailsService")
public class ClientUserDetailsService implements UserDetailsService { public class DefaultClientUserDetailsService implements UserDetailsService {
@Autowired @Autowired
ClientDetailsService clientDetailsService; private ClientDetailsService clientDetailsService;
@Override @Override
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException, DataAccessException { public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException, DataAccessException {
ClientDetails client = clientDetailsService.loadClientByClientId(clientId); ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
if (client != null) {
String password = client.getClientSecret(); String password = client.getClientSecret();
boolean enabled = true; boolean enabled = true;
boolean accountNonExpired = true; boolean accountNonExpired = true;
boolean credentialsNonExpired = true; boolean credentialsNonExpired = true;
boolean accountNonLocked = true; boolean accountNonLocked = true;
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); Collection<GrantedAuthority> authorities = client.getAuthorities();
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT"); if (authorities == null || authorities.isEmpty()) {
authorities.add(roleClient); // automatically inject ROLE_CLIENT if none exists ...
// TODO: this should probably happen on the client service side instead to keep it in the real data model
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); authorities = new ArrayList<GrantedAuthority>();
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
authorities.add(roleClient);
}
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
} else {
throw new UsernameNotFoundException("Client not found: " + clientId);
}
} }