001package ca.cdr.api.model.json;
002
003/*
004 * #%L
005 * Smile CDR - CDR
006 * %%
007 * Copyright (C) 2016 - 2026 Smile CDR, Inc.
008 * %%
009 * All rights reserved.
010 * #L%
011 */
012
013import ca.cdr.api.model.enm.OAuth2AuthorizedGrantTypeEnum;
014import ca.uhn.fhir.model.api.annotation.ExampleSupplier;
015import com.fasterxml.jackson.annotation.JsonProperty;
016import io.swagger.v3.oas.annotations.media.Schema;
017import org.apache.commons.lang3.time.DateUtils;
018
019import java.util.ArrayList;
020import java.util.Date;
021import java.util.List;
022import java.util.function.Supplier;
023
024@Schema(name = "OAuth2Clients", description = "A collection of OAuth2 clients")
025@ExampleSupplier(OAuth2ClientsJson.ExampleSupplier.class)
026public class OAuth2ClientsJson implements IModelJson {
027
028        @JsonProperty("clients")
029        private List<OAuth2ClientDetailsJson> myClients;
030
031        @JsonProperty("pageIndex")
032        private int myPageIndex;
033
034        @JsonProperty("totalPages")
035        private int myTotalPages;
036
037        public List<OAuth2ClientDetailsJson> getClients() {
038                if (myClients == null) {
039                        myClients = new ArrayList<>();
040                }
041                return myClients;
042        }
043
044        public void setClients(List<OAuth2ClientDetailsJson> theClients) {
045                myClients = theClients;
046        }
047
048        public int getPageIndex() {
049                return myPageIndex;
050        }
051
052        public void setPageIndex(int thePageIndex) {
053                myPageIndex = thePageIndex;
054        }
055
056        public int getTotalPages() {
057                return myTotalPages;
058        }
059
060        public void setTotalPages(int theTotalPages) {
061                myTotalPages = theTotalPages;
062        }
063
064        public static class ExampleSupplier implements Supplier<OAuth2ClientsJson> {
065                @Override
066                public OAuth2ClientsJson get() {
067                        OAuth2ClientsJson retVal = new OAuth2ClientsJson();
068
069                        OAuth2ClientDetailsJson client = new OAuth2ClientDetailsJson();
070                        client.setClientId("my-client-id");
071                        client.setClientName("Sample Client");
072                        client.addClientSecret("THIS_IS_A_CLIENT_SECRET")
073                                        .setActivation(new Date())
074                                        .setExpiration(DateUtils.addYears(new Date(), 1));
075                        client.addAllowedGrantType(OAuth2AuthorizedGrantTypeEnum.AUTHORIZATION_CODE);
076                        client.addAllowedGrantType(OAuth2AuthorizedGrantTypeEnum.REFRESH_TOKEN);
077                        client.addRedirectUrlIfNotBlank("http://example.com/app-redirect");
078                        client.addScopeIfNotBlank("openid").addScopeIfNotBlank("profile").addScopeIfNotBlank("patient/*.read");
079                        client.setSecretRequired(true);
080                        retVal.getClients().add(client);
081
082                        return retVal;
083                }
084        }
085}