Package org.mitre.openid.connect.model

Examples of org.mitre.openid.connect.model.UserInfo


  private List<String> admins = new ArrayList<String>();

  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    UserInfo userInfo = repository.getByUsername(username);

    if (userInfo != null) {

      // TODO: make passwords configurable? part of object?
      String password = "password";

      List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
      authorities.add(ROLE_USER);

      if (admins != null && admins.contains(username)) {
        authorities.add(ROLE_ADMIN);
      }

      // TODO: this should really be our own UserDetails wrapper class, shouldn't it?
      User user = new User(userInfo.getSub(), password, authorities);
      return user;
    } else {
      throw new UsernameNotFoundException("Could not find username: " + username);
    }
  }
View Full Code Here


   * javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {

    UserInfo userInfo = (UserInfo) model.get("userInfo");

    Set<String> scope = (Set<String>) model.get("scope");

    response.setContentType("application/json");

View Full Code Here

      OIDCAuthenticationToken token = (OIDCAuthenticationToken) authentication;

      Collection<SubjectIssuerGrantedAuthority> authorities = Lists.newArrayList(new SubjectIssuerGrantedAuthority(token.getSub(), token.getIssuer()));

      UserInfo userInfo = userInfoFetcher.loadUserInfo(token);

      if (userInfo == null) {
        // TODO: user Info not found -- error?
      } else {
        if (!Strings.isNullOrEmpty(userInfo.getSub()) && !userInfo.getSub().equals(token.getSub())) {
          // the userinfo came back and the user_id fields don't match what was in the id_token
          throw new UsernameNotFoundException("user_id mismatch between id_token and user_info call: " + token.getSub() + " / " + userInfo.getSub());
        }
      }

      return new OIDCAuthenticationToken(token.getSub(),
          token.getIssuer(),
View Full Code Here

      if (!Strings.isNullOrEmpty(userInfoString)) {

        JsonObject userInfoJson = new JsonParser().parse(userInfoString).getAsJsonObject();
 
        UserInfo userInfo = DefaultUserInfo.fromJson(userInfoJson);

        return userInfo;
      } else {
        // didn't get anything, return null
        return null;
View Full Code Here

        } else {
          // don't bother checking if we don't have a principal or a userInfoService to work with
          if (p != null && p.getName() != null && userInfoService != null) {

            // try to look up a user based on the principal's name
            UserInfo user = userInfoService.getByUsername(p.getName());

            // if we have one, inject it so views can use it
            if (user != null) {
              modelAndView.addObject("userInfo", user);
              modelAndView.addObject("userInfoJson", user.toJson());
            }
          }
        }
      }
    }
View Full Code Here

      if (resourceUri != null
          && resourceUri.getScheme() != null
          && resourceUri.getScheme().equals("acct")) {
        // acct: URI

        UserInfo user = userService.getByUsername(resourceUri.getUserInfo()); // first part is the username

        if (user == null) {
          logger.info("User not found: " + resource);
          model.addAttribute("code", HttpStatus.NOT_FOUND);
          return HttpCodeView.VIEWNAME;
View Full Code Here

     */
    if (originalAuthRequest.getScope().contains("openid")
        && !authentication.isClientOnly()) {

      String username = authentication.getName();
      UserInfo userInfo = userInfoService.getByUsernameAndClientId(username, clientId);

      if (userInfo != null) {

        OAuth2AccessTokenEntity idTokenEntity = connectTokenService.createIdToken(client,
            originalAuthRequest, claims.getIssueTime(),
            userInfo.getSub(), token);

        // attach the id token to the parent access token
        token.setIdToken(idTokenEntity);
      } else {
        // can't create an id token if we can't find the user
View Full Code Here

   * has both the ROLE_USER and ROLE_ADMIN authorities.
   */
  @Test
  public void loadByUsername_admin_success() {
    Mockito.when(userInfoRepository.getByUsername(adminUsername)).thenReturn(userInfoAdmin);
    UserInfo user = service.getByUsername(adminUsername);
    assertEquals(user.getSub(), adminSub);
  }
View Full Code Here

   */
  @Test
  public void loadByUsername_regular_success() {

    Mockito.when(userInfoRepository.getByUsername(regularUsername)).thenReturn(userInfoRegular);
    UserInfo user = service.getByUsername(regularUsername);
    assertEquals(user.getSub(), regularSub);

  }
View Full Code Here

   */
  @Test()
  public void loadByUsername_nullUser() {

    Mockito.when(userInfoRepository.getByUsername(adminUsername)).thenReturn(null);
    UserInfo user = service.getByUsername(adminUsername);

    assertNull(user);
  }
View Full Code Here

TOP

Related Classes of org.mitre.openid.connect.model.UserInfo

Copyright © 2018 www.massapicom. 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.