Java Code Examples for com.sun.net.httpserver.HttpPrincipal

The following are top voted examples for showing how to use com.sun.net.httpserver.HttpPrincipal. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 2
Project: openjdk-jdk10   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 3
Project: openjdk9   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 4
Project: jdk8u_jdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 5
Project: lookaside_java-1.8.0-openjdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 6
Project: infobip-open-jdk-8   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 7
Project: jdk8u-dev-jdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 8
Project: jdk7-jdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 9
Project: openjdk-source-code-learn   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 10
Project: OLD-OpenJDK8   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 11
Project: JAVA_UNIT   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 12
Project: openjdk-jdk7u-jdk   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 13
Project: openjdk-icedtea7   File: Deadlock.java   View source code 6 votes vote down vote up
@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();
}
 
Example 14
Project: jdk8u-jdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 15
Project: openjdk-jdk10   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 16
Project: openjdk9   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 17
Project: DigitalMediaServer   File: RemoteUtil.java   View source code 5 votes vote down vote up
public static String userName(HttpExchange t) {
	HttpPrincipal p = t.getPrincipal();
	if (p == null) {
		return "";
	}
	return p.getUsername();
}
 
Example 18
Project: jdk8u_jdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 19
Project: lookaside_java-1.8.0-openjdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 20
Project: infobip-open-jdk-8   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 21
Project: jdk8u-dev-jdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 22
Project: jdk7-jdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 23
Project: openjdk-source-code-learn   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 24
Project: OLD-OpenJDK8   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 25
Project: JAVA_UNIT   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 26
Project: openjdk-jdk7u-jdk   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 27
Project: openjdk-icedtea7   File: BasicLongCredentials.java   View source code 5 votes vote down vote up
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();
}
 
Example 28
Project: pi   File: HttpExchangeImplTest.java   View source code 5 votes vote down vote up
@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);
}
 
Example 29
Project: openbravo-pos   File: JettyHttpExchange.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal()
{
	return _principal;
}
 
Example 30
Project: openbravo-pos   File: JettyHttpExchange.java   View source code 4 votes vote down vote up
public void setPrincipal(HttpPrincipal principal)
{
	this._principal = principal;
}
 
Example 31
Project: blink-java   File: HttpExchangeStub.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal() {
    return null;
}
 
Example 32
Project: glowroot   File: UserIT.java   View source code 4 votes vote down vote up
@Override
protected void before(HttpExchange exchange) {
    ((MockHttpExchange) exchange)
            .setPrincipal(new HttpPrincipal(PRINCIPAL_NAME, "my realm"));
}
 
Example 33
Project: glowroot   File: UserIT.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal() {
    throw new RuntimeException("Glowroot should not call this directly as it may fail");
}
 
Example 34
Project: glowroot   File: MockHttpExchange.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal() {
    return principal;
}
 
Example 35
Project: glowroot   File: MockHttpExchange.java   View source code 4 votes vote down vote up
void setPrincipal(HttpPrincipal principal) {
    this.principal = principal;
}
 
Example 36
Project: OpenbravoPOS   File: JettyHttpExchange.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal()
{
	return _principal;
}
 
Example 37
Project: OpenbravoPOS   File: JettyHttpExchange.java   View source code 4 votes vote down vote up
public void setPrincipal(HttpPrincipal principal)
{
	this._principal = principal;
}
 
Example 38
Project: pi   File: HttpExchangeImpl.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal() {
    return this.httpExchange.getPrincipal();
}
 
Example 39
Project: pi   File: RestQueryFilterTest.java   View source code 4 votes vote down vote up
@Override
public HttpPrincipal getPrincipal() {
    // TODO Auto-generated method stub
    return null;
}
 
Example 40
Project: javaone-shanghai-2013-javafx-presentation   File: DigestAuthenticator.java   View source code 4 votes vote down vote up
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;
}