Add apache-geode-extensions module containing classes implementing Apache Geode interfaces and SPIs.
These extensions will be used for testing and documentation purposes. For example, this module contains extensions to Apache Geode's o.a.g.security.SecurityManager and o.a.g.security.AuthInitialize interfaces used in the SBDG samples.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.geode.security;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.geode.LogWriter;
|
||||
import org.apache.geode.distributed.DistributedMember;
|
||||
import org.apache.geode.management.internal.security.ResourceConstants;
|
||||
import org.apache.geode.security.AuthInitialize;
|
||||
import org.apache.geode.security.AuthenticationFailedException;
|
||||
|
||||
/**
|
||||
* Simple, test {@link AuthInitialize} implementation.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.apache.geode.security.AuthInitialize
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class TestAuthInitialize implements AuthInitialize {
|
||||
|
||||
private static final String DEFAULT_USERNAME = "test";
|
||||
private static final String DEFAULT_PASSWORD = DEFAULT_USERNAME;
|
||||
|
||||
public static TestAuthInitialize create() {
|
||||
return new TestAuthInitialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init(LogWriter systemLogger, LogWriter securityLogger) throws AuthenticationFailedException { }
|
||||
|
||||
@Override
|
||||
public Properties getCredentials(Properties securityProperties, DistributedMember server, boolean isPeer)
|
||||
throws AuthenticationFailedException {
|
||||
|
||||
Properties credentials = new Properties();
|
||||
|
||||
credentials.setProperty(ResourceConstants.USER_NAME,
|
||||
securityProperties.getProperty(ResourceConstants.USER_NAME, DEFAULT_USERNAME));
|
||||
|
||||
credentials.setProperty(ResourceConstants.PASSWORD,
|
||||
securityProperties.getProperty(ResourceConstants.PASSWORD, DEFAULT_PASSWORD));
|
||||
|
||||
return credentials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.geode.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.Principal;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.geode.management.internal.security.ResourceConstants;
|
||||
import org.apache.geode.security.AuthenticationFailedException;
|
||||
|
||||
/**
|
||||
* Simple, test {@link org.apache.geode.security.SecurityManager}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.security.Principal
|
||||
* @see java.util.Properties
|
||||
* @see org.apache.geode.security.SecurityManager
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class TestSecurityManager implements org.apache.geode.security.SecurityManager {
|
||||
|
||||
@Override
|
||||
public Object authenticate(Properties credentials) throws AuthenticationFailedException {
|
||||
|
||||
String username = credentials.getProperty(ResourceConstants.USER_NAME);
|
||||
String password = credentials.getProperty(ResourceConstants.PASSWORD);
|
||||
|
||||
if (!String.valueOf(username).equals(password)) {
|
||||
throw new AuthenticationFailedException(String.format("User [%s] could not be authenticated", username));
|
||||
}
|
||||
|
||||
return User.create(username);
|
||||
}
|
||||
|
||||
public static class User implements Comparable<User>, Principal, Serializable {
|
||||
|
||||
public static User create(String name) {
|
||||
return new User(name);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
public User(String name) {
|
||||
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Username is required");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(User user) {
|
||||
return this.getName().compareTo(user.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof User)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
User that = (User) obj;
|
||||
|
||||
return this.getName().equals(that.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int hashValue = 17;
|
||||
|
||||
hashValue = 37 * hashValue + getName().hashCode();
|
||||
|
||||
return hashValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user