org.solovyev.common.security.SecurityServiceConverter Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013 serso aka se.solovyev
*
* 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.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: [email protected]
* Site: http://se.solovyev.org/java/jcl
*/
package org.solovyev.common.security;
import org.solovyev.common.Converter;
import javax.annotation.Nonnull;
/**
* User: serso
* Date: 2/9/13
* Time: 5:23 PM
*/
public class SecurityServiceConverter implements SecurityService {
@Nonnull
private final SecurityService securityService;
@Nonnull
private final Cipherer cipherer;
@Nonnull
private final HashProvider hashProvider;
private SecurityServiceConverter(@Nonnull SecurityService securityService,
@Nonnull Cipherer cipherer,
@Nonnull HashProvider hashProvider) {
this.securityService = securityService;
this.cipherer = cipherer;
this.hashProvider = hashProvider;
}
@Nonnull
public static SecurityService wrap(@Nonnull SecurityService securityService,
@Nonnull Converter decoder,
@Nonnull Converter encoder) {
final Cipherer cipherer = TypedCipherer.newInstance(securityService.getCipherer(), decoder, encoder);
final HashProvider hashProvider = TypedHashProvider.newInstance(securityService.getHashProvider(), decoder, encoder);
return new SecurityServiceConverter(securityService, cipherer, hashProvider);
}
@Nonnull
public static SecurityServiceConverter wrap(@Nonnull SecurityService securityService,
@Nonnull Converter decryptedDecoder,
@Nonnull Converter decryptedEncoder,
@Nonnull Converter encryptedDecoder,
@Nonnull Converter encryptedEncoder) {
return wrap(securityService, decryptedDecoder, decryptedEncoder, encryptedDecoder, encryptedEncoder, encryptedEncoder);
}
@Nonnull
public static SecurityServiceConverter wrap(@Nonnull SecurityService securityService,
@Nonnull Converter decryptedDecoder,
@Nonnull Converter decryptedEncoder,
@Nonnull Converter encryptedDecoder,
@Nonnull Converter encryptedEncoder,
@Nonnull Converter hashConverter) {
final Cipherer cipherer = TypedCipherer.newInstance(securityService.getCipherer(), decryptedDecoder, decryptedEncoder, encryptedDecoder, encryptedEncoder);
final HashProvider hashProvider = TypedHashProvider.newInstance(securityService.getHashProvider(), decryptedDecoder, hashConverter);
return new SecurityServiceConverter(securityService, cipherer, hashProvider);
}
@Nonnull
@Override
public SaltGenerator getSaltGenerator() {
return securityService.getSaltGenerator();
}
@Nonnull
@Override
public SecretKeyProvider getSecretKeyProvider() {
return securityService.getSecretKeyProvider();
}
@Nonnull
@Override
public HashProvider getHashProvider() {
return hashProvider;
}
@Nonnull
@Override
public Cipherer getCipherer() {
return cipherer;
}
}