necouchman commented on code in PR #830: URL: https://github.com/apache/guacamole-client/pull/830#discussion_r1218440828
########## 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, good point, I had not considered that. I guess I see the following options: * See if there's an existing Java class that contains the various locales and Weekday/Weekend mappings. * Create a custom class and/or enum that contains this data, and try to somehow map that to the current system locale and/or user locale. * Create a guacamole.properties item to configure weekend and weekday days. * Rework the UX a little bit, removing these specific Weekday/Weekend entries, but then creating a multi-select interface of some sort where multiple days could be selected. Or, something else, if anyone has any other ideas? ########## extensions/guacamole-auth-restrict/pom.xml: ########## @@ -0,0 +1,191 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.guacamole</groupId> + <artifactId>guacamole-auth-restrict</artifactId> + <packaging>jar</packaging> + <version>1.5.1</version> + <name>guacamole-auth-restrict</name> + <url>http://guacamole.apache.org/</url> + + <parent> + <groupId>org.apache.guacamole</groupId> + <artifactId>extensions</artifactId> + <version>1.5.1</version> + <relativePath>../</relativePath> + </parent> + + <build> + <plugins> + + <!-- Pre-cache Angular templates with maven-angular-plugin --> + <plugin> + <groupId>com.keithbranton.mojo</groupId> + <artifactId>angular-maven-plugin</artifactId> + <version>0.3.4</version> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>html2js</goal> + </goals> + </execution> + </executions> + <configuration> + <sourceDir>${basedir}/src/main/resources</sourceDir> + <include>**/*.html</include> + <target>${basedir}/src/main/resources/generated/templates-main/templates.js</target> + <prefix>app/ext/restrict</prefix> + </configuration> + </plugin> + + <!-- JS/CSS Minification Plugin --> + <plugin> + <groupId>com.github.buckelieg</groupId> + <artifactId>minify-maven-plugin</artifactId> + <executions> + <execution> + <id>default-cli</id> + <configuration> + <charset>UTF-8</charset> + + <webappSourceDir>${basedir}/src/main/resources</webappSourceDir> + <webappTargetDir>${project.build.directory}/classes</webappTargetDir> + + <cssSourceDir>/</cssSourceDir> + <cssTargetDir>/</cssTargetDir> + <cssFinalFile>restrict.css</cssFinalFile> + + <cssSourceFiles> + <cssSourceFile>license.txt</cssSourceFile> + </cssSourceFiles> + + <cssSourceIncludes> + <cssSourceInclude>**/*.css</cssSourceInclude> + </cssSourceIncludes> + + <jsSourceDir>/</jsSourceDir> + <jsTargetDir>/</jsTargetDir> + <jsFinalFile>restrict.js</jsFinalFile> + + <jsSourceFiles> + <jsSourceFile>license.txt</jsSourceFile> + </jsSourceFiles> + + <jsSourceIncludes> + <jsSourceInclude>**/*.js</jsSourceInclude> + </jsSourceIncludes> + + <!-- Do not minify and include tests --> + <jsSourceExcludes> + <jsSourceExclude>**/*.test.js</jsSourceExclude> + </jsSourceExcludes> + <jsEngine>CLOSURE</jsEngine> + + <!-- Disable warnings for JSDoc annotations --> + <closureWarningLevels> + <misplacedTypeAnnotation>OFF</misplacedTypeAnnotation> + <nonStandardJsDocs>OFF</nonStandardJsDocs> + </closureWarningLevels> + + </configuration> + <goals> + <goal>minify</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <dependencies> + + <!-- Guacamole Extension API --> + <dependency> + <groupId>org.apache.guacamole</groupId> + <artifactId>guacamole-ext</artifactId> + <version>1.5.1</version> Review Comment: Yep, will rework for 1.5.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: dev-unsubscr...@guacamole.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org