necouchman commented on code in PR #830:
URL: https://github.com/apache/guacamole-client/pull/830#discussion_r1218472369


##########
extensions/guacamole-auth-restrict/src/main/java/org/apache/guacamole/calendar/TimeRestrictionParser.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.calendar;
+
+import java.time.DayOfWeek;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A class for parsing time-based restrictions stored in a String into other
+ * formats that can be used by Guacamole.
+ */
+public class TimeRestrictionParser {
+    
+    /**
+     * The compiled regular expression that matches one or more instances of
+     * a restriction string, which specifies at least one day and time range
+     * that the restriction applies to.
+     * 
+     * <p>Examples of valid restrictions are as follows:
+     * <ul>
+     * <li>1:0700-1700 - Monday from 07:00 to 17:00
+     * <li>7:0000-2359 - Sunday, all day (00:00 to 23:59)
+     * <li>wd:0900-1700 - Monday through Friday, 09:00 to 17:00
+     * <li>we:0900-1700 - Saturday and Sunday, 09:00 to 17:00
+     * <li>6:0900-1600;7:1200-1300 - Saturday, 09:00 to 16:00, and Sunday, 
+     * 12:00 - 13:00
+     * </ul>
+     */
+    private static final Pattern RESTRICTION_REGEX = 
+            
Pattern.compile("(?:^|;)+([1-7*]|(?:[w][ed]))(?::((?:[01][0-9]|2[0-3])[0-5][0-9])\\-((?:[01][0-9]|2[0-3])[0-5][0-9]))+");
+    
+    /**
+     * The RegEx group that contains the start day-of-week of the restriction.
+     */
+    private static final int RESTRICTION_DAY_GROUP = 1;
+    
+    /**
+     * The RegEx group that contains the start time of the restriction.
+     */
+    private static final int RESTRICTION_TIME_START_GROUP = 2;
+    
+    /**
+     * The RegEx group that contains the end time of the restriction.
+     */
+    private static final int RESTRICTION_TIME_END_GROUP = 3;
+    
+    /**
+     * A list of DayOfWeek items that make up weekdays.
+     */
+    private static final List<DayOfWeek> RESTRICTION_WEEKDAYS = Arrays.asList(
+            DayOfWeek.MONDAY,
+            DayOfWeek.TUESDAY,
+            DayOfWeek.WEDNESDAY,
+            DayOfWeek.THURSDAY,
+            DayOfWeek.FRIDAY
+    );
+    
+    /**
+     * A list of DayOfWeek items that make up weekends.
+     */
+    private static final List<DayOfWeek> RESTRICTION_WEEKEND = Arrays.asList(
+            DayOfWeek.SATURDAY,
+            DayOfWeek.SUNDAY
+    );

Review Comment:
   > One possibility would be to just get rid of the weekday / weekend 
distinction - you can always still create a "employees can only log in between 
9 and 5 on M-F" sort of restriction like what I suggested in [#830 
(comment)](https://github.com/apache/guacamole-client/pull/830#issuecomment-1506083282).
   
   Maybe I misunderstood what you were getting at with this in your original 
comment. Are you thinking of some way that people would be able to enter a 
custom restriction set, maybe even using the way it is stored in the database, 
that allows for easier entry than selecting a day and enter start and end 
times? Or just enter the days (M-F) for the day field instead of selecting from 
the drop-down?
   
   > 
   > So I guess option 3 would be what I lean towards. Allowing configurable 
weekdays / weekends sounds a bit overkill to me. I'm happy to be convinced 
otherwise though. You could even possibly just skip the multi drop down, and 
just add e.g. individual rules for Saturday and for Sunday.
   
   So, you're saying, allow "weekend" and "weekday" to be defined in 
guacamole.properties, and not worry about a separate class where you track 
different weekend and weekday values for each locale (option 2)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to