necouchman commented on code in PR #830: URL: https://github.com/apache/guacamole-client/pull/830#discussion_r1218588036
########## 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: Ah, okay - so that should be doable given the way it's currently implemented. The "Allow" rules are evaluated first, followed by the "Deny" rules, which means the "Deny" rules would take precedence. So, you should be able to: 1. Add an Allow rule for "All Days" and select 09:00 - 17:00. 2. Add a Deny rule for Saturday, and one for Sunday, and select 00:00 to 23:59. -- 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: dev-unsubscr...@guacamole.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org