|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | +package io.kubernetes.client.util.authenticators; |
| 14 | + |
| 15 | +import io.kubernetes.client.util.KubeConfig; |
| 16 | +import java.util.Date; |
| 17 | +import java.util.Map; |
| 18 | + |
| 19 | +/** |
| 20 | + * The Authenticator interface represents a plugin that can handle a specific type of authentication |
| 21 | + * information (e.g. 'azure') |
| 22 | + */ |
| 23 | +public class AzureActiveDirectoryAuthenticator implements Authenticator { |
| 24 | + static { |
| 25 | + KubeConfig.registerAuthenticator(new AzureActiveDirectoryAuthenticator()); |
| 26 | + } |
| 27 | + |
| 28 | + private static final String ACCESS_TOKEN = "access-token"; |
| 29 | + private static final String EXPIRES_ON = "expires-on"; |
| 30 | + |
| 31 | + @Override |
| 32 | + public String getName() { |
| 33 | + return "azure"; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public String getToken(Map<String, Object> config) { |
| 38 | + return (String) config.get(ACCESS_TOKEN); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public boolean isExpired(Map<String, Object> config) { |
| 43 | + String expiresOn = (String) config.get(EXPIRES_ON); |
| 44 | + Date expiry = new Date(Long.parseLong(expiresOn) * 1000); |
| 45 | + if (expiry != null && expiry.compareTo(new Date()) <= 0) { |
| 46 | + return true; |
| 47 | + } |
| 48 | + return false; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public Map<String, Object> refresh(Map<String, Object> config) { |
| 53 | + throw new RuntimeException("Unimplemented"); |
| 54 | + } |
| 55 | +} |
0 commit comments