View as "text/plain" | Blame | Last modification | View Log | Download | RSS feed
/*
* Copyright 2014 Brian Rosenberger (Brutex Network)
*
* 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.
*/
package net.brutex.emitter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.Logger;
/**
* The EventManagerContext class represents the eventmanager endpoint and authentication credentials.
*
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.1
*/
public class EventManagerContext {
private Logger logger = Logger.getLogger(EventManagerContext.class);
private final URL url;
private final String user;
private final byte[] pass;
private static final String CHARSET_UTF8 = "UTF-8";
/**
* Create a new Eventmanager context.
*
* @param url URL for the SBM ALF Eventmanager
* @param username ALFSecurity user name
* @param password ALFSecurity password
* @throws MalformedURLException
*/
public EventManagerContext(String url, String username, String password) throws MalformedURLException {
//Verify URL
try {
this.url = new URL(url);
} catch (MalformedURLException e) {
logger.error(String.format("Could not parse '%s' as a valid URL. %s", url, e.getMessage()));
throw e;
}
//Verify username
this.user = username;
if(this.user==null) {
final String s = "Username for ALF Eventmanager cannot be null.";
logger.error(s);
throw new IllegalArgumentException(s);
}
//Verify password
try {
this.pass = password.getBytes(CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new IllegalArgumentException(e.getMessage());
}
if(this.pass==null) {
final String s = "Password for ALF Eventmanager cannot be null.";
logger.error(s);
throw new IllegalArgumentException(s);
}
}
public URL getUrl() {
return url;
}
public String getUser() {
return user;
}
public byte[] getPass() {
return pass;
}
}