/**
* The orginal class is "jcifs.http.NtlmHttpFilter",
* SPNEGO protocol support is added to this class by Wayne Lou
*/
package com.tidalsoft.webconsole.sso.http;
import java.io.*;
import java.net.*;
import java.security.*;
import java.util.*;
import javax.security.auth.login.*;
import jcifs.*;
import jcifs.ntlmssp.*;
import jcifs.util.*;
import com.tidalsoft.webconsole.sso.*;
/**
*Wraps an <code>HttpURLConnection</code> to provide Kerberos delegate and NTLM
* authentication services.
*
* Authentication for HTTP Connections</a>.
*/
public class SpnegoHttpURLConnection extends HttpURLConnection {
private static final int MAX_REDIRECTS = Integer.parseInt(System
.getProperty("http.maxRedirects", "20"));
private static final int LM_COMPATIBILITY = Config.getInt(
"jcifs.smb.lmCompatibility", 0);
private HttpURLConnection connection;
private Map requestProperties;
private Map headerFields;
private ByteArrayOutputStream cachedOutput;
private String authProperty;
private String authMethod;
private boolean handshakeComplete;
/**
* User credential, get it from thread local, added by wayne
*/
private UserCredential userCred;
public UserCredential getUserCred() {
return userCred;
}
public void setUserCred(UserCredential userCred) {
this.userCred = userCred;
}
public SpnegoHttpURLConnection(HttpURLConnection connection) {
super(connection.getURL());
this.connection = connection;
requestProperties = new HashMap();
}
public void connect() throws IOException {
if (connected)
return;
connection.connect();
connected = true;
}
private void handshake() throws IOException {
if (handshakeComplete)
return;
doHandshake();
handshakeComplete = true;
}
public URL getURL() {
return connection.getURL();
}
public int getContentLength() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getContentLength();
}
public String getContentType() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getContentType();
}
public String getContentEncoding() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getContentEncoding();
}
public long getExpiration() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getExpiration();
}
public long getDate() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getDate();
}
public long getLastModified() {
try {
handshake();
} catch (IOException ex) {
}
return connection.getLastModified();
}
public String getHeaderField(String header) {
try {
handshake();
} catch (IOException ex) {
}
return connection.getHeaderField(header);
}
private Map getHeaderFields0() {
if (headerFields != null)
return headerFields;
Map map = new HashMap();
String key = connection.getHeaderFieldKey(0);
String value = connection.getHeaderField(0);
for (int i = 1; key != null || value != null; i++) {
List values = (List) map.get(key);
if (values == null) {
values = new ArrayList();
map.put(key, values);
}
values.add(value);
key = connection.getHeaderFieldKey(i);
value = connection.getHeaderField(i);
}
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
entry.setValue(Collections
.unmodifiableList((List) entry.getValue()));
}
return (headerFields = Collections.unmodifiableMap(map));
}
public Map getHeaderFields() {
if (headerFields != null)
return headerFields;
try {
handshake();
} catch (IOException ex) {
}
return getHeaderFields0();
}
public int getHeaderFieldInt(String header, int def) {
try {
handshake();
} catch (IOException ex) {
}
return connection.getHeaderFieldInt(header, def);
}
public long getHeaderFieldDate(String header, long def) {
try {
handshake();
} catch (IOException ex) {
}
return connection.getHeaderFieldDate(header, def);
}
public String getHeaderFieldKey(int index) {
try {
handshake();
} catch (IOException ex) {
}
return connection.getHeaderFieldKey(index);
}
public String getHeaderField(int index) {
try {
handshake();
} catch (IOException ex) {
}
return connection.getHeaderField(index);
}
public Object getContent() throws IOException {
try {
handshake();
} catch (IOException ex) {
}
return connection.getContent();
}
public Object getContent(Class[] classes) throws IOException {
try {
handshake();
} catch (IOException ex) {
}
return connection.getContent(classes);
}
public Permission getPermission() throws IOException {
return connection.getPermission();
}
public InputStream getInputStream() throws IOException {
try {
handshake();
} catch (IOException ex) {
}
return connection.getInputStream();
}
public OutputStream getOutputStream() throws IOException {
try {
connect();
} catch (IOException ex) {
}
OutputStream output = connection.getOutputStream();
cachedOutput = new ByteArrayOutputStream();
return new CacheStream(output, cachedOutput);
}
public String toString() {
return connection.toString();
}
public void setDoInput(boolean doInput) {
connection.setDoInput(doInput);
this.doInput = doInput;
}
public boolean getDoInput() {
return connection.getDoInput();
}
public void setDoOutput(boolean doOutput) {
connection.setDoOutput(doOutput);
this.doOutput = doOutput;
}
public boolean getDoOutput() {
return connection.getDoOutput();
}
public void setAllowUserInteraction(boolean allowUserInteraction) {
connection.setAllowUserInteraction(allowUserInteraction);
this.allowUserInteraction = allowUserInteraction;
}
public boolean getAllowUserInteraction() {
return connection.getAllowUserInteraction();
}
public void setUseCaches(boolean useCaches) {
connection.setUseCaches(useCaches);
this.useCaches = useCaches;
}
public boolean getUseCaches() {
return connection.getUseCaches();
}
public void setIfModifiedSince(long ifModifiedSince) {
connection.setIfModifiedSince(ifModifiedSince);
this.ifModifiedSince = ifModifiedSince;
}
public long getIfModifiedSince() {
return connection.getIfModifiedSince();
}
public boolean getDefaultUseCaches() {
return connection.getDefaultUseCaches();
}
public void setDefaultUseCaches(boolean defaultUseCaches) {
connection.setDefaultUseCaches(defaultUseCaches);
}
public void setRequestProperty(String key, String value) {
if (key == null)
throw new NullPointerException();
List values = new ArrayList();
values.add(value);
boolean found = false;
Iterator entries = requestProperties.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
if (key.equalsIgnoreCase((String) entry.getKey())) {
entry.setValue(values);
found = true;
break;
}
}
if (!found)
requestProperties.put(key, values);
connection.setRequestProperty(key, value);
}
public void addRequestProperty(String key, String value) {
if (key == null)
throw new NullPointerException();
List values = null;
Iterator entries = requestProperties.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
if (key.equalsIgnoreCase((String) entry.getKey())) {
values = (List) entry.getValue();
values.add(value);
break;
}
}
if (values == null) {
values = new ArrayList();
values.add(value);
requestProperties.put(key, values);
}
// 1.3-compatible.
StringBuffer buffer = new StringBuffer();
没有合适的资源?快使用搜索试试~ 我知道了~
JAAS.rar_jaas
共29个文件
java:17个
class:4个
classpath:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 74 浏览量
2022-09-24
04:10:31
上传
评论
收藏 94KB RAR 举报
温馨提示
JAAS 支持单点注册 可以参考参考 很不错的解决方案
资源推荐
资源详情
资源评论
收起资源包目录
JAAS.rar (29个子文件)
JAAS
bin
commons-logging-1.1.1.jar 59KB
src
com
tidalsoft
webconsole
sso
UserAuthResult.java 2KB
filter
SpnegoFilter.java 4KB
Krb5LoginAuthAction.java 2KB
SpnegoHandler.java 5KB
http
Handler.java 5KB
SpnegoHttpURLConnection.java 17KB
Krb5DeleAuthAction.java 2KB
WebconsoleJaas.java 2KB
UserCredentialFactory.java 792B
SSOConf.java 2KB
UserCredential.java 2KB
.project 379B
.classpath 903B
sample
bin
sample
MyCallbackHandler.class 3KB
SampleAcn.class 2KB
module
SampleLoginModule.class 5KB
principal
SamplePrincipal.class 1KB
SampleAcn.java 7KB
.settings
org.eclipse.jdt.core.prefs 629B
src
sample
SampleAcn.java 7KB
module
SampleLoginModule.java 11KB
principal
SamplePrincipal.java 5KB
module
SampleLoginModule.java 11KB
.project 382B
sample_jaas.config 132B
sampleacn.policy 365B
.classpath 301B
principal
SamplePrincipal.java 5KB
共 29 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 73
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功