Re: Performance tuning

Splash Forums Rewrite Users Performance tuning Re: Performance tuning

#22950

pavel.arnost
Participant

Here they are:

TrivialProvider:

public class TrivialHttpConfigurationProvider extends HttpConfigurationProvider implements NonEnriching {

@Override
public Configuration getConfiguration(ServletContext context) {
HttpOperation userCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isUserLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(userLoginUrl(rewrite));
}
}
}
};

HttpOperation userAndAcknowledgesCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isUserLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(userLoginUrl(rewrite));
} else {
if (!Auth.isAllAcknowledged(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAckUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(acknowledgementUrl(rewrite));
}
}
}
}
};

HttpOperation staffCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isStaffLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("staffPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(adminLoginUrl(rewrite));
}
}
}
};

return ConfigurationBuilder.begin()
.addRule(Join.path("/faq").to("/faq.html"))

/* fallback, default deny */
.defineRule()
.when(Direction.isInbound()
.and(DispatchType.isRequest())
.andNot(Path.matches("{1}javax.faces.resource{2}").where("1").matches(".*").where("2").matches(".*"))
.andNot(Path.matches("/css/{1}").where("1").matches(".*"))
.andNot(Path.matches("/media/{1}").where("1").matches(".*"))
.andNot(Path.matches("/avatar/{1}").where("1").matches(".*"))
.andNot(Path.matches("/avatar/proposed-change/{1}").where("1").matches(".*")))
.perform(SendStatus.SendError.code(403));
}

@Override
public int priority() {
return 10;
}

private String preAuthUrl(HttpInboundServletRewrite rewrite) {
String preAuthUrl = rewrite.getRequest().getRequestURL().toString();
String queryString = rewrite.getRequestQueryString();

if (queryString != null && !queryString.isEmpty()) {
preAuthUrl = preAuthUrl + "?" + queryString;
}

return preAuthUrl;
}

private String userLoginUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/login.html";
}

private String adminLoginUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/admin/login.html";
}

private String acknowledgementUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/user/acknowledgement.html";
}
}

MyProvider:

public class MyHttpConfigurationProvider extends HttpConfigurationProvider implements NonEnriching {

@Override
public Configuration getConfiguration(ServletContext context) {
HttpOperation userCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isUserLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(userLoginUrl(rewrite));
}
}
}
};

HttpOperation userAndAcknowledgesCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isUserLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(userLoginUrl(rewrite));
} else {
if (!Auth.isAllAcknowledged(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("userPreAckUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(acknowledgementUrl(rewrite));
}
}
}
}
};

HttpOperation staffCheck = new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context) {
if (event instanceof HttpInboundServletRewrite) {
HttpInboundServletRewrite rewrite = (HttpInboundServletRewrite) event;

if (!Auth.isStaffLoggedIn(event.getRequest())) {
rewrite.getRequest().getSession().setAttribute("staffPreAuthUrl", preAuthUrl(rewrite));
rewrite.redirectTemporary(adminLoginUrl(rewrite));
}
}
}
};

return ConfigurationBuilder.begin()
/* home, login and registration */
.addRule(Join.path("/").to("/index.html"))
.addRule(Join.path("/prihlaseni").to("/login.html"))
.addRule(Join.path("/prihlaseni/facebook").to("/user/facebooklogin.html"))
.addRule(Join.path("/zapomenute-heslo").to("/user/lostpassword.html"))
.addRule(Join.path("/obnova-hesla/{token}").to("/user/resetpassword.html"))
.addRule(Join.path("/registrace/pracovnik/facebook").to("/user/registration/facebookworker.html"))
.addRule(Join.path("/registrace/zadavatel/facebook").to("/user/registration/facebooksubmitter.html"))
.addRule(Join.path("/registrace/facebook/dokonceni").to("/user/registration/facebookfinish.html"))
.addRule(Join.path("/registrace/pracovnik").to("/user/registration/worker.html"))
.addRule(Join.path("/registrace/zadavatel").to("/user/registration/submitter.html"))
.addRule(Join.path("/kontrola-psc/{postCode}").to("/user/postcode/check.html"))
.addRule(Join.path("/mapa").to("/map.html"))
.addRule(Join.path("/odeslat-dotaz-provozovateli").to("/feedback.html"))
.addRule(Join.path("/profil/{nickname}").to("/user/profile.html"))
.addRule(Join.path("/faq").to("/faq.html"))

/* dashboard and profile */
.addRule(Join.path("/udeleni-souhlasu").to("/user/acknowledgement.html").perform(userCheck))
.addRule(Join.path("/prehled").to("/user/dashboard.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/zmena-hesla").to("/user/passwordchange.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/zadost-o-provereni").to("/user/applyforverification.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/muj-profil").to("/user/myprofile.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/uprava-profilu").to("/user/myprofileedit.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/muj-ucet").to("/user/myaccount.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/moje-oblasti-a-kategorie").to("/user/myregionsandcategories.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/nastaveni-notifikaci").to("/user/notificationpreferences.html").perform(userAndAcknowledgesCheck))

/* messages */
.addRule(Join.path("/moje-zpravy").to("/user/message/list.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/zprava/link").to("/user/message/link.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/zprava/{id}").to("/user/message/detail.html").perform(userAndAcknowledgesCheck))

/* admin */
.addRule(Join.path("/admin/").to("/admin/index.html").perform(staffCheck))
.addRule(Join.path("/admin/prihlaseni").to("/admin/login.html"))
.addRule(Join.path("/admin/kategorie").to("/admin/categories.html").perform(staffCheck))
.addRule(Join.path("/admin/pozadavaky-ke-schvaleni").to("/admin/approvalrequests.html").perform(staffCheck))
.addRule(Join.path("/admin/uzivatele").to("/admin/user/list.html").perform(staffCheck))
.addRule(Join.path("/admin/zadosti-o-provereni").to("/admin/verifications.html").perform(staffCheck))
.addRule(Join.path("/admin/ukoly").to("/admin/task/list.html").perform(staffCheck))
.addRule(Join.path("/admin/ukol/{id}").to("/admin/task/detail.html").where("id").matches(".*").perform(staffCheck))
.addRule(Join.path("/admin/ukol").to("/admin/task/detail.html").perform(staffCheck))
.addRule(Join.path("/admin/uzivatel/{id}").to("/admin/user/detail.html").where("id").matches(".*").perform(staffCheck))
.addRule(Join.path("/admin/uzivatel").to("/admin/user/detail.html").perform(staffCheck))
.addRule(Join.path("/admin/bankovniucty").to("/admin/bankaccounts.html").perform(staffCheck))
.addRule(Join.path("/admin/bankovniucet").to("/admin/bankaccount.html").perform(staffCheck))
.addRule(Join.path("/admin/bankovnitransakce").to("/admin/banktransactions.html").perform(staffCheck))
.addRule(Join.path("/admin/platby").to("/admin/payments.html").perform(staffCheck))
.addRule(Join.path("/admin/konfigurace").to("/admin/configuration/detail.html").perform(staffCheck))
.addRule(Join.path("/admin/konfigurace/upravit").to("/admin/configuration/edit.html").perform(staffCheck))
.addRule(Join.path("/admin/urovne-uzivatelu").to("/admin/userlevel/list.html").perform(staffCheck))
.addRule(Join.path("/admin/nastroje").to("/admin/utils/index.html").perform(staffCheck))

/* admin: notifications */
.addRule(Join.path("/admin/notifikace").to("/admin/notification/list.html").perform(staffCheck))
.addRule(Join.path("/admin/notifikace/upravit").to("/admin/notification/edit.html").perform(staffCheck))
.addRule(Join.path("/admin/notifikace/{id}").to("/admin/notification/detail.html").perform(staffCheck))

/* admin: acknowledgements */
.addRule(Join.path("/admin/souhlasy").to("/admin/acknowledgement/list.html").perform(staffCheck))
.addRule(Join.path("/admin/souhlasy/upravit").to("/admin/acknowledgement/edit.html").perform(staffCheck))
.addRule(Join.path("/admin/souhlasy/pridat").to("/admin/acknowledgement/add.html").perform(staffCheck))

/* admin: greetings */
.addRule(Join.path("/admin/pozdravy").to("/admin/greeting/list.html").perform(staffCheck))
.addRule(Join.path("/admin/pozdrav/upravit").to("/admin/greeting/edit.html").perform(staffCheck))
.addRule(Join.path("/admin/pozdrav/pridat").to("/admin/greeting/add.html").perform(staffCheck))

/* admin: staff */
.addRule(Join.path("/admin/sprava-personalu").to("/admin/staff/list.html").perform(staffCheck))
.addRule(Join.path("/admin/personal/pridat").to("/admin/staff/add.html").perform(staffCheck))
.addRule(Join.path("/admin/personal/upravit").to("/admin/staff/edit.html").where("id").matches(".*").perform(staffCheck))
.addRule(Join.path("/admin/personal/zmena-hesla/{id}").to("/admin/staff/passwordchange.html").where("id").matches(".*").perform(staffCheck))
.addRule(Join.path("/admin/personal/{id}").to("/admin/staff/detail.html").where("id").matches(".*").perform(staffCheck))

/* admin: coupons */
.addRule(Join.path("/admin/seznam-kuponu").to("/admin/coupon/list.html").perform(staffCheck))
.addRule(Join.path("/admin/pridani-kuponu").to("/admin/coupon/add.html").perform(staffCheck))
.addRule(Join.path("/admin/uprava-kuponu/{id}").to("/admin/coupon/edit.html").perform(staffCheck))

/* task */
.addRule(Join.path("/moje-ukoly").to("/task/mytasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/uhrazeni-poplatku/{id}").to("/user/payment.html").where("id").matches(".*").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/payu/ok").to("/user/payment/ok.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/payu/error").to("/user/payment/error.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/payu/update").to("/user/payment/update.html"))
.addRule(Join.path("/hotove-ukoly").to("/task/finishedtasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/aktivni-ukoly").to("/task/activetasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/nevyhrane-ukoly").to("/task/notwontasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/ukoly-cekajici-na-schvaleni").to("/task/waitingtasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/ukoly-cekajici-na-uhrazeni").to("/task/waitingforpaymenttasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/ukoly-cekajici-na-splneni").to("/task/assignedtasks.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/upravit-ukol/{id}").to("/task/edit.html").where("id").matches(".*").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/upravit-ukol").to("/task/edit.html").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/podat-ukol").to("/task/post.html").where("id").perform(userAndAcknowledgesCheck))
.addRule(Join.path("/{urlName}").to("/task/detail.html")
.where("urlName").matches("\d+-[0-9a-z-]+"))
.addRule(Join.path("/{regionName}/{categoryName}/hledani/{searchTerm}").to("/task/search.html")
.where("regionName").matches("[a-z-]+")
.where("categoryName").matches("[a-z-]+")
.where("searchTerm").matches(".*"))
.addRule(Join.path("/{regionName}/{categoryName}").to("/task/list.html")
.where("regionName").matches("[a-z-]+")
.where("categoryName").matches("[a-z-]+"))

/* fallback, default deny */
.defineRule()
.when(Direction.isInbound()
.and(DispatchType.isRequest())
.andNot(Path.matches("{1}javax.faces.resource{2}").where("1").matches(".*").where("2").matches(".*"))
.andNot(Path.matches("/css/{1}").where("1").matches(".*"))
.andNot(Path.matches("/media/{1}").where("1").matches(".*"))
.andNot(Path.matches("/avatar/{1}").where("1").matches(".*"))
.andNot(Path.matches("/avatar/proposed-change/{1}").where("1").matches(".*")))
.perform(SendStatus.SendError.code(403));
}

@Override
public int priority() {
return 10;
}

private String preAuthUrl(HttpInboundServletRewrite rewrite) {
String preAuthUrl = rewrite.getRequest().getRequestURL().toString();
String queryString = rewrite.getRequestQueryString();

if (queryString != null && !queryString.isEmpty()) {
preAuthUrl = preAuthUrl + "?" + queryString;
}

return preAuthUrl;
}

private String userLoginUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/login.html";
}

private String adminLoginUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/admin/login.html";
}

private String acknowledgementUrl(HttpInboundServletRewrite rewrite) {
String contextPath = rewrite.getRequest().getContextPath();

return contextPath + "/user/acknowledgement.html";
}
}