本文整理汇总了Java中com.sun.net.httpserver.HttpPrincipal类的典型用法代码示例。如果您正苦于以下问题:Java HttpPrincipal类的具体用法?Java HttpPrincipal怎么用?Java HttpPrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpPrincipal类属于com.sun.net.httpserver包,在下文中一共展示了HttpPrincipal类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public void handle (HttpExchange t)
throws IOException
{
InputStream is = t.getRequestBody();
Headers map = t.getRequestHeaders();
Headers rmap = t.getResponseHeaders();
while (is.read() != -1);
is.close();
t.sendResponseHeaders(200, -1);
HttpPrincipal p = t.getPrincipal();
if (!p.getUsername().equals("fred")) {
error = true;
}
if (!p.getRealm().equals("[email protected]")) {
error = true;
}
t.close();
}
示例2: handle
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
public void handle (HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
while (is.read () != -1) ;
is.close();
t.sendResponseHeaders(200, -1);
HttpPrincipal p = t.getPrincipal();
if (!p.getUsername().equals(USERNAME)) {
error = true;
}
if (!p.getRealm().equals(REALM)) {
error = true;
}
t.close();
}
示例3: userName
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
public static String userName(HttpExchange t) {
HttpPrincipal p = t.getPrincipal();
if (p == null) {
return "";
}
return p.getUsername();
}
示例4: testGetPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Test
public void testGetPrincipal() {
// setup
HttpPrincipal expectedResult = mock(HttpPrincipal.class);
when(this.httpExchange.getPrincipal()).thenReturn(expectedResult);
// act
HttpPrincipal result = this.httpExchangeImpl.getPrincipal();
// assert
assertEquals(expectedResult, result);
}
示例5: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal()
{
return _principal;
}
示例6: setPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
public void setPrincipal(HttpPrincipal principal)
{
this._principal = principal;
}
示例7: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal() {
return null;
}
示例8: before
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
protected void before(HttpExchange exchange) {
((MockHttpExchange) exchange)
.setPrincipal(new HttpPrincipal(PRINCIPAL_NAME, "my realm"));
}
示例9: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal() {
throw new RuntimeException("Glowroot should not call this directly as it may fail");
}
示例10: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal() {
return principal;
}
示例11: setPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
void setPrincipal(HttpPrincipal principal) {
this.principal = principal;
}
示例12: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal() {
return this.httpExchange.getPrincipal();
}
示例13: getPrincipal
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
@Override
public HttpPrincipal getPrincipal() {
// TODO Auto-generated method stub
return null;
}
示例14: validateUser
import com.sun.net.httpserver.HttpPrincipal; //导入依赖的package包/类
private HttpPrincipal validateUser(HttpExchange httpExchange, Map<String, String> challengeParameters) {
String realm = challengeParameters.get("realm");
String username = challengeParameters.get("username");
if (realm == null || realm.length() == 0 || username == null || username.length() == 0) {
return null;
}
String password = passwords.getProperty(username);
if (password == null) {
return null;
}
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(username.getBytes());
md5.update(COL);
md5.update(realm.getBytes());
md5.update(COL);
md5.update(password.getBytes());
byte[] ha1 = Utils.toHexBytes(md5.digest());
md5.update(httpExchange.getRequestMethod().getBytes());
md5.update(COL);
md5.update(challengeParameters.get("uri").getBytes());
byte[] ha2 = Utils.toHexBytes(md5.digest());
md5.update(ha1);
md5.update(COL);
md5.update(challengeParameters.get("nonce").getBytes());
md5.update(COL);
md5.update(ha2);
byte[] expectedResponse = Utils.toHexBytes(md5.digest());
byte[] actualResponse = challengeParameters.get("response").getBytes();
if (MessageDigest.isEqual(expectedResponse, actualResponse)) {
return new HttpPrincipal(username, realm);
}
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No MD5? Should not be possible", e);
}
return null;
}
开发者ID:NitorCreations,项目名称:javaone-shanghai-2013-javafx-presentation,代码行数:47,代码来源:DigestAuthenticator.java