Java Code Examples for javax.servlet.http.HttpServletRequest#getAuthType()

The following examples show how to use javax.servlet.http.HttpServletRequest#getAuthType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthenticationMessageServlet.java    From quarkus-http with Apache License 2.0 9 votes vote down vote up
private void checkExpectedMechanism(HttpServletRequest req) {
    String expectedMechanism = req.getHeader("ExpectedMechanism");
    if (expectedMechanism == null) {
        throw new IllegalStateException("No ExpectedMechanism received.");
    }
    if (expectedMechanism.equals("None")) {
        if (req.getAuthType() != null) {
            throw new IllegalStateException("Authentication occurred when not expected.");
        }
    } else if (expectedMechanism.equals("BASIC")) {
        if (req.getAuthType() != HttpServletRequest.BASIC_AUTH) {
            throw new IllegalStateException("Expected mechanism type not matched.");
        }
    } else {
        throw new IllegalStateException("ExpectedMechanism not recognised.");
    }
}
 
Example 2
Source File: RequestVerifier.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
private HttpRequestCopy(HttpServletRequest request) {
    this.authType = request.getAuthType();
    this.cookies = request.getCookies();
    this.pathInfo = request.getPathInfo();
    this.contextPath = request.getContextPath();
    this.queryString = request.getQueryString();
    this.requestURI = request.getRequestURI();
    this.requestURL = request.getRequestURL();

    for (final Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements(); ) {
        final String headerName = e.nextElement();

        final List<String> headers = new LinkedList<>();
        for (final Enumeration<String> e2 = request.getHeaders(headerName); e2.hasMoreElements(); ) {
            headers.add(e2.nextElement());
        }
        headersData.put(headerName.toLowerCase(), headers);
    }
}
 
Example 3
Source File: HttpRequestInfo.java    From odo with Apache License 2.0 6 votes vote down vote up
public HttpRequestInfo(HttpServletRequest request) {
    this.authType = request.getAuthType();
    this.contextPath = request.getContextPath();
    populateHeaders(request);
    this.method = request.getMethod();
    this.pathInfo = request.getPathInfo();
    this.queryString = request.getQueryString();
    this.requestURI = request.getRequestURI();
    this.servletPath = request.getServletPath();
    this.contentType = request.getContentType();
    this.characterEncoding = request.getCharacterEncoding();
    this.contentLength = request.getContentLength();
    this.localName = request.getLocalName();
    this.localPort = request.getLocalPort();
    populateParameters(request);
    this.protocol = request.getProtocol();
    this.remoteAddr = request.getRemoteAddr();
    this.remoteHost = request.getRemoteHost();
    this.remotePort = request.getRemotePort();
    this.serverName = request.getServerName();
    this.secure = request.isSecure();
    populateAttributes(request);
}
 
Example 4
Source File: ServletContainerRequest.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
private static SecurityContext getSecurityContext(final HttpServletRequest servletRequest) {
    return new SecurityContext() {
        @Override
        public Principal getUserPrincipal() {
            return servletRequest.getUserPrincipal();
        }

        @Override
        public boolean isUserInRole(String role) {
            return servletRequest.isUserInRole(role);
        }

        @Override
        public boolean isSecure() {
            return servletRequest.isSecure();
        }

        @Override
        public String getAuthenticationScheme() {
            return servletRequest.getAuthType();
        }
    };
}
 
Example 5
Source File: DefaultSecurityManager.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Authenticate the request.
 *
 * @param request the request.
 * @param response the response.
 * @return true if authenticated, false otherwise.
 * @throws IOException when an I/O error occurs.
 * @throws ServletException when a Servlet error occurs.
 */
@Override
public boolean authenticate(
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    boolean result = false;

    if (request.getAuthType() != null) {
        if (request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) {
            throw new ServletException("Basic auth is not supported");
        }

        if (request.getAuthType().equals(HttpServletRequest.CLIENT_CERT_AUTH)) {
            throw new ServletException("Client cert auth is not supported");
        }

        if (request.getAuthType().equals(HttpServletRequest.DIGEST_AUTH)) {
            throw new ServletException("Digest auth is not supported");
        }

        if (request.getAuthType().equals(HttpServletRequest.FORM_AUTH)) {
            String username = request.getParameter("j_username");
            String password = request.getParameter("j_password");
            login(request, username, password);
            if (request.getUserPrincipal() != null) {
                result = true;
            }
        }
    }

    return result;
}
 
Example 6
Source File: HttpServletRequestSnapshot.java    From cxf with Apache License 2.0 5 votes vote down vote up
public HttpServletRequestSnapshot(HttpServletRequest request) {
    super(request);
    authType = request.getAuthType();
    characterEncoding = request.getCharacterEncoding();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    contextPath = request.getContextPath();
    cookies = request.getCookies();
    requestHeaderNames = request.getHeaderNames();
    Enumeration<String> tmp = request.getHeaderNames();
    while (tmp.hasMoreElements()) {
        String key = tmp.nextElement();
        headersMap.put(key, request.getHeaders(key));
    }
    localAddr = request.getLocalAddr();
    local = request.getLocale();
    localName = request.getLocalName();
    localPort = request.getLocalPort();
    method = request.getMethod();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    protocol = request.getProtocol();
    queryString = request.getQueryString();
    remoteAddr = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    remoteUser = request.getRemoteUser();
    requestURI = request.getRequestURI();
    requestURL = request.getRequestURL();
    requestedSessionId = request.getRequestedSessionId();
    schema = request.getScheme();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    servletPath = request.getServletPath();
    if (request.isRequestedSessionIdValid()) {
        session = request.getSession();
    }
    principal = request.getUserPrincipal();
}
 
Example 7
Source File: RequestData.java    From sample.ferret with Apache License 2.0 5 votes vote down vote up
public RequestData(final HttpServletRequest request) {
    method = request.getMethod();
    uri = request.getRequestURI();
    protocol = request.getProtocol();
    servletPath = request.getServletPath();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    characterEncoding = request.getCharacterEncoding();
    queryString = request.getQueryString();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    remoteUser = request.getRemoteUser();
    remoteAddress = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    localAddress = request.getLocalAddr();
    localHost = request.getLocalName();
    localPort = request.getLocalPort();
    authorizationScheme = request.getAuthType();
    preferredClientLocale = request.getLocale();
    allClientLocales = Collections.list(request.getLocales());
    contextPath = request.getContextPath();
    userPrincipal = request.getUserPrincipal();
    requestHeaders = getRequestHeaders(request);
    cookies = getCookies(request.getCookies());
    requestAttributes = getRequestAttributes(request);
}
 
Example 8
Source File: SendAuthTypeServlet.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    OutputStream stream = resp.getOutputStream();
    String authType = req.getAuthType();
    stream.write(authType.getBytes());
}
 
Example 9
Source File: RequestServlet.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	logger.info("访问 doGet");

	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");

	response.setContentType("text/html");

	String authType = request.getAuthType();
	String localAddr = request.getLocalAddr();
	Locale locale = request.getLocale();
	String localName = request.getLocalName();
	String contextPath = request.getContextPath();
	int localPort = request.getLocalPort();
	String method = request.getMethod();
	String pathInfo = request.getPathInfo();
	String pathTranslated = request.getPathTranslated();
	String protocol = request.getProtocol();
	String queryString = request.getQueryString();
	String remoteAddr = request.getRemoteAddr();
	int port = request.getRemotePort();
	String remoteUser = request.getRemoteUser();
	String requestedSessionId = request.getRequestedSessionId();
	String requestURI = request.getRequestURI();
	StringBuffer requestURL = request.getRequestURL();
	String scheme = request.getScheme();
	String serverName = request.getServerName();
	int serverPort = request.getServerPort();
	String servletPath = request.getServletPath();
	Principal userPrincipal = request.getUserPrincipal();

	String accept = request.getHeader("accept");
	String referer = request.getHeader("referer");
	String userAgent = request.getHeader("user-agent");

	String serverInfo = this.getServletContext().getServerInfo();

	PrintWriter out = response.getWriter();
	out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
	out.println("<HTML>");

	// 这里<title></title>之间的信息在浏览器中显示为标题
	out.println("  <HEAD><TITLE>Request Servlet</TITLE></HEAD>");
	out.println("  <style>body, font, td, div {font-size:12px; line-height:18px; }</style>");
	out.println("  <BODY>");

	out.println("<b>您的IP为</b> " + remoteAddr + "<b>;您使用</b> " + getOS(userAgent) + " <b>操作系统</b>,"
		+ getNavigator(userAgent) + " <b>。您使用</b> " + getLocale(locale) + "。<br/>");
	out.println("<b>服务器IP为</b> " + localAddr + localAddr + "<b>;服务器使用</b> " + serverPort + " <b>端口,您的浏览器使用了</b> "
		+ port + " <b>端口访问本网页。</b><br/>");
	out.println("<b>服务器软件为</b>:" + serverInfo + "。<b>服务器名称为</b> " + localName + "。<br/>");
	out.println("<b>您的浏览器接受</b> " + getAccept(accept) + "。<br/>");
	out.println("<b>您从</b> " + referer + " <b>访问到该页面。</b><br/>");
	out.println("<b>使用的协议为</b> " + protocol + "。<b>URL协议头</b> " + scheme + ",<b>服务器名称</b> " + serverName
		+ ",<b>您访问的URI为</b> " + requestURI + "。<br/>");
	out.println("<b>该 Servlet 路径为</b> " + servletPath + ",<b>该 Servlet 类名为</b> " + this.getClass().getName()
		+ "。<br/>");
	out.println("<b>本应用程序在硬盘的根目录为</b> " + this.getServletContext().getRealPath("") + ",<b>网络相对路径为</b> "
		+ contextPath + "。 <br/>");

	out.println("<br/>");

	out.println("<br/><br/><a href=" + requestURI + "> 点击刷新本页面 </a>");

	out.println("  </BODY>");
	out.println("</HTML>");
	out.flush();
	out.close();
}