|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.client.mgmt.filter.PageBasedPaginationFilter; |
| 4 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile; |
| 5 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse; |
| 6 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage; |
| 7 | +import com.auth0.json.mgmt.selfserviceprofiles.SsoAccessTicketResponse; |
| 8 | +import com.auth0.net.*; |
| 9 | +import com.auth0.net.client.Auth0HttpClient; |
| 10 | +import com.auth0.net.client.HttpMethod; |
| 11 | +import com.auth0.utils.Asserts; |
| 12 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 13 | +import okhttp3.HttpUrl; |
| 14 | + |
| 15 | +import java.util.Map; |
| 16 | + |
| 17 | +public class SelfServiceProfilesEntity extends BaseManagementEntity { |
| 18 | + |
| 19 | + private final static String ORGS_PATH = "api/v2/self-service-profiles"; |
| 20 | + |
| 21 | + SelfServiceProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 22 | + super(client, baseUrl, tokenProvider); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Request the list of self-service profiles. |
| 27 | + * A token with {@code read:self_service_profiles} scope is needed |
| 28 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles</a> |
| 29 | + * @param pageFilter the pagination filter to apply. Can be null to use the default values. |
| 30 | + * @return a Request to execute. |
| 31 | + */ |
| 32 | + public Request<SelfServiceProfileResponsePage> get(PageBasedPaginationFilter pageFilter) { |
| 33 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 34 | + .addPathSegments(ORGS_PATH); |
| 35 | + |
| 36 | + if (pageFilter != null) { |
| 37 | + for (Map.Entry<String, Object> e : pageFilter.getAsMap().entrySet()) { |
| 38 | + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + String url = builder.build().toString(); |
| 43 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponsePage>() { |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Create a new self-service profile. |
| 49 | + * A token with {@code create:self_service_profiles} scope is needed |
| 50 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles</a> |
| 51 | + * @param selfServiceProfile the self-service profile to create. |
| 52 | + * @return a Request to execute. |
| 53 | + */ |
| 54 | + public Request<SelfServiceProfileResponse> create(SelfServiceProfile selfServiceProfile) { |
| 55 | + Asserts.assertNotNull(selfServiceProfile, "self service profile"); |
| 56 | + Asserts.assertNotNull(selfServiceProfile.getName(), "name"); |
| 57 | + |
| 58 | + String url = baseUrl.newBuilder() |
| 59 | + .addPathSegments(ORGS_PATH) |
| 60 | + .build() |
| 61 | + .toString(); |
| 62 | + |
| 63 | + BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SelfServiceProfileResponse>() { |
| 64 | + }); |
| 65 | + request.setBody(selfServiceProfile); |
| 66 | + return request; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Request the self-service profile with the given ID. |
| 71 | + * A token with {@code read:self_service_profiles} scope is needed |
| 72 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id</a> |
| 73 | + * @param id the self-service profile ID. |
| 74 | + * @return a Request to execute. |
| 75 | + */ |
| 76 | + public Request<SelfServiceProfileResponse> getById(String id) { |
| 77 | + Asserts.assertNotNull(id, "id"); |
| 78 | + |
| 79 | + String url = baseUrl.newBuilder() |
| 80 | + .addPathSegments(ORGS_PATH) |
| 81 | + .addPathSegment(id) |
| 82 | + .build() |
| 83 | + .toString(); |
| 84 | + |
| 85 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponse>() { |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Delete the self-service profile with the given ID. |
| 91 | + * A token with {@code delete:self_service_profiles} scope is needed |
| 92 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id</a> |
| 93 | + * @param id the self-service profile ID. |
| 94 | + * @return a Request to execute. |
| 95 | + */ |
| 96 | + public Request<Void> delete(String id) { |
| 97 | + Asserts.assertNotNull(id, "id"); |
| 98 | + |
| 99 | + String url = baseUrl.newBuilder() |
| 100 | + .addPathSegments(ORGS_PATH) |
| 101 | + .addPathSegment(id) |
| 102 | + .build() |
| 103 | + .toString(); |
| 104 | + |
| 105 | + return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Update the self-service profile with the given ID. |
| 110 | + * A token with {@code update:self_service_profiles} scope is needed |
| 111 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id</a> |
| 112 | + * @param selfServiceProfile the self-service profile to update. |
| 113 | + * @param id the self-service profile ID. |
| 114 | + * @return a Request to execute. |
| 115 | + */ |
| 116 | + public Request<SelfServiceProfileResponse> update(SelfServiceProfile selfServiceProfile, String id) { |
| 117 | + Asserts.assertNotNull(selfServiceProfile, "self service profile"); |
| 118 | + Asserts.assertNotNull(id, "id"); |
| 119 | + |
| 120 | + String url = baseUrl.newBuilder() |
| 121 | + .addPathSegments(ORGS_PATH) |
| 122 | + .addPathSegment(id) |
| 123 | + .build() |
| 124 | + .toString(); |
| 125 | + |
| 126 | + BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<SelfServiceProfileResponse>() { |
| 127 | + }); |
| 128 | + request.setBody(selfServiceProfile); |
| 129 | + return request; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Get the custom text for specific self-service profile and language. |
| 134 | + * A token with {@code read:self_service_profile_custom_texts} scope is needed |
| 135 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text</a> |
| 136 | + * @param id the self-service profile ID. |
| 137 | + * @param language the language. |
| 138 | + * @param page the page. |
| 139 | + * @return a Request to execute. |
| 140 | + */ |
| 141 | + public Request<Object> getCustomText(String id, String language, String page) { |
| 142 | + Asserts.assertNotNull(id, "id"); |
| 143 | + Asserts.assertNotNull(language, "language"); |
| 144 | + Asserts.assertNotNull(page, "page"); |
| 145 | + |
| 146 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 147 | + .addPathSegments(ORGS_PATH) |
| 148 | + .addPathSegment(id) |
| 149 | + .addPathSegment("custom-text") |
| 150 | + .addPathSegment(language) |
| 151 | + .addPathSegment(page); |
| 152 | + |
| 153 | + String url = builder.build().toString(); |
| 154 | + |
| 155 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { |
| 156 | + }); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Set the custom text for specific self-service profile and language. |
| 161 | + * A token with {@code update:self_service_profile_custom_texts} scope is needed |
| 162 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text</a> |
| 163 | + * @param id the self-service profile ID. |
| 164 | + * @param language the language. |
| 165 | + * @param page the page. |
| 166 | + * @param customText the custom text. |
| 167 | + * @return a Request to execute. |
| 168 | + */ |
| 169 | + public Request<Object> setCustomText(String id, String language, String page, Object customText) { |
| 170 | + Asserts.assertNotNull(id, "id"); |
| 171 | + Asserts.assertNotNull(language, "language"); |
| 172 | + Asserts.assertNotNull(page, "page"); |
| 173 | + Asserts.assertNotNull(customText, "custom text"); |
| 174 | + |
| 175 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 176 | + .addPathSegments(ORGS_PATH) |
| 177 | + .addPathSegment(id) |
| 178 | + .addPathSegment("custom-text") |
| 179 | + .addPathSegment(language) |
| 180 | + .addPathSegment(page); |
| 181 | + |
| 182 | + String url = builder.build().toString(); |
| 183 | + |
| 184 | + BaseRequest<Object> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Object>() { |
| 185 | + }); |
| 186 | + request.setBody(customText); |
| 187 | + return request; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Create a new SSO access ticket. |
| 192 | + * A token with {@code create:sso_access_tickets} scope is needed |
| 193 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket</a> |
| 194 | + * @param id the self-service profile ID. |
| 195 | + * @param payload the payload. |
| 196 | + * @return a Request to execute. |
| 197 | + */ |
| 198 | + public Request<SsoAccessTicketResponse> createSsoAccessTicket(String id, Object payload) { |
| 199 | + Asserts.assertNotNull(id, "id"); |
| 200 | + Asserts.assertNotNull(payload, "payload"); |
| 201 | + |
| 202 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 203 | + .addPathSegments(ORGS_PATH) |
| 204 | + .addPathSegment(id) |
| 205 | + .addPathSegment("sso-ticket"); |
| 206 | + |
| 207 | + String url = builder.build().toString(); |
| 208 | + |
| 209 | + BaseRequest<SsoAccessTicketResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SsoAccessTicketResponse>() { |
| 210 | + }); |
| 211 | + request.setBody(payload); |
| 212 | + return request; |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Revoke an SSO ticket. |
| 217 | + * A token with {@code delete:sso_access_tickets} scope is needed |
| 218 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke</a> |
| 219 | + * @param id the self-service profile ID. |
| 220 | + * @param ticketId the ticket ID. |
| 221 | + * @return a Request to execute. |
| 222 | + */ |
| 223 | + public Request<Void> revokeSsoTicket(String id, String ticketId) { |
| 224 | + Asserts.assertNotNull(id, "id"); |
| 225 | + Asserts.assertNotNull(ticketId, "ticket id"); |
| 226 | + |
| 227 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 228 | + .addPathSegments(ORGS_PATH) |
| 229 | + .addPathSegment(id) |
| 230 | + .addPathSegment("sso-ticket") |
| 231 | + .addPathSegment(ticketId) |
| 232 | + .addPathSegment("revoke"); |
| 233 | + |
| 234 | + String url = builder.build().toString(); |
| 235 | + |
| 236 | + return new EmptyBodyVoidRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Void>() { |
| 237 | + }); |
| 238 | + } |
| 239 | +} |
0 commit comments