示例#1
0
 private ClientDetails removeSecret(ClientDetails client) {
   BaseClientDetails details = new BaseClientDetails();
   details.setClientId(client.getClientId());
   details.setScope(client.getScope());
   details.setResourceIds(client.getResourceIds());
   details.setAuthorizedGrantTypes(client.getAuthorizedGrantTypes());
   details.setRegisteredRedirectUri(client.getRegisteredRedirectUri());
   details.setAuthorities(client.getAuthorities());
   details.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds());
   return details;
 }
 public BaseClientDetails(ClientDetails prototype) {
   this();
   setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds());
   setRefreshTokenValiditySeconds(prototype.getRefreshTokenValiditySeconds());
   setAuthorities(prototype.getAuthorities());
   setAuthorizedGrantTypes(prototype.getAuthorizedGrantTypes());
   setClientId(prototype.getClientId());
   setClientSecret(prototype.getClientSecret());
   setRegisteredRedirectUri(prototype.getRegisteredRedirectUri());
   setScope(prototype.getScope());
   setResourceIds(prototype.getResourceIds());
 }
  @Test
  public void adminClientIsAdmin() throws Exception {

    BaseClientDetails client = new BaseClientDetails();
    client.setAuthorities(UaaAuthority.ADMIN_AUTHORITIES);

    DefaultAuthorizationRequest authorizationRequest =
        new DefaultAuthorizationRequest("admin", null);
    authorizationRequest.addClientDetails(client);
    SecurityContextHolder.getContext()
        .setAuthentication(new OAuth2Authentication(authorizationRequest, null));

    assertTrue(new DefaultSecurityContextAccessor().isAdmin());
  }
 @JsonProperty("authorities")
 @JsonDeserialize(using = ArrayOrStringDeserializer.class)
 private void setAuthoritiesAsStrings(Set<String> values) {
   setAuthorities(AuthorityUtils.createAuthorityList(values.toArray(new String[values.size()])));
 }