Remove unneeded service declaration
[aaa.git] / aaa-password-service / impl / src / main / java / org / opendaylight / aaa / impl / password / service / OSGiPasswordHashService.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.impl.password.service;
9
10 import org.opendaylight.aaa.api.password.service.PasswordHash;
11 import org.opendaylight.aaa.api.password.service.PasswordHashService;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.password.service.config.rev170619.PasswordServiceConfig;
13 import org.osgi.service.component.annotations.Component;
14 import org.osgi.service.component.annotations.Reference;
15 import org.osgi.service.component.annotations.ReferenceCardinality;
16 import org.osgi.service.component.annotations.ReferencePolicy;
17
18 @Component(immediate = true, property = "type=default")
19 public final class OSGiPasswordHashService implements PasswordHashService {
20     private volatile DefaultPasswordHashService delegate = null;
21
22     @Override
23     public PasswordHash getPasswordHash(final String password) {
24         return delegate.getPasswordHash(password);
25     }
26
27     @Override
28     public PasswordHash getPasswordHash(final String password, final String salt) {
29         return delegate.getPasswordHash(password, salt);
30     }
31
32     @Override
33     public boolean passwordsMatch(final String plaintext, final String stored, final String salt) {
34         return delegate.passwordsMatch(plaintext, stored, salt);
35     }
36
37     @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MANDATORY)
38     void bindConfig(final PasswordServiceConfig config) {
39         updatedConfig(config);
40     }
41
42     void unbindConfig(final PasswordServiceConfig config) {
43         delegate = null;
44     }
45
46     void updatedConfig(final PasswordServiceConfig config) {
47         delegate = new DefaultPasswordHashService(config);
48     }
49 }