| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.ui.cas; |
| 17 |
|
|
| 18 |
|
import java.io.IOException; |
| 19 |
|
import java.net.URLEncoder; |
| 20 |
|
|
| 21 |
|
import javax.servlet.ServletException; |
| 22 |
|
import javax.servlet.ServletRequest; |
| 23 |
|
import javax.servlet.ServletResponse; |
| 24 |
|
import javax.servlet.http.HttpServletRequest; |
| 25 |
|
import javax.servlet.http.HttpServletResponse; |
| 26 |
|
|
| 27 |
|
import org.acegisecurity.AuthenticationException; |
| 28 |
|
import org.acegisecurity.ui.AuthenticationEntryPoint; |
| 29 |
|
import org.springframework.beans.factory.InitializingBean; |
| 30 |
|
import org.springframework.util.Assert; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
5 |
public class CasProcessingFilterEntryPoint implements AuthenticationEntryPoint, InitializingBean { |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
private ServiceProperties serviceProperties; |
| 48 |
|
private String loginUrl; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
public void afterPropertiesSet() throws Exception { |
| 53 |
4 |
Assert.hasLength(this.loginUrl, "loginUrl must be specified"); |
| 54 |
3 |
Assert.notNull(this.serviceProperties, "serviceProperties must be specified"); |
| 55 |
2 |
} |
| 56 |
|
|
| 57 |
|
public void commence(final ServletRequest servletRequest, final ServletResponse servletResponse, |
| 58 |
|
final AuthenticationException authenticationException) |
| 59 |
|
throws IOException, ServletException { |
| 60 |
2 |
final HttpServletRequest request = (HttpServletRequest) servletRequest; |
| 61 |
2 |
final HttpServletResponse response = (HttpServletResponse) servletResponse; |
| 62 |
2 |
final String urlEncodedService = response.encodeURL(this.serviceProperties.getService()); |
| 63 |
|
|
| 64 |
2 |
final StringBuffer buffer = new StringBuffer(255); |
| 65 |
|
|
| 66 |
2 |
synchronized (buffer) { |
| 67 |
2 |
buffer.append(this.loginUrl); |
| 68 |
2 |
buffer.append("?service="); |
| 69 |
2 |
buffer.append(URLEncoder.encode(urlEncodedService, "UTF-8")); |
| 70 |
2 |
buffer.append(this.serviceProperties.isSendRenew() ? "&renew=true" : ""); |
| 71 |
2 |
} |
| 72 |
|
|
| 73 |
2 |
response.sendRedirect(buffer.toString()); |
| 74 |
2 |
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
public String getLoginUrl() { |
| 83 |
1 |
return this.loginUrl; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
public ServiceProperties getServiceProperties() { |
| 87 |
1 |
return this.serviceProperties; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
public void setLoginUrl(final String loginUrl) { |
| 91 |
4 |
this.loginUrl = loginUrl; |
| 92 |
4 |
} |
| 93 |
|
|
| 94 |
|
public void setServiceProperties(final ServiceProperties serviceProperties) { |
| 95 |
4 |
this.serviceProperties = serviceProperties; |
| 96 |
4 |
} |
| 97 |
|
} |