Package org.mitre.openid.connect.service.impl

Source Code of org.mitre.openid.connect.service.impl.DefaultUserInfoService

/*******************************************************************************
* Copyright 2014 The MITRE Corporation
*   and the MIT Kerberos and Internet Trust Consortium
*
* 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.openid.connect.service.impl;

import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.model.ClientDetailsEntity.SubjectType;
import org.mitre.oauth2.service.ClientDetailsEntityService;
import org.mitre.openid.connect.model.UserInfo;
import org.mitre.openid.connect.repository.UserInfoRepository;
import org.mitre.openid.connect.service.PairwiseIdentiferService;
import org.mitre.openid.connect.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* Implementation of the UserInfoService
*
* @author Michael Joseph Walsh, jricher
*
*/
@Service
public class DefaultUserInfoService implements UserInfoService {

  @Autowired
  private UserInfoRepository userInfoRepository;

  @Autowired
  private ClientDetailsEntityService clientService;

  @Autowired
  private PairwiseIdentiferService pairwiseIdentifierService;

  @Override
  public void save(UserInfo userInfo) {
    userInfoRepository.save(userInfo);
  }

  @Override
  public UserInfo getBySubject(String userId) {
    return userInfoRepository.getBySubject(userId);
  }

  @Override
  public void remove(UserInfo userInfo) {
    userInfoRepository.remove(userInfo);
  }

  @Override
  public UserInfo getByUsername(String username) {
    return userInfoRepository.getByUsername(username);
  }

  @Override
  public UserInfo getByUsernameAndClientId(String username, String clientId) {

    ClientDetailsEntity client = clientService.loadClientByClientId(clientId);

    UserInfo userInfo = getByUsername(username);

    if (client == null || userInfo == null) {
      return null;
    }

    if (SubjectType.PAIRWISE.equals(client.getSubjectType())) {
      String pairwiseSub = pairwiseIdentifierService.getIdentifier(userInfo, client);
      userInfo.setSub(pairwiseSub);
    }

    return userInfo;

  }

}
TOP

Related Classes of org.mitre.openid.connect.service.impl.DefaultUserInfoService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.