Skip to content

Commit

Permalink
GUACAMOLE-1020: Implement a new Restrictable interface and make sligh…
Browse files Browse the repository at this point in the history
…t name changes to classes.
  • Loading branch information
necouchman committed Jul 29, 2024
1 parent f86e6d7 commit e4e98e9
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.auth.restrict;

import org.apache.guacamole.calendar.RestrictionType;
import org.apache.guacamole.net.auth.Attributes;

/**
* An interface which defines methods that apply to items that can have
* restrictions applied to them.
*/
public interface Restrictable extends Attributes {

/**
* Return the restriction state for this restrictable object at the
* current date and time. By default returns an implicit denial.
*
* @return
* The restriction status for the current date and time.
*/
default public RestrictionType getCurrentTimeRestriction() {
return RestrictionType.IMPLICIT_DENY;
}

/**
* Return the restriction state for this restrictable object for the host
* from which the current user is logged in. By default returns an implicit
* denial.
*
* @return
* The restriction status for the host from which the current user is
* logged in.
*/
default public RestrictionType getCurrentHostRestriction() {
return RestrictionType.IMPLICIT_DENY;
}

/**
* Returns true if the current item is available based on the restrictions
* for the given implementation of this interface, or false if the item is
* not currently available. The default implementation checks current time
* and host restrictions, allowing if both those restrictions allow access.
*
* @return
* true if the item is available, otherwise false.
*/
default public boolean isAvailable() {
return (getCurrentTimeRestriction().isAllowed() && getCurrentHostRestriction().isAllowed());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package org.apache.guacamole.auth.restrict;

import com.google.inject.Guice;
import com.google.inject.Injector;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.restrict.user.RestrictUserContext;
import org.apache.guacamole.auth.restrict.user.RestrictedUserContext;
import org.apache.guacamole.net.auth.AbstractAuthenticationProvider;
import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.Credentials;
Expand All @@ -32,7 +34,7 @@
* administrators to further control access to Guacamole resources.
*/
public class RestrictionAuthenticationProvider extends AbstractAuthenticationProvider {

@Override
public String getIdentifier() {
return "restrict";
Expand All @@ -43,20 +45,23 @@ public UserContext decorate(UserContext context,
AuthenticatedUser authenticatedUser, Credentials credentials)
throws GuacamoleException {

String remoteAddress = credentials.getRemoteAddress();


// Verify identity of user
RestrictionVerificationService.verifyLoginRestrictions(context, authenticatedUser);
RestrictionVerificationService.verifyLoginRestrictions(context, remoteAddress);

// User has been verified, and authentication should be allowed to
// continue
return new RestrictUserContext(context, credentials.getRemoteAddress());
return new RestrictedUserContext(context, remoteAddress);

}

@Override
public UserContext redecorate(UserContext decorated, UserContext context,
AuthenticatedUser authenticatedUser, Credentials credentials)
throws GuacamoleException {
return new RestrictUserContext(context, credentials.getRemoteAddress());
return new RestrictedUserContext(context, credentials.getRemoteAddress());
}

}
Loading

0 comments on commit e4e98e9

Please sign in to comment.