Subversion Repositories XServices

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
150 brianR 1
/*
2
 *   Copyright 2014 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
package net.brutex.emitter;
17
 
18
import java.io.UnsupportedEncodingException;
19
import java.net.MalformedURLException;
20
import java.net.URL;
21
 
22
import org.apache.log4j.Logger;
23
 
24
/**
25
 * The EventManagerContext class represents the eventmanager endpoint and authentication credentials.
26
 *
27
 * @author Brian Rosenberger, bru(at)brutex.de
28
 * @since 0.1
29
 */
30
public class EventManagerContext {
31
 
32
	private Logger logger = Logger.getLogger(EventManagerContext.class);
33
 
34
	private final URL url;
35
	private final String user;
36
	private final byte[] pass;
37
 
38
	private static final String CHARSET_UTF8 = "UTF-8";
39
 
40
	/**
41
	 * Create a new Eventmanager context.
42
	 *
43
	 * @param url	URL for the SBM ALF Eventmanager
44
	 * @param username	ALFSecurity user name
45
	 * @param password  ALFSecurity password
46
	 * @throws MalformedURLException
47
	 */
48
	public EventManagerContext(String url, String username, String password) throws MalformedURLException {
49
		//Verify URL
50
		try {
51
			this.url = new URL(url);
52
		} catch (MalformedURLException e) {
53
			logger.error(String.format("Could not parse '%s' as a valid URL. %s", url, e.getMessage()));
54
			throw e;
55
		}
56
 
57
		//Verify username
58
		this.user = username;
59
		if(this.user==null) {
60
			final String s = "Username for ALF Eventmanager cannot be null.";
61
			logger.error(s);
62
			throw new IllegalArgumentException(s);
63
		}
64
 
65
		//Verify password
66
		try {
67
			this.pass = password.getBytes(CHARSET_UTF8);
68
		} catch (UnsupportedEncodingException e) {
69
			e.printStackTrace();
70
			throw new IllegalArgumentException(e.getMessage());
71
		}
72
		if(this.pass==null) {
73
			final String s = "Password for ALF Eventmanager cannot be null.";
74
			logger.error(s);
75
			throw new IllegalArgumentException(s);
76
		}
77
 
78
	}
79
 
80
	public URL getUrl() {
81
		return url;
82
	}
83
 
84
	public String getUser() {
85
		return user;
86
	}
87
 
88
	public byte[] getPass() {
89
		return pass;
90
	}
91
}