* @return
*/
protected boolean parse(HttpCode<TRANS, ?> code, String cntnt) {
- byte bytes[] = cntnt.getBytes();
+ byte[] bytes = cntnt.getBytes();
- int cis,cie=-1,cend;
- int sis,sie,send;
+ int cis;
+ int cie=-1;
+ int cend;
+ int sis;
+ int sie;
+ int send;
String name;
ArrayList<String> props = new ArrayList<>();
do {
}
}
- private static String MAX_AGE = "max-age=3600"; // 1 hour Caching
+ private static String maxAge = "max-age=3600"; // 1 hour Caching
private final Map<String,String> typeMap;
private final NavigableMap<String,Content> content;
private final Set<String> attachOnly;
- public final static String CFA_WEB_PATH = "aaf_cfa_web_path";
+ public static final String CFA_WEB_PATH = "aaf_cfa_web_path";
// when to re-validate from file
// Re validating means comparing the Timestamp on the disk, and seeing it has changed. Cache is not marked
// dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e.
// deployed GUI elements is unnecessary, and wastes time.
// This parameter exists to cover the cases where data can be more volatile, so the user can choose how often the
// File IO will be accessed, based on probability of change. "0", of course, means, check every time.
- private final static String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval";
- private final static String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit
- private final static String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command";
+ private static final String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval";
+ private static final String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit
+ private static final String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command";
// Note: can be null without a problem, but included
// to tie in with existing Logging.
public long checkInterval; // = 600000L; // only check if not hit in 10 mins by default
public int maxItemSize; // = 512000; // max file 500k
private Timer timer;
- private String web_path;
+ private String webPath;
// A command key is set in the Properties, preferably changed on deployment.
// it is compared at the beginning of the path, and if so, it is assumed to issue certain commands
// It's purpose is to protect, to some degree the command, even though it is HTTP, allowing
// local batch files to, for instance, clear caches on resetting of files.
- private String clear_command;
+ private String clearCommand;
+
+ public static final String TEXT_PLAIN = "text/plain";
public CachingFileAccess(EnvJAXB env, String ... args) throws IOException {
super(null,"Caching File Access");
typeMap.put("html","text/html");
typeMap.put("css","text/css");
typeMap.put("js","text/javascript");
- typeMap.put("txt","text/plain");
+ typeMap.put("txt", TEXT_PLAIN);
typeMap.put("xml","text/xml");
typeMap.put("xsd","text/xml");
attachOnly.add("xsd");
typeMap.put("jar","application/x-java-applet");
typeMap.put("jnlp", "application/x-java-jnlp-file");
typeMap.put("class", "application/java");
- typeMap.put("props", "text/plain");
+ typeMap.put("props", TEXT_PLAIN);
typeMap.put("jks", "application/octet-stream");
// Fonts
timer.schedule(new Cleanup(content,500),60000,60000);
// Property params
- web_path = env.get(env.staticSlot(CFA_WEB_PATH));
- env.init().log("CachingFileAccess path: " + new File(web_path).getCanonicalPath());
+ webPath = env.get(env.staticSlot(CFA_WEB_PATH));
+ env.init().log("CachingFileAccess path: " + new File(webPath).getCanonicalPath());
Object obj;
obj = env.get(env.staticSlot(CFA_CACHE_CHECK_INTERVAL),600000L); // Default is 10 mins
if (obj instanceof Long) {
maxItemSize =Integer.parseInt((String)obj);
}
- clear_command = env.getProperty(CFA_CLEAR_COMMAND,null);
+ clearCommand = env.getProperty(CFA_CLEAR_COMMAND,null);
}
public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException {
String key = pathParam(req, ":key");
int slash = key.indexOf('/');
- if(key.length()>2 && slash>=0 && key.substring(0,slash).equals(clear_command)) {
+ if(key.length()>2 && slash>=0 && key.substring(0,slash).equals(clearCommand)) {
resp.setHeader("Content-Type",typeMap.get("txt"));
if ("clear".equals(key.substring(slash+1))) {
content.clear();
}
return;
}
- Content c = load(logT , web_path,key, null, checkInterval);
+ Content c = load(logT , webPath,key, null, checkInterval);
if (c.attachmentOnly) {
resp.setHeader("Content-disposition", "attachment");
}
public String webPath() {
- return web_path;
+ return webPath;
}
/**
@Override
public void setHeader(HttpServletResponse resp) {
resp.setStatus(404/*NOT_FOUND_404*/);
- resp.setHeader("Content-type","text/plain");
+ resp.setHeader("Content-type",TEXT_PLAIN);
}
@Override
};
- private static abstract class Content {
+ private abstract static class Content {
private long date; // date of the actual artifact (i.e. File modified date)
private long access; // last accessed
public void setHeader(HttpServletResponse resp) {
resp.setStatus(200/*OK_200*/);
resp.setHeader("Content-Type",contentType);
- resp.setHeader("Cache-Control", MAX_AGE);
+ resp.setHeader("Cache-Control", maxAge);
}
public abstract void write(Writer writer) throws IOException;
}
Collections.sort(scont);
int end = size - ((maxSize/4)*3); // reduce to 3/4 of max size
- //System.out.println("------ Cleanup Cycle ------ " + new Date().toString() + " -------");
for (int i=0;i<end;++i) {
Entry<String, Content> entry = scont.get(i).entry;
content.remove(entry.getKey());
- //System.out.println("removed Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString());
}
-// for (int i=end;i<size;++i) {
-// Entry<String, Content> entry = scont.get(i).entry;
-// //System.out.println("remaining Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString());
-// }
}
}
}
package org.onap.aaf.auth.rserv;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
* @return
*/
protected boolean parse(HttpCode<TRANS,?> code, String cntnt) {
- byte bytes[] = cntnt.getBytes();
- boolean contType=false,contProp=true;
- int cis,cie=-1,cend;
- int sis,sie,send;
+ byte[] bytes = cntnt.getBytes();
+ boolean contType=false;
+ boolean contProp=true;
+ int cis;
+ int cie=-1;
+ int cend;
+ int sis;
+ int sie;
+ int send;
do {
cis = cie+1;
cie = cntnt.indexOf(',',cis);
send = sie>cend || sie<0?cend:sie;
if (me==null) {
String semi = new String(bytes,sis,send-sis);
- // trans.checkpoint(semi);
// Look at first entity within comma group
// Is this an acceptable Type?
me=types(code, semi);
if (eq>sis && eq<send) {
String tag = new String(bytes,sis,eq-sis);
String value = new String(bytes,eq+1,send-(eq+1));
- // trans.checkpoint(" Prop " + tag + "=" + value);
boolean bool = props(me,tag,value);
if (!bool) {
contProp=false;
return false;
}
- public boolean no_cache() {
+ public boolean noCache() {
return false;
}
*/
public class Match {
private Map<String, Integer> params;
- private byte[] values[];
- private Integer vars[];
+ private byte[][] values;
+ private Integer[] vars;
private boolean wildcard;
* a multi-field option, i.e. ending with a wild-card.
*/
public Match(String path) {
- // IF DEBUG: System.out.print("\n[" + path + "]");
params = new HashMap<>();
if (path!=null) {
String[] pa = path.split("/");
vars[i]=0; // this is actually a variable, if it only contains a "*"
}
}
- // vars[i]=null;
}
}
}
int lastField = values.length;
int lastByte = pabytes.length;
- boolean fieldMatched = false; // = lastByte>0?(pabytes[0]=='/'):false;
- // IF DEBUG: System.out.println("\n -- " + path + " --");
+ boolean fieldMatched = false;
for (int i=0;rv && i<lastByte;++i) {
if (field>=lastField) { // checking here allows there to be a non-functional ending /
rv = false;
if (end==0)end=start+1;
int k = i;
for (int j=start; j<end && k<lastByte; ++k) {
- // IF DEBUG: System.out.print((char)pabytes[k]);
if (pabytes[k]=='/') {
++field;
++j;
fieldMatched = false; // reset
fieldIdx = 0;
} else {
- // IF DEBUG: System.out.print((char)pabytes[i]);
if (pabytes[i]=='/') { // end of field, eval if Field is matched
// if double slash, check if supposed to be empty
if (fieldIdx==0 && values[field].length==0) {
response.setStatus(404); // Not Found
} else {
// Find best Code in Route based on "Accepts (Get) or Content-Type" (if exists)
- code = codesetter.code();// route.getCode(trans, request, response);
+ code = codesetter.code();
}
} finally {
tt.done();
private CadiHTTPManip cadi;
- private final String[] no_authn;
+ private final String[] noAuthn;
public TransFilter(Access access, Connector con, TrustChecker tc, Object ... additionalTafLurs) throws CadiException, LocatorException {
cadi = new CadiHTTPManip(access, con, tc, additionalTafLurs);
String no = access.getProperty(Config.CADI_NOAUTHN, null);
if (no!=null) {
- no_authn = Split.split(':', no);
+ noAuthn = Split.split(':', no);
} else {
- no_authn=null;
+ noAuthn =null;
}
}
try {
request.setAttribute(TRANS_TAG, trans);
- if (no_authn!=null) {
- for (String prefix : no_authn) {
+ if (noAuthn !=null) {
+ for (String prefix : noAuthn) {
if (req.getPathInfo().startsWith(prefix)) {
chain.doFilter(request, response);
return;
// Want Q percentage is to be first in the array everytime. If not listed, 1.0 is default
props.add(new Pair<String,Object>(Q,1f));
Pair<HttpCode<TRANS,?>, List<Pair<String,Object>>> cl = new Pair<HttpCode<TRANS,?>, List<Pair<String,Object>>>(code, props);
-// // breakup "plus" stuff, i.e. application/xaml+xml
-// int plus = str.indexOf('+');
-// if (plus<0) {
type = new Pair<String, Pair<HttpCode<TRANS,?>,List<Pair<String,Object>>>>(str, cl);
types.add(type);
return type;
-// } else {
-// int prev = str.indexOf('/')+1;
-// String first = str.substring(0,prev);
-// String nstr;
-// while (prev!=0) {
-// nstr = first + (plus>-1?str.substring(prev,plus):str.substring(prev));
-// type = new Pair<String, Pair<HttpCode<TRANS,?>,List<Pair<String,Object>>>>(nstr, cl);
-// types.add(type);
-// prev = plus+1;
-// plus = str.indexOf('+',prev);
-// }
-// return type;
-// }
}
@Override
if (accepted) {
switch(acc.acceptable.size()) {
case 0:
-// // TODO best Status Code?
-// resp.setStatus(HttpStatus.NOT_ACCEPTABLE_406);
break;
case 1:
rv = acc.acceptable.get(0);
}
}
if (bestT!=null) {
- // When it is a GET, the matched type is what is returned, so set ContentType
-// if (isGet)resp.setContentType(bestT.x); // set ContentType of Code<TRANS,?>
-// rv = bestT.y.x;
rv = bestT;
}
}
private Object[] parts;
public Version(String v) {
- String sparts[] = v.split("\\.");
+ String[] sparts = v.split("\\.");
parts = new Object[sparts.length];
System.arraycopy(sparts, 0, parts, 0, sparts.length);
if (parts.length>1) { // has at least a minor
public final ENV env;
private AAFConHttp aafCon;
- public final String app_name;
- public final String app_version;
- public final String ROOT_NS;
+ public final String appName;
+ public final String appVersion;
+ public final String rootNs;
public AbsService(final Access access, final ENV env) throws CadiException {
Define.set(access);
- ROOT_NS = Define.ROOT_NS();
+ rootNs = Define.ROOT_NS();
this.access = access;
this.env = env;
if(scomp.length==0) {
throw new CadiException(Config.AAF_LOCATOR_ENTRIES + " must be defined.");
} else {
- str = ROOT_NS + '.' + scomp[0];
+ str = rootNs + '.' + scomp[0];
}
- app_name = str;
+ appName = str;
str = access.getProperty(Config.AAF_LOCATOR_VERSION, null);
if(str==null) {
str = Defaults.AAF_VERSION;
env.setProperty(Config.AAF_LOCATOR_VERSION, str);
}
- app_version = access.getProperty(Config.AAF_DEPLOYED_VERSION, str);
+ appVersion = access.getProperty(Config.AAF_DEPLOYED_VERSION, str);
// Print Cipher Suites Available
if (access.willLog(Level.DEBUG)) {
public Rcli<?> clientAsUser(TaggedPrincipal p) throws CadiException {
return aafCon.client().forUser(
- new HTransferSS(p,app_name, aafCon.securityInfo()));
+ new HTransferSS(p, appName, aafCon.securityInfo()));
}
public<RET> RET clientAsUser(TaggedPrincipal p,Retryable<RET> retryable) throws APIException, LocatorException, CadiException {
- return aafCon.hman().best(new HTransferSS(p,app_name, aafCon.securityInfo()), retryable);
+ return aafCon.hman().best(new HTransferSS(p, appName, aafCon.securityInfo()), retryable);
}
protected static final String loadFromArgOrSystem(final Properties props, final String tag, final String args[], final String def) {
public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Trans> implements ServiceStarter {
private Registrar<ENV> registrar;
- private boolean do_register;
+ private boolean doRegister;
protected AbsService<ENV,TRANS> service;
protected String hostname;
protected final boolean secure;
}
// do_register - this is used for specialty Debug Situations. Developer can create an Instance for a remote system
// for Debugging purposes without fear that real clients will start to call your debug instance
- do_register = !"TRUE".equalsIgnoreCase(access().getProperty("aaf_locate_no_register",null));
+ doRegister = !"TRUE".equalsIgnoreCase(access().getProperty("aaf_locate_no_register",null));
hostname = access().getProperty(Config.HOSTNAME, null);
if (hostname==null) {
try {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
- absSS.access().printf(Level.INIT, "Shutting down %s:%s\n",absSS.service.app_name, absSS.service.app_version);
+ absSS.access().printf(Level.INIT, "Shutting down %s:%s\n",absSS.service.appName, absSS.service.appVersion);
absSS.shutdown();
app.cancel(true);
}
@SafeVarargs
public final synchronized void register(final Registrant<ENV> ... registrants) {
- if (do_register) {
+ if (doRegister) {
if (registrar==null) {
registrar = new Registrar<ENV>(env(),false);
}
File status = new File("/opt/app/aaf/status/");
boolean deleted = false;
if(status.exists()) {
- int lastdot = service.app_name.lastIndexOf("aaf.");
+ int lastdot = service.appName.lastIndexOf("aaf.");
String fname;
if(lastdot<0) {
- fname = service.app_name + '-' + hostname;
+ fname = service.appName + '-' + hostname;
} else {
- fname = service.app_name.substring(lastdot).replace('.', '-')
+ fname = service.appName.substring(lastdot).replace('.', '-')
+ '-' + hostname;
}
status = new File(status, fname);
@Override
public void _propertyAdjustment() {
-// System.setProperty("com.sun.management.jmxremote.port", "8081");
Properties props = access().getProperties();
Object httpproto = null;
// Critical - if no Security Protocols set, then set it. We'll just get messed up if not
// Want to use Client Certificates, if they exist.
sslContextFactory.setWantClientAuth(true);
- // Optional future checks.
- // sslContextFactory.setValidateCerts(true);
- // sslContextFactory.setValidatePeerCerts(true);
- // sslContextFactory.setEnableCRLDP(false);
- // sslContextFactory.setEnableOCSP(false);
String certAlias = access().getProperty(Config.CADI_ALIAS, null);
if (certAlias!=null) {
sslContextFactory.setCertAlias(certAlias);
}
service.setProtocol(protocol);
-
- // Setup JMX
- // TODO trying to figure out how to set up/log ports
-// MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
-// MBeanContainer mbContainer=new MBeanContainer(mbeanServer);
-// server.addEventListener(mbContainer);
-// server.addBean(mbContainer);
-
- // Add loggers MBean to server (will be picked up by MBeanContainer above)
-// server.addBean(Log.getLog());
-
conn.setHost(hostname);
conn.setPort(port);
conn.setIdleTimeout(IDLE_TIMEOUT);
}
}
try {
- String no_register = env().getProperty("aaf_no_register",null);
- if(no_register==null) {
+ String noRegister = env().getProperty("aaf_no_register",null);
+ if(noRegister==null) {
register(service.registrants(port));
} else {
- access().printf(Level.INIT,"'aaf_no_register' is set. %s will not be registered with Locator", service.app_name);
+ access().printf(Level.INIT,"'aaf_no_register' is set. %s will not be registered with Locator", service.appName);
}
- access().printf(Level.INIT, "Starting Jetty Service for %s, version %s, on %s://%s:%d", service.app_name,service.app_version,protocol,hostname,port);
+ access().printf(Level.INIT, "Starting Jetty Service for %s, version %s, on %s://%s:%d", service.appName,service.appVersion,protocol,hostname,port);
rserv.postStartup(hostname, port);
} catch (Exception e) {
- access().log(e,"Error registering " + service.app_name);
+ access().log(e,"Error registering " + service.appName);
String doExit = access().getProperty("cadi_exitOnFailure", "true");
if (doExit == "true") {
System.exit(1);
public Log4JLogIt(final String[] args, final String root) throws APIException {
String propsFile = getArgOrVM(AAF_LOG4J_PREFIX, args, "org.osaaf.aaf")+".log4j.props";
- String log_dir = getArgOrVM(Config.CADI_LOGDIR,args,"/opt/app/osaaf/logs");
- String etc_dir = getArgOrVM(Config.CADI_ETCDIR,args,"/opt/app/osaaf/etc");
- String log_level = getArgOrVM(Config.CADI_LOGLEVEL,args,"INFO");
- File logs = new File(log_dir);
+ String logDir = getArgOrVM(Config.CADI_LOGDIR,args,"/opt/app/osaaf/logs");
+ String etcDir = getArgOrVM(Config.CADI_ETCDIR,args,"/opt/app/osaaf/etc");
+ String logLevel = getArgOrVM(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(logDir);
if (!logs.isDirectory()) {
logs.delete();
}
}
if (System.getProperty("log4j.configuration")==null) {
- System.setProperty("log4j.configuration", etc_dir+'/'+propsFile);
+ System.setProperty("log4j.configuration", etcDir+'/'+propsFile);
}
- LogFileNamer lfn = new LogFileNamer(log_dir,root);
+ LogFileNamer lfn = new LogFileNamer(logDir,root);
try {
service=lfn.setAppender("service"); // when name is split, i.e. authz|service, the Appender is "authz", and "service"
audit=lfn.setAppender("audit"); // is part of the log-file name
linit = Logger.getLogger(init);
ltrace = Logger.getLogger(trace);
- lfn.configure(etc_dir,propsFile, log_level);
+ lfn.configure(etcDir,propsFile, logLevel);
} catch (IOException e) {
throw new APIException(e);
}
private final Pattern actionChars;
private final Pattern instChars;
private StringBuilder msgs;
-
+ public static final String PERM_TYPE = "Perm Type [";
+ public static final String IS_INVALID = "] is invalid.";
+ public static final String ROLE_STR = "Role [";
static {
nsKeywords = new ArrayList<>();
nsKeywords.add(".access");
public final Validator permType(String type) {
if (nob(type,NAME_CHARS)) {
- msg("Perm Type [" +type + "] is invalid.");
+ msg(PERM_TYPE +type + IS_INVALID);
}
return this;
}
} else {
if(!(type.startsWith(user) && type.endsWith(":id"))) {
if(nob(type,NAME_CHARS)) {
- msg("Perm Type [" + type + "] is invalid.");
+ msg(PERM_TYPE + type + IS_INVALID);
}
}
}
} else if (ns==null) {
msg("Perm NS is null");
} else if (nob(type,NAME_CHARS)) {
- msg("Perm Type [" + (ns+(type.length()==0?"":'.')) + type + "] is invalid.");
+ msg(PERM_TYPE + (ns+(type.length()==0?"":'.')) + type + IS_INVALID);
}
return this;
}
public final Validator permInstance(String instance) {
if(!"/".equals(instance) && nob(instance,instChars)) {
- msg("Perm Instance [" + instance + "] is invalid.");
+ msg("Perm Instance [" + instance + IS_INVALID);
}
return this;
}
public final Validator permAction(String action) {
// TODO check for correct Splits? Type|Instance|Action ?
if (nob(action, actionChars)) {
- msg("Perm Action [" + action + "] is invalid.");
+ msg("Perm Action [" + action + IS_INVALID);
}
return this;
}
if(!quit) {
if(role.startsWith(user) && role.endsWith(":user")) {
if(!(role.length() == user.length() + 5)) {
- msg("Role [" + role + "] is invalid.");
+ msg(ROLE_STR + role + IS_INVALID);
}
} else if (nob(role, NAME_CHARS)) {
- msg("Role [" + role + "] is invalid.");
+ msg(ROLE_STR + role + IS_INVALID);
}
}
return this;
public final Validator role(String role) {
if (nob(role, NAME_CHARS)) {
- msg("Role [" + role + "] is invalid.");
+ msg(ROLE_STR + role + IS_INVALID);
}
return this;
}
msg("NS is null");
return this;
} else if (nob(ns,NAME_CHARS)) {
- msg("NS [" + ns + "] is invalid.");
+ msg("NS [" + ns + IS_INVALID);
}
for (String s : nsKeywords) {
if (ns.endsWith(s)) {
HttpCode<?, ?> code = mock(HttpCode.class);
code.pathParam(null, null);
code.isAuthorized(null); //Testing httpcode, currently not working
- code.no_cache();
+ code.noCache();
code.toString();
typedCode.add(code , "");
env.put(sThemeWebPath,"theme");
}
+
slotHttpServletRequest = env.slot(HTTP_SERVLET_REQUEST);
- deployedVersion = app_version;
+ deployedVersion = appVersion;
+
// Certificate Manager
String aafUrlCm = env.getProperty(Config.AAF_URL_CM,Config.AAF_URL_CM_DEF);
} else {
// Transfer whether Page shouldn't be cached to local Final var.
+
final boolean noCache = page.noCache;
gui.route(gui.env, meth, page.url(),
}
@Override
- public boolean no_cache() {
+ public boolean noCache() {
+
return noCache;
}
}, "text/html","*/*");