Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2021 Red Hat, Inc.
*
* 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 org.wildfly.security.credential.store.impl;
import static org.wildfly.security.credential.store._private.ElytronMessages.log;
import static org.wildfly.security.encryption.SecretKeyUtil.exportSecretKey;
import static org.wildfly.security.encryption.SecretKeyUtil.importSecretKey;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.spec.AlgorithmParameterSpec;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import javax.crypto.SecretKey;
import org.wildfly.common.codec.DecodeException;
import org.wildfly.security.credential.Credential;
import org.wildfly.security.credential.SecretKeyCredential;
import org.wildfly.security.credential.store.CredentialStore;
import org.wildfly.security.credential.store.CredentialStore.ProtectionParameter;
import org.wildfly.security.credential.store.CredentialStoreException;
import org.wildfly.security.credential.store.CredentialStoreSpi;
import org.wildfly.security.credential.store.UnsupportedCredentialTypeException;
import org.wildfly.security.util.AtomicFileOutputStream;
/**
* A {@link CredentialStore} implementation backed by a properties file.
*
* This is a simple implementation which only supports the storage of {@code SecretKey} credentials, additionally
* password protection of the store is not supported.
*
* @author Darran Lofthouse
*/
public class PropertiesCredentialStore extends CredentialStoreSpi {
/*
* Regular Expression To Test Valid Line In Credential Store.
*
* ^ - Apply test from the start of the line.
* \s* - Whitespace is allowed at the start.
* (#.*) - A comment character followed by one or more characters.
* OR (\\w+=[^=]+={0,2}\\s*)
* \w - Alpha numeric one or more times (The alias of the entry)
* = - A single '=' delimiter.
* [^=]+ - Any character other than '=' one or more times.
* ={0,2} - An '='up to two times (Base64 padding).
* \s* - Whitespace is allowed at the end.
* $ - Apply the test to the end of the line.
*/
private static final Pattern PATTERN = Pattern.compile("^\\s*(#.*)|(\\w+=[^=]+={0,2}\\s*)$");
public static final String NAME = PropertiesCredentialStore.class.getSimpleName();
private final String HEADER = "# Properties Credential Store (Do Not Modify)";
private static final char COMMENT = '#';
private static final char DELIMITER = '=';
private static final String CREATE = "create";
private static final String LOCATION = "location";
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
private final AtomicReference