Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) Orchestral Developments Ltd and the Orion Health group of companies (2001 - 2018).
- *
- * This document is copyright. Except for the purpose of fair reviewing, no part
- * of this publication may be reproduced or transmitted in any form or by any
- * means, electronic or mechanical, including photocopying, recording, or any
- * information storage and retrieval system, without permission in writing from
- * the publisher. Infringers of copyright render themselves liable for
- * prosecution.
- */
- package com.orchestral.releasemanagement.compatibilitymanager;
- import java.io.IOException;
- import java.util.Properties;
- import org.apache.commons.codec.binary.Base64;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- public class Credentials {
- private static final Logger LOGGER = LoggerFactory.getLogger(Credentials.class);
- private static final String LDAP_CONFIG_FILE = "ldap-credentials.properties";
- private final String USERNAME;
- private final String PASSWORD;
- private final String BASIC_AUTHENTICATION;
- private Credentials() {
- LOGGER.debug("Creating new instance of Credentials");
- Properties properties = null;
- try {
- properties = PropertiesHelper.load(LDAP_CONFIG_FILE);
- } catch (final IOException e) {
- LOGGER.error("Couldn't load credentials properties file: {}", LDAP_CONFIG_FILE);
- e.printStackTrace();
- System.exit(1);
- }
- this.USERNAME = properties.getProperty("username", "");
- this.PASSWORD = properties.getProperty("password", "");
- this.BASIC_AUTHENTICATION = new String(Base64.encodeBase64((this.USERNAME + ":" + this.PASSWORD).getBytes()));
- LOGGER.debug("Credentials object has been created");
- }
- private static class CredentialsHolder {
- private static final Credentials INSTANCE = new Credentials();
- }
- public static Credentials getInstance() {
- return CredentialsHolder.INSTANCE;
- }
- public String getUsername() {
- return this.USERNAME;
- }
- public String getPassword() {
- return this.PASSWORD;
- }
- public String getHttpBasicAuthentication() {
- return this.BASIC_AUTHENTICATION;
- }
- private Credentials(final String configFileName) {
- Properties properties = null;
- try {
- properties = PropertiesHelper.load(configFileName);
- } catch (final IOException e) {
- LOGGER.error("Couldn't load credentials properties file: {}", configFileName);
- e.printStackTrace();
- System.exit(1);
- }
- this.USERNAME = properties.getProperty("username", "");
- this.PASSWORD = properties.getProperty("password", "");
- this.BASIC_AUTHENTICATION = new String(Base64.encodeBase64((this.USERNAME + ":" + this.PASSWORD).getBytes()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement