1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.web.admin.accesstoken;
17
18 import org.codelibs.fess.app.web.CrudMode;
19 import org.codelibs.fess.util.ComponentUtil;
20 import org.codelibs.fess.validation.CustomSize;
21 import org.lastaflute.web.validation.Required;
22 import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
23
24 import jakarta.validation.constraints.Pattern;
25 import jakarta.validation.constraints.Size;
26
27 /**
28 * Form class for creating access tokens in the admin interface.
29 * This form handles the creation of API access tokens with configurable permissions and expiration dates.
30 */
31 public class CreateForm {
32
33 /**
34 * Creates a new CreateForm instance.
35 */
36 public CreateForm() {
37 // Default constructor
38 }
39
40 /**
41 * The CRUD operation mode for this form.
42 * Indicates whether this is a create, read, update, or delete operation.
43 */
44 @ValidateTypeFailure
45 public Integer crudMode;
46
47 /**
48 * The name of the access token.
49 * This is a required field with a maximum length of 1000 characters.
50 */
51 @Required
52 @Size(max = 1000)
53 public String name;
54
55 /**
56 * The actual access token string.
57 * This is the token value that will be used for authentication.
58 * Maximum length is 10000 characters.
59 */
60 @Size(max = 10000)
61 public String token;
62
63 /**
64 * The permissions associated with this access token.
65 * Defines what operations and resources this token can access.
66 */
67 @CustomSize(maxKey = "form.admin.max.input.size")
68 public String permissions;
69
70 /**
71 * The parameter name for the access token.
72 * This field specifies how the token should be passed in API requests.
73 * Maximum length is 10000 characters.
74 */
75 @Size(max = 10000)
76 public String parameterName;
77
78 /**
79 * The expiration date and time for the access token.
80 * Must be in ISO 8601 format: YYYY-MM-DDTHH:MM:SS
81 */
82 @Pattern(regexp = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]")
83 public String expires;
84
85 /**
86 * The username of the user who created this access token.
87 * Maximum length is 1000 characters.
88 */
89 @Size(max = 1000)
90 public String createdBy;
91
92 /**
93 * The timestamp when this access token was created.
94 * Stored as a long value representing milliseconds since epoch.
95 */
96 @ValidateTypeFailure
97 public Long createdTime;
98
99 /**
100 * Initializes the form with default values for creation.
101 * Sets the CRUD mode to CREATE and populates created by and created time fields
102 * with current user and timestamp information.
103 */
104 public void initialize() {
105 crudMode = CrudMode.CREATE;
106 createdBy = ComponentUtil.getSystemHelper().getUsername();
107 createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
108 }
109 }