moved client details service, fixed authorities mapper
parent
2a206654b6
commit
f072aba3f5
|
@ -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();
|
||||||
|
if (authorities == null || authorities.isEmpty()) {
|
||||||
|
// 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
|
||||||
|
authorities = new ArrayList<GrantedAuthority>();
|
||||||
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
|
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
|
||||||
authorities.add(roleClient);
|
authorities.add(roleClient);
|
||||||
|
}
|
||||||
|
|
||||||
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||||
|
} else {
|
||||||
|
throw new UsernameNotFoundException("Client not found: " + clientId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue