jdeppe-pivotal commented on a change in pull request #6994: URL: https://github.com/apache/geode/pull/6994#discussion_r731232871
########## File path: geode-for-redis/src/main/java/org/apache/geode/redis/internal/services/SecurityServiceWrapper.java ########## @@ -0,0 +1,65 @@ +/* + * 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.geode.redis.internal.services; + +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import io.netty.channel.ChannelId; +import org.apache.shiro.subject.Subject; + +import org.apache.geode.internal.security.SecurityService; +import org.apache.geode.security.ResourcePermission; + +/** + * This class is a thin wrapper around Geode's {@link SecurityService} and delegates + * login (authenticate), logout and authorize calls. It exists as a central point to track whether + * a given channel (connection) has previously been authenticated. + */ +public class SecurityServiceWrapper { + + private final Map<String, Subject> subjects = new ConcurrentHashMap<>(); + + private final SecurityService securityService; + + public SecurityServiceWrapper(SecurityService securityService) { + this.securityService = securityService; + } + + public boolean isEnabled() { + return securityService.isIntegratedSecurity(); + } + + public boolean isAuthenticated(ChannelId channelId) { + return subjects.containsKey(channelId.asShortText()); + } + + public Subject login(ChannelId channelId, Properties properties) { + Subject subject = securityService.login(properties); + subjects.put(channelId.asShortText(), subject); + return subject; + } + + public void logout(ChannelId channelId) { + subjects.remove(channelId.asShortText()); Review comment: Previously `ExecutionHandlerContext.logout` was the only caller of this method and was performing a logout of the `Subject`. I've moved `Subject.logout()` into this method now to consolidate the logic a bit. -- 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]
