diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingActivityRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingActivityRecordSet.java new file mode 100644 index 000000000..295f842f9 --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingActivityRecordSet.java @@ -0,0 +1,154 @@ +/* + * 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.net.auth; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.guacamole.GuacamoleException; + +/** + * ActivityRecordSet implementation which simplifies decorating the records + * within an underlying ActivityRecordSet. The decorate() function must be + * implemented to define how each record is decorated. As ActivityRecordSets + * are read-only, there is no need to define an undecorate() function as + * required by {@link DecoratingDirectory}. + * + * @param + * The type of records stored within this ActivityRecordSet. + */ +public abstract class DecoratingActivityRecordSet + extends DelegatingActivityRecordSet { + + /** + * Creates a new DecoratingActivityRecordSet which decorates the records + * within the given set. + * + * @param recordSet + * The ActivityRecordSet whose records are being decorated. + */ + public DecoratingActivityRecordSet(ActivityRecordSet recordSet) { + super(recordSet); + } + + /** + * Given a record retrieved from a ActivityRecordSet which originates from + * a different AuthenticationProvider, returns an identical type of record + * optionally wrapped with additional information, functionality, etc. If + * this record set chooses to decorate the record provided, it is up to the + * implementation of that decorated record to properly pass through + * operations as appropriate. All records retrieved from this + * DecoratingActivityRecordSet will first be passed through this function. + * + * @param record + * A record from a ActivityRecordSet which originates from a different + * AuthenticationProvider. + * + * @return + * A record which may have been decorated by this + * DecoratingActivityRecordSet. If the record was not decorated, the + * original, unmodified record may be returned instead. + * + * @throws GuacamoleException + * If the provided record cannot be decorated due to an error. + */ + protected abstract RecordType decorate(RecordType record) + throws GuacamoleException; + + /** + * Given an ActivityRecordSet which originates from a different + * AuthenticationProvider, returns an identical type of record set + * optionally wrapped with additional information, functionality, etc. If + * this record set chooses to decorate the record set provided, it is up to + * the implementation of that decorated record set to properly pass through + * operations as appropriate. All record sets retrieved from this + * DecoratingActivityRecordSet will first be passed through this function, + * such as those returned by {@link #limit(int)} and similar functions. + *

+ * By default, this function will wrap any provided ActivityRecordSet in a + * simple, anonymous instance of DecoratingActivityRecordSet that delegates + * to the decorate() implementations of this DecoratingActivityRecordSet. + * This default behavior may need to be overridden if the + * DecoratingActivityRecordSet implementation maintains any internal + * state. + * + * @param recordSet + * An ActivityRecordSet which originates from a different + * AuthenticationProvider. + * + * @return + * A record set which may have been decorated by this + * DecoratingActivityRecordSet. If the record set was not decorated, the + * original, unmodified record set may be returned instead, however + * beware that this may result in records within the set no longer + * being decorated. + * + * @throws GuacamoleException + * If the provided record set cannot be decorated due to an error. + */ + protected ActivityRecordSet decorate(ActivityRecordSet recordSet) + throws GuacamoleException { + final DecoratingActivityRecordSet decorator = this; + return new DecoratingActivityRecordSet(recordSet) { + + @Override + protected RecordType decorate(RecordType record) throws GuacamoleException { + return decorator.decorate(record); + } + + @Override + protected ActivityRecordSet decorate(ActivityRecordSet recordSet) + throws GuacamoleException { + return decorator.decorate(recordSet); + } + + }; + } + + @Override + public ActivityRecordSet sort(SortableProperty property, + boolean desc) throws GuacamoleException { + return decorate(super.sort(property, desc)); + } + + @Override + public ActivityRecordSet limit(int limit) throws GuacamoleException { + return decorate(super.limit(limit)); + } + + @Override + public ActivityRecordSet contains(String value) throws GuacamoleException { + return decorate(super.contains(value)); + } + + @Override + public Collection asCollection() throws GuacamoleException { + + Collection records = super.asCollection(); + + List decoratedRecords = new ArrayList<>(records.size()); + for (RecordType record : records) + decoratedRecords.add(decorate(record)); + + return decoratedRecords; + + } + +} diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecord.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecord.java new file mode 100644 index 000000000..1a9b30ee0 --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecord.java @@ -0,0 +1,94 @@ +/* + * 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.net.auth; + +import java.util.Date; +import java.util.Map; +import java.util.UUID; + +/** + * ActivityRecord implementation which simply delegates all function calls to an + * underlying ActivityRecord. + */ +public class DelegatingActivityRecord implements ActivityRecord { + + /** + * The wrapped ActivityRecord. + */ + private final ActivityRecord record; + + /** + * Wraps the given ActivityRecord such that all function calls against this + * DelegatingActivityRecord will be delegated to it. + * + * @param record + * The record to wrap. + */ + public DelegatingActivityRecord(ActivityRecord record) { + this.record = record; + } + + /** + * Returns the underlying ActivityRecord wrapped by this + * DelegatingActivityRecord. + * + * @return + * The ActivityRecord wrapped by this DelegatingActivityRecord. + */ + protected ActivityRecord getDelegateActivityRecord() { + return record; + } + + @Override + public Date getStartDate() { + return record.getStartDate(); + } + + @Override + public Date getEndDate() { + return record.getEndDate(); + } + + @Override + public String getRemoteHost() { + return record.getRemoteHost(); + } + + @Override + public String getUsername() { + return record.getUsername(); + } + + @Override + public boolean isActive() { + return record.isActive(); + } + + @Override + public UUID getUUID() { + return record.getUUID(); + } + + @Override + public Map getAttributes() { + return record.getAttributes(); + } + +} diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecordSet.java new file mode 100644 index 000000000..32ecd2198 --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingActivityRecordSet.java @@ -0,0 +1,83 @@ +/* + * 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.net.auth; + +import java.util.Collection; +import org.apache.guacamole.GuacamoleException; + +/** + * ActivityRecordSet implementation which simply delegates all function calls + * to an underlying ActivityRecordSet. + * + * @param + * The type of ActivityRecord contained within this set. + */ +public class DelegatingActivityRecordSet + implements ActivityRecordSet { + + /** + * The wrapped ActivityRecordSet. + */ + private final ActivityRecordSet recordSet; + + /** + * Wraps the given ActivityRecordSet such that all function calls against this + * DelegatingActivityRecordSet will be delegated to it. + * + * @param recordSet + * The ActivityRecordSet to wrap. + */ + public DelegatingActivityRecordSet(ActivityRecordSet recordSet) { + this.recordSet = recordSet; + } + + /** + * Returns the underlying ActivityRecordSet wrapped by this + * DelegatingActivityRecordSet. + * + * @return + * The ActivityRecordSet wrapped by this DelegatingActivityRecordSet. + */ + protected ActivityRecordSet getDelegateActivityRecordSet() { + return recordSet; + } + + @Override + public Collection asCollection() throws GuacamoleException { + return recordSet.asCollection(); + } + + @Override + public ActivityRecordSet contains(String value) throws GuacamoleException { + return recordSet.contains(value); + } + + @Override + public ActivityRecordSet limit(int limit) throws GuacamoleException { + return recordSet.limit(limit); + } + + @Override + public ActivityRecordSet sort(SortableProperty property, + boolean desc) throws GuacamoleException { + return recordSet.sort(property, desc); + } + +} diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionRecord.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionRecord.java new file mode 100644 index 000000000..4d953b4bb --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionRecord.java @@ -0,0 +1,81 @@ +/* + * 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.net.auth; + +import java.util.Date; +import java.util.Map; +import java.util.UUID; + +/** + * ConnectionRecord implementation which simply delegates all function calls to + * an underlying ConnectionRecord. + */ +public class DelegatingConnectionRecord extends DelegatingActivityRecord + implements ConnectionRecord { + + /** + * The wrapped ConnectionRecord. + */ + private final ConnectionRecord record; + + /** + * Wraps the given ConnectionRecord such that all function calls against + * this DelegatingConnectionRecord will be delegated to it. + * + * @param record + * The record to wrap. + */ + public DelegatingConnectionRecord(ConnectionRecord record) { + super(record); + this.record = record; + } + + /** + * Returns the underlying ConnectionRecord wrapped by this + * DelegatingConnectionRecord. + * + * @return + * The ConnectionRecord wrapped by this DelegatingConnectionRecord. + */ + protected ConnectionRecord getDelegateConnectionRecord() { + return record; + } + + @Override + public String getConnectionIdentifier() { + return record.getConnectionIdentifier(); + } + + @Override + public String getConnectionName() { + return record.getConnectionName(); + } + + @Override + public String getSharingProfileIdentifier() { + return record.getSharingProfileIdentifier(); + } + + @Override + public String getSharingProfileName() { + return record.getSharingProfileName(); + } + +}