本文整理匯總了Java中javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.SC_UNAUTHORIZED屬性的具體用法?Java HttpServletResponse.SC_UNAUTHORIZED怎麽用?Java HttpServletResponse.SC_UNAUTHORIZED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.SC_UNAUTHORIZED屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: scheduleExport
private void scheduleExport(HttpServletRequest req, HttpServletResponse resp,
ResourceBundle backendMessages, ResourceBundle messages) {
xLogger.fine("Entered scheduleExport");
int statusCode = HttpServletResponse.SC_OK;
// Send response back to client
try {
String respStr = RESTUtil.scheduleKioskDataExport(req, messages, resp);
if (respStr.contains("Invalid token")) {
statusCode = HttpServletResponse.SC_UNAUTHORIZED;
}
// Send response
sendJsonResponse(resp, statusCode, respStr);
} catch (Exception e2) {
xLogger.severe("OrderServlet Protocol Exception: {0}", e2.getMessage());
resp.setStatus(500);
}
xLogger.fine("Exiting scheduleExport");
}
示例2: scheduleExport
private void scheduleExport(HttpServletRequest req, HttpServletResponse resp,
ResourceBundle backendMessages, ResourceBundle messages) {
xLogger.fine("Entered scheduleExport");
int statusCode = HttpServletResponse.SC_OK;
// Send response back to client
try {
String respStr = RESTUtil.scheduleKioskDataExport(req, backendMessages, resp);
// Send response
if (respStr.contains("Invalid token")) {
statusCode = HttpServletResponse.SC_UNAUTHORIZED;
}
sendJsonResponse(resp, statusCode, respStr);
} catch (Exception e2) {
xLogger.severe("InventoryServlet Protocol Exception: {0}", e2.getMessage(), e2);
resp.setStatus(500);
}
xLogger.fine("Exiting scheduleExport");
}
示例3: getStatusForAccessDeniedException
/**
* Determines status code for AccessDeniedException based on client's HTTP headers.
*
* @return Returns status code
*/
protected int getStatusForAccessDeniedException()
{
if (m_request != null && m_request.getHeader(WebDAV.HEADER_USER_AGENT) != null)
{
String userAgent = m_request.getHeader(WebDAV.HEADER_USER_AGENT);
for (Entry<String, Integer> entry : accessDeniedStatusCodes.entrySet())
{
if (Pattern.compile(entry.getKey()).matcher(userAgent).find())
{
return entry.getValue();
}
}
}
return HttpServletResponse.SC_UNAUTHORIZED;
}
示例4: getErrorMessageByStatusCode
private String getErrorMessageByStatusCode(String requestPath, final int statusCode) {
String errMessage;
switch (statusCode) {
case HttpServletResponse.SC_NOT_FOUND:
errMessage = MessageFormat.format(ERROR_PATH_NOT_FOUND, requestPath);
break;
case HttpServletResponse.SC_UNAUTHORIZED:
errMessage = MessageFormat.format(ERROR_WRONG_CREDENTIALS, requestPath);
break;
case HttpServletResponse.SC_FORBIDDEN:
errMessage = MessageFormat.format(ERROR_UNAUTHORIZED, requestPath);
break;
default:
errMessage = MessageFormat.format(ERROR_UNEXPECTED_RESPONSE, requestPath);
}
return errMessage;
}
示例5: doFilter
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
KMSResponse kmsResponse = new KMSResponse(response);
super.doFilter(request, kmsResponse, filterChain);
if (kmsResponse.statusCode != HttpServletResponse.SC_OK &&
kmsResponse.statusCode != HttpServletResponse.SC_CREATED &&
kmsResponse.statusCode != HttpServletResponse.SC_UNAUTHORIZED) {
KMSWebApp.getInvalidCallsMeter().mark();
}
// HttpServletResponse.SC_UNAUTHORIZED is because the request does not
// belong to an authenticated user.
if (kmsResponse.statusCode == HttpServletResponse.SC_UNAUTHORIZED) {
KMSWebApp.getUnauthenticatedCallsMeter().mark();
String method = ((HttpServletRequest) request).getMethod();
StringBuffer requestURL = ((HttpServletRequest) request).getRequestURL();
String queryString = ((HttpServletRequest) request).getQueryString();
if (queryString != null) {
requestURL.append("?").append(queryString);
}
KMSWebApp.getKMSAudit().unauthenticated(
request.getRemoteHost(), method, requestURL.toString(),
kmsResponse.msg);
}
}
示例6: authenticate
@Override
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
{
return _authenticatedUser != null || (response.isCommitted() &&
(response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED ||
response.getStatus() == HttpServletResponse.SC_FORBIDDEN));
}
示例7: checkRedirectorAccess
private void checkRedirectorAccess(FlowContext context) throws ResponseCodeException, IOException {
String remoteAddress = context.getHttpServletRequest().getRemoteAddr();
if (!NmsCoreCommonConfiguration.getInstance().getDispatcherIpAddress().contains(remoteAddress)) {
String message = "Not used redirector.[" + remoteAddress + "]";
throw new ResponseCodeException(HttpServletResponse.SC_UNAUTHORIZED, message);
}
}
示例8: doTestBasic
private void doTestBasic(String uri,
TestSSOnonLoginAndBasicAuthenticator.BasicCredentials credentials,
boolean useCookie, int expectedRC) throws Exception {
Map<String,List<String>> reqHeaders = new HashMap<String,List<String>>();
Map<String,List<String>> respHeaders = new HashMap<String,List<String>>();
if (useCookie && (cookies != null)) {
reqHeaders.put(CLIENT_COOKIE_HEADER, cookies);
}
else {
if (credentials != null) {
List<String> auth = new ArrayList<String>();
auth.add(credentials.getCredentials());
reqHeaders.put(CLIENT_AUTH_HEADER, auth);
}
}
ByteChunk bc = new ByteChunk();
int rc = getUrl(HTTP_PREFIX + getPort() + uri, bc, reqHeaders,
respHeaders);
assertEquals("Unexpected Return Code", expectedRC, rc);
if (expectedRC != HttpServletResponse.SC_OK) {
assertTrue(bc.getLength() > 0);
if (expectedRC == HttpServletResponse.SC_UNAUTHORIZED) {
// The server should identify the acceptable method(s)
boolean methodFound = false;
List<String> authHeaders = respHeaders.get(SERVER_AUTH_HEADER);
for (String authHeader : authHeaders) {
if (authHeader.indexOf(NICE_METHOD) > -1) {
methodFound = true;
break;
}
}
assertTrue(methodFound);
}
}
else {
String thePage = bc.toString();
assertNotNull(thePage);
assertTrue(thePage.startsWith("OK"));
if (useCookie) {
List<String> newCookies = respHeaders.get(SERVER_COOKIE_HEADER);
if (newCookies != null) {
// harvest cookies whenever the server sends some new ones
cookies = newCookies;
}
}
else {
encodedURL = "";
final String start = "<a href=\"";
final String end = "\">";
int iStart = thePage.indexOf(start);
int iEnd = 0;
if (iStart > -1) {
iStart += start.length();
iEnd = thePage.indexOf(end, iStart);
if (iEnd > -1) {
encodedURL = thePage.substring(iStart, iEnd);
}
}
}
}
}
示例9: doTestBasic
private void doTestBasic(String uri, BasicCredentials credentials,
boolean useCookie, int expectedRC) throws Exception {
Map<String,List<String>> reqHeaders =
new HashMap<String, List<String>>();
Map<String,List<String>> respHeaders =
new HashMap<String, List<String>>();
if (useCookie && (cookies != null)) {
reqHeaders.put(CLIENT_COOKIE_HEADER, cookies);
}
else {
if (credentials != null) {
List<String> auth = new ArrayList<String>();
auth.add(credentials.getCredentials());
reqHeaders.put(CLIENT_AUTH_HEADER, auth);
}
}
ByteChunk bc = new ByteChunk();
int rc = getUrl(HTTP_PREFIX + getPort() + uri, bc, reqHeaders,
respHeaders);
if (expectedRC != HttpServletResponse.SC_OK) {
assertEquals(expectedRC, rc);
assertTrue(bc.getLength() > 0);
if (expectedRC == HttpServletResponse.SC_UNAUTHORIZED) {
// The server should identify the acceptable method(s)
boolean methodFound = false;
List<String> authHeaders = respHeaders.get(SERVER_AUTH_HEADER);
for (String authHeader : authHeaders) {
if (authHeader.indexOf(NICE_METHOD) > -1) {
methodFound = true;
break;
}
}
assertTrue(methodFound);
}
}
else {
assertEquals("OK", bc.toString());
List<String> newCookies = respHeaders.get(SERVER_COOKIE_HEADER);
if (newCookies != null) {
// harvest cookies whenever the server sends some new ones
cookies = newCookies;
}
}
}
示例10: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Current user
String userID = AuthenticationUtil.getFullyAuthenticatedUser();
if (userID == null)
{
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script ["
+ req.getServiceMatch().getWebScript().getDescription()
+ "] requires user authentication.");
}
StoreRef storeRef = parseRequestForStoreRef(req);
NodeRef nodeRef = parseRequestForNodeRef(req);
List<NodeRef> nodesToBePurged = new ArrayList<NodeRef>();
if (nodeRef != null)
{
// check if the current user has the permission to purge the node
validatePermission(nodeRef, userID);
// If there is a specific NodeRef, then that is the only Node that should be purged.
// In this case, the NodeRef points to the actual node to be purged i.e. the node in
// the archive store.
nodesToBePurged.add(nodeRef);
}
else
{
// But if there is no specific NodeRef and instead there is only a StoreRef, then
// all nodes which were originally in that StoreRef should be purged.
// Create paging
ScriptPagingDetails paging = new ScriptPagingDetails(maxSizeView, 0);
PagingResults<NodeRef> result = getArchivedNodesFrom(storeRef, paging, null);
nodesToBePurged.addAll(result.getPage());
}
if (log.isDebugEnabled())
{
log.debug("Purging " + nodesToBePurged.size() + " nodes");
}
// Now having identified the nodes to be purged, we simply have to do it.
nodeArchiveService.purgeArchivedNodes(nodesToBePurged);
model.put(PURGED_NODES, nodesToBePurged);
return model;
}
示例11: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Current user
String userID = AuthenticationUtil.getFullyAuthenticatedUser();
if (userID == null)
{
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script ["
+ req.getServiceMatch().getWebScript().getDescription()
+ "] requires user authentication.");
}
NodeRef nodeRefToBeRestored = parseRequestForNodeRef(req);
if (nodeRefToBeRestored == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "nodeRef not recognised. Could not restore.");
}
// check if the current user has the permission to restore the node
validatePermission(nodeRefToBeRestored, userID);
RestoreNodeReport report = nodeArchiveService.restoreArchivedNode(nodeRefToBeRestored);
// Handling of some error scenarios
if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_ARCHIVE_NODE))
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find archive node: " + nodeRefToBeRestored);
}
else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_PERMISSION))
{
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Unable to restore archive node: " + nodeRefToBeRestored);
}
else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_DUPLICATE_CHILD_NODE_NAME))
{
throw new WebScriptException(HttpServletResponse.SC_CONFLICT, "Unable to restore archive node: " + nodeRefToBeRestored +". Duplicate child node name");
}
else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_PARENT) ||
report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INTEGRITY) ||
report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_OTHER))
{
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to restore archive node: " + nodeRefToBeRestored);
}
model.put("restoreNodeReport", report);
return model;
}