[DMAAP-KAFKA] Release image 1.1.0
[dmaap/kafka11aaf.git] / src / main / java / org / onap / dmaap / kafkaauthorize / PlainLoginModule1.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  Modification copyright (C) 2021 Nordix Foundation.
7  *  ================================================================================
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *        http://www.apache.org/licenses/LICENSE-2.0
12 *  
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *  ============LICENSE_END=========================================================
19  *  
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.kafkaauthorize;
23
24 import java.util.Map;
25 import javax.security.auth.Subject;
26 import javax.security.auth.callback.CallbackHandler;
27 import javax.security.auth.spi.LoginModule;
28
29 public class PlainLoginModule1 implements LoginModule {
30
31         private static final String USERNAME_CONFIG = "username";
32         private static final String PASSWORD_CONFIG = "password";
33
34         static {
35                 PlainSaslServerProvider1.initialize();
36         }
37
38         @Override
39         public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
40                 String username = (String) options.get(USERNAME_CONFIG);
41                 if (username != null)
42                         subject.getPublicCredentials().add(username);
43                 String password = (String) options.get(PASSWORD_CONFIG);
44                 if (password != null)
45                         subject.getPrivateCredentials().add(password);
46
47         }
48
49         @Override
50         public boolean login() {
51                 return true;
52         }
53
54         @Override
55         public boolean logout() {
56                 return true;
57         }
58
59         @Override
60         public boolean commit() {
61                 return true;
62         }
63
64         @Override
65         public boolean abort() {
66                 return false;
67         }
68 }