org.beangle.security.cas.CasConfig Maven / Gradle / Ivy
/*
* Beangle, Agile Java/Scala Development Scaffold and Toolkit
*
* Copyright (c) 2005-2013, Beangle Software.
*
* Beangle is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Beangle is distributed in the hope that it will be useful.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Beangle. If not, see .
*/
package org.beangle.security.cas;
import javax.servlet.http.HttpServletRequest;
import org.beangle.commons.bean.Initializing;
import org.beangle.commons.lang.Assert;
/**
* Stores properties related to this CAS service.
*
* Each web application capable of processing CAS tickets is known as a service. This class stores
* the properties that are relevant to the local CAS service, being the application that is being
* secured by Beangle Security.
*
* @author chaostone
* @version $Id: ServiceProperties.java $
*/
public class CasConfig implements Initializing {
private String casServer;
private boolean renew = false;
private boolean encode = true;
private String artifactName = "ticket";
private String loginUri = "/login";
private String validateUri = "/serviceValidate";
private String checkAliveUri = "/checkAlive";
public CasConfig() {
super();
}
public CasConfig(String casServer) {
super();
this.casServer = casServer;
}
public void init() throws Exception {
Assert.notEmpty(this.casServer, "cas server must be specified.");
Assert.isTrue(!this.casServer.endsWith("/"), "cas server should not end with /");
Assert.notEmpty(this.loginUri, "loginUri must be specified. like /login");
Assert.notEmpty(this.artifactName, "artifact name must be specified.etc. ticket");
}
public String getCasServer() {
return casServer;
}
public void setCasServer(String casServer) {
if (casServer.endsWith("/")) this.casServer = casServer.substring(0, casServer.length() - 1);
else this.casServer = casServer;
}
public static String getLocalServer(HttpServletRequest request) {
StringBuilder sb = new StringBuilder();
String scheme = request.getScheme();
int port = request.getServerPort();
String serverName = request.getServerName();
boolean includePort = true;
if (null != scheme) {
sb.append(scheme).append("://");
includePort = (port != (scheme.equals("http") ? 80 : 443));
}
if (null != serverName) {
sb.append(serverName);
if (includePort && port > 0) {
sb.append(':').append(port);
}
}
return sb.toString();
}
/**
* The enterprise-wide CAS login URL. Usually something like
* https://www.mycompany.com/cas/login
.
*
* @return the enterprise-wide CAS login URL
*/
public String getLoginUrl() {
return casServer + loginUri;
}
/**
* Indicates whether the renew
parameter should be sent to the
* CAS login URL and CAS validation URL.
*
* If true
, it will force CAS to authenticate the user again (even if the user has
* previously authenticated). During ticket validation it will require the ticket was generated as
* a consequence of an explicit login. High security applications would probably set this to
* true
. Defaults to false
, providing automated single sign on.
*
* @return whether to send the renew
parameter to CAS
*/
public boolean isRenew() {
return renew;
}
public void setRenew(boolean renew) {
this.renew = renew;
}
public boolean isEncode() {
return encode;
}
public void setEncode(boolean encode) {
this.encode = encode;
}
public String getLoginUri() {
return loginUri;
}
public void setLoginUri(String loginUri) {
this.loginUri = loginUri;
}
public String getArtifactName() {
return artifactName;
}
public void setArtifactName(String artifactName) {
this.artifactName = artifactName;
}
public String getValidateUri() {
return validateUri;
}
public void setValidateUri(String validateUri) {
this.validateUri = validateUri;
}
public String getCheckAliveUri() {
return checkAliveUri;
}
public void setCheckAliveUri(String checkAliveUri) {
this.checkAliveUri = checkAliveUri;
}
}