コード例 #1
0
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  public Response createOAuthClient(
      final @Context UriInfo uriInfo, final OAuthClientRepresentation rep) {
    auth.requireManage();

    OAuthClientManager resourceManager = new OAuthClientManager(realm);
    OAuthClientModel oauth = resourceManager.create(rep);
    return Response.created(uriInfo.getAbsolutePathBuilder().path(oauth.getId()).build()).build();
  }
コード例 #2
0
  public void update(OAuthClientRepresentation rep, OAuthClientModel model) {
    if (rep.getName() != null) model.setClientId(rep.getName());
    if (rep.isEnabled() != null) model.setEnabled(rep.isEnabled());
    if (rep.isPublicClient() != null) model.setPublicClient(rep.isPublicClient());
    if (rep.getClaims() != null) {
      ClaimManager.setClaims(model, rep.getClaims());
    }
    if (rep.getNotBefore() != null) {
      model.setNotBefore(rep.getNotBefore());
    }
    if (rep.getSecret() != null) model.setSecret(rep.getSecret());
    List<String> redirectUris = rep.getRedirectUris();
    if (redirectUris != null) {
      model.setRedirectUris(new HashSet<String>(redirectUris));
    }

    List<String> webOrigins = rep.getWebOrigins();
    if (webOrigins != null) {
      model.setWebOrigins(new HashSet<String>(webOrigins));
    }

    if (rep.getClaims() != null) {
      ClaimManager.setClaims(model, rep.getClaims());
    }

    if (rep.getNotBefore() != null) {
      model.setNotBefore(rep.getNotBefore());
    }
  }
コード例 #3
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @NoCache
  public List<OAuthClientRepresentation> getOAuthClients() {
    List<OAuthClientRepresentation> rep = new ArrayList<OAuthClientRepresentation>();
    List<OAuthClientModel> oauthModels = realm.getOAuthClients();

    boolean view = auth.hasView();
    for (OAuthClientModel oauth : oauthModels) {
      if (view) {
        rep.add(OAuthClientManager.toRepresentation(oauth));
      } else {
        OAuthClientRepresentation client = new OAuthClientRepresentation();
        client.setName(oauth.getClientId());
        rep.add(client);
      }
    }
    return rep;
  }
コード例 #4
0
  public InstallationAdapterConfig toInstallationRepresentation(
      RealmModel realmModel, OAuthClientModel model, URI baseUri) {
    InstallationAdapterConfig rep = new InstallationAdapterConfig();
    rep.setRealm(realmModel.getName());
    rep.setRealmKey(realmModel.getPublicKeyPem());
    rep.setSslNotRequired(realmModel.isSslNotRequired());
    rep.setAuthServerUrl(baseUri.toString());
    if (model.isPublicClient()) rep.setPublicClient(true);

    rep.setResource(model.getClientId());

    if (!model.isPublicClient()) {
      Map<String, String> creds = new HashMap<String, String>();
      creds.put(CredentialRepresentation.SECRET, model.getSecret());
      rep.setCredentials(creds);
    }

    return rep;
  }
コード例 #5
0
  public static OAuthClientRepresentation toRepresentation(OAuthClientModel model) {
    OAuthClientRepresentation rep = new OAuthClientRepresentation();
    rep.setId(model.getId());
    rep.setName(model.getClientId());
    rep.setEnabled(model.isEnabled());
    rep.setPublicClient(model.isPublicClient());
    Set<String> redirectUris = model.getRedirectUris();
    if (redirectUris != null) {
      rep.setRedirectUris(new LinkedList<String>(redirectUris));
    }

    Set<String> webOrigins = model.getWebOrigins();
    if (webOrigins != null) {
      rep.setWebOrigins(new LinkedList<String>(webOrigins));
    }
    rep.setNotBefore(model.getNotBefore());
    return rep;
  }
コード例 #6
0
 public UserCredentialModel generateSecret(OAuthClientModel app) {
   UserCredentialModel secret = UserCredentialModel.generateSecret();
   app.setSecret(secret.getValue());
   return secret;
 }