Java Code Examples for io.choerodon.core.oauth.CustomUserDetails#setClientId()
The following examples show how to use
io.choerodon.core.oauth.CustomUserDetails#setClientId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetUserDetailsServiceImpl.java From gateway-helper with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private CustomUserDetails setUserDetails(final Map<String, Object> map, boolean isClientOnly) { if (map.containsKey(USER_ID)) { CustomUserDetails user = new CustomUserDetails((String) map.get("username"), "unknown password", Collections.emptyList()); user.setOrganizationId((long) (Integer) map.get("organizationId")); if (map.get(USER_ID) != null) { user.setUserId((long) (Integer) map.get(USER_ID)); user.setLanguage((String) map.get("language")); user.setAdmin((Boolean) map.get("admin")); user.setTimeZone((String) map.get("timeZone")); if (map.get("email") != null) { user.setEmail((String) map.get("email")); } } if (isClientOnly) { user.setClientId((long) (Integer) map.get("clientId")); user.setClientName((String) map.get("clientName")); user.setClientAccessTokenValiditySeconds((Integer) map.get("clientAccessTokenValiditySeconds")); user.setClientRefreshTokenValiditySeconds((Integer) map.get("clientRefreshTokenValiditySeconds")); user.setClientAuthorizedGrantTypes((Collection<String>) map.get("clientAuthorizedGrantTypes")); user.setClientAutoApproveScopes((Collection<String>) map.get("clientAutoApproveScopes")); user.setClientRegisteredRedirectUri((Collection<String>) map.get("clientRegisteredRedirectUri")); user.setClientResourceIds((Collection<String>) map.get("clientResourceIds")); user.setClientScope((Collection<String>) map.get("clientScope")); } try { if (map.get(ADDITION_INFO) != null) { user.setAdditionInfo((Map) map.get(ADDITION_INFO)); } } catch (Exception e) { LOGGER.warn("Parser addition info error:{}", e); } return user; } return null; }
Example 2
Source File: GetUserDetailsServiceImpl.java From api-gateway-old with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private CustomUserDetails setUserDetails(final Map<String, Object> map, boolean isClientOnly) { if (map.containsKey(USER_ID)) { CustomUserDetails user = new CustomUserDetails((String) map.get("username"), "unknown password", Collections.emptyList()); user.setOrganizationId((long) (Integer) map.get("organizationId")); if (map.get(USER_ID) != null) { user.setUserId((long) (Integer) map.get(USER_ID)); user.setLanguage((String) map.get("language")); user.setAdmin((Boolean) map.get("admin")); user.setTimeZone((String) map.get("timeZone")); if (map.get("email") != null) { user.setEmail((String) map.get("email")); } } if (isClientOnly) { user.setClientId((long) (Integer) map.get("clientId")); user.setClientName((String) map.get("clientName")); user.setClientAccessTokenValiditySeconds((Integer) map.get("clientAccessTokenValiditySeconds")); user.setClientRefreshTokenValiditySeconds((Integer) map.get("clientRefreshTokenValiditySeconds")); user.setClientAuthorizedGrantTypes((Collection<String>) map.get("clientAuthorizedGrantTypes")); user.setClientAutoApproveScopes((Collection<String>) map.get("clientAutoApproveScopes")); user.setClientRegisteredRedirectUri((Collection<String>) map.get("clientRegisteredRedirectUri")); user.setClientResourceIds((Collection<String>) map.get("clientResourceIds")); user.setClientScope((Collection<String>) map.get("clientScope")); } try { if (map.get(ADDITION_INFO) != null) { user.setAdditionInfo((Map) map.get(ADDITION_INFO)); } } catch (Exception e) { LOGGER.warn("Parser addition info error:{}", e); } return user; } return null; }
Example 3
Source File: PrincipalServiceImpl.java From oauth-server with Apache License 2.0 | 4 votes |
/** * 用于Userdetail获取时,往Userdetail中添加客户端信息(Userdetail中user为客户端创建人) */ @Override public Principal setClientDetailUserDetails(Principal principal) { String clientName = ((OAuth2Authentication) principal).getPrincipal().toString(); ClientE clientE = new ClientE(); clientE.setName(clientName); clientE = clientMapper.selectOne(clientE); if (clientE == null || clientE.getId() == null) { throw new CommonException("setClientDetailUserDetails.client.not.exist"); } CustomUserDetails user = new CustomUserDetails(clientName, "unknown password", Collections.emptyList()); UserE userE = userMapper.selectByPrimaryKey(clientE.getCreatedBy()); user.eraseCredentials(); //添加client创建人信息 if (userE != null) { user.setUserId(userE.getId()); user.setLanguage(userE.getLanguage()); user.setAdmin(userE.getAdmin()); user.setTimeZone(userE.getTimeZone()); user.setOrganizationId(userE.getOrganizationId()); user.setEmail(userE.getEmail()); addRouteRuleCode(user); } //添加client信息 user.setOrganizationId(clientE.getOrganizationId()); user.setClientId(clientE.getId()); user.setClientName(clientE.getName()); int accessTokenValidity = clientE.getAccessTokenValidity() != null ? clientE.getAccessTokenValidity().intValue() : 3600; user.setClientAccessTokenValiditySeconds(accessTokenValidity); int refreshTokenValidity = clientE.getRefreshTokenValidity() != null ? clientE.getRefreshTokenValidity().intValue() : 3600; user.setClientRefreshTokenValiditySeconds(refreshTokenValidity); user.setClientAuthorizedGrantTypes(StringUtils .commaDelimitedListToSet(clientE.getAuthorizedGrantTypes())); user.setClientAutoApproveScopes(StringUtils.commaDelimitedListToSet(clientE.getAutoApprove())); user.setClientRegisteredRedirectUri(StringUtils .commaDelimitedListToSet(clientE.getWebServerRedirectUri())); user.setClientResourceIds(StringUtils.commaDelimitedListToSet(clientE.getResourceIds())); user.setClientScope(StringUtils.commaDelimitedListToSet(clientE.getScope())); String json = clientE.getAdditionalInformation(); if (json != null) { try { Map<String, Object> additionalInformation = mapper.readValue(json, Map.class); user.setAdditionInfo(additionalInformation); } catch (Exception e) { LOGGER.warn("parser addition info error: {}", e); } } //构建返回Principal (原Principal添加客户端及用户信息) UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken( user, ((OAuth2Authentication) principal).getCredentials(), ((OAuth2Authentication) principal).getAuthorities()); OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(((OAuth2Authentication) principal).getOAuth2Request(), usernamePasswordAuthenticationToken); copyDetails((OAuth2Authentication) principal, oAuth2Authentication); return oAuth2Authentication; }