
com.hazelcast.config.security.RealmConfig Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* 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
*
* 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 com.hazelcast.config.security;
import com.hazelcast.config.LoginModuleConfig;
import com.hazelcast.security.Credentials;
import com.hazelcast.security.ICredentialsFactory;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
/**
* Security realm represents the security configuration for part of the system (e.g. member-to-member communication).
*/
public class RealmConfig {
private AuthenticationConfig authenticationConfig = DefaultAuthenticationConfig.INSTANCE;
private IdentityConfig identityConfig;
public JaasAuthenticationConfig getJaasAuthenticationConfig() {
return getIfType(authenticationConfig, JaasAuthenticationConfig.class);
}
public RealmConfig setJaasAuthenticationConfig(JaasAuthenticationConfig authenticationConfig) {
this.authenticationConfig = requireNonNull(authenticationConfig, "Authentication config can't be null");
return this;
}
public TokenIdentityConfig getTokenIdentityConfig() {
return getIfType(identityConfig, TokenIdentityConfig.class);
}
public RealmConfig setCredentials(Credentials credentials) {
this.identityConfig = new CredentialsIdentityConfig(credentials);
return this;
}
public boolean isAuthenticationConfigured() {
return authenticationConfig != null && authenticationConfig != DefaultAuthenticationConfig.INSTANCE;
}
public LoginModuleConfig[] asLoginModuleConfigs() {
return authenticationConfig.asLoginModuleConfigs();
}
public ICredentialsFactory asCredentialsFactory() {
return identityConfig != null ? identityConfig.asCredentialsFactory(null) : null;
}
@Override
public int hashCode() {
return Objects.hash(authenticationConfig, identityConfig);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
RealmConfig other = (RealmConfig) obj;
return Objects.equals(authenticationConfig, other.authenticationConfig)
&& Objects.equals(identityConfig, other.identityConfig);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RealmConfig [authenticationConfig=").append(authenticationConfig)
.append(", identityConfig=").append(identityConfig)
.append("]");
return builder.toString();
}
private T getIfType(Object inst, Class clazz) {
return clazz.isInstance(inst) ? clazz.cast(inst) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy