當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.SC_FORBIDDEN屬性代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.SC_FORBIDDEN屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.SC_FORBIDDEN屬性的具體用法?Java HttpServletResponse.SC_FORBIDDEN怎麽用?Java HttpServletResponse.SC_FORBIDDEN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.SC_FORBIDDEN屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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;
}
 
開發者ID:SAP,項目名稱:cloud-c4c-ticket-duplicate-finder-ext,代碼行數:17,代碼來源:DefaultHTTPResponseValidator.java

示例2: 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));
}
 
開發者ID:curityio,項目名稱:oauth-filter-for-java,代碼行數:7,代碼來源:AuthenticatedUserRequestWrapper.java

示例3: validateCurrentUser

protected void validateCurrentUser()
{
    String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
    // check the current user access rights
    if (!facetService.isSearchAdmin(currentUser))
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Access denied.");
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:9,代碼來源:AbstractSolrFacetConfigAdminWebScript.java

示例4: buildModel

@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
{
    Map<String, String> params = req.getServiceMatch().getTemplateVars();

    // getting workflow instance id from request parameters
    String workflowInstanceId = params.get("workflow_instance_id");
    
    // determine if instance should be cancelled or deleted
    boolean forced = getForced(req);

    if (canUserEndWorkflow(workflowInstanceId))
    {
        if (forced)
        {
            workflowService.deleteWorkflow(workflowInstanceId);
        }
        else
        {
            workflowService.cancelWorkflow(workflowInstanceId);
        }
        
        return null;
    }
    else
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Failed to " + 
                    (forced ? "delete" : "cancel") + " workflow instance with id: " + workflowInstanceId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:30,代碼來源:WorkflowInstanceDelete.java

示例5: executeImpl

@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    
    try
    {
        boolean canRead = quickShareService.canRead(sharedId);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("canRead", canRead);
        return result;            
    }
    catch (InvalidSharedIdException ex)
    {
        logger.error("Unable to find: "+sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:34,代碼來源:ReadGet.java

示例6: executeImpl

@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    
    try
    {
        return quickShareService.getMetaData(sharedId);
    }
    catch (InvalidSharedIdException ex)
    {
        logger.error("Unable to find: "+sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:31,代碼來源:QuickShareMetaDataGet.java

示例7: executeImpl

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
    if (nodeRef == null)
    {
        String msg = "A valid NodeRef must be specified!";
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
    }
    
    try
    {
        QuickShareDTO dto = quickShareService.shareContent(nodeRef);
        
        Map<String, Object> model = new HashMap<String, Object>(1);
        model.put("sharedDTO", dto);
        return model;
    }
    catch (InvalidNodeRefException inre)
    {
    	throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:30,代碼來源:ShareContentPost.java

示例8: login

protected Map<String, Object> login(final String username, String password)
{
    try
    {
        // get ticket
        authenticationService.authenticate(username, password.toCharArray());

        eventPublisher.publishEvent(new EventPreparator(){
            @Override
            public Event prepareEvent(String user, String networkId, String transactionId)
            {
            	// TODO need to fix up to pass correct seqNo and alfrescoClientId
                return new RepositoryEventImpl(-1l, "login", transactionId, networkId, new Date().getTime(),
                		username, null);
            }
        });
        
        // add ticket to model for javascript and template access
        Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
        model.put("username", username);
        model.put("ticket",  authenticationService.getCurrentTicket());
        
        return model;
    }
    catch(AuthenticationException e)
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Login failed");
    }
    finally
    {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:33,代碼來源:AbstractLoginBean.java

示例9: 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;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:48,代碼來源:ArchivedNodePut.java

示例10: authenticate

public boolean authenticate(RequiredAuthentication required, boolean isGuest)
{
    // first look for the username key in the session - we add this by hand for some portals
    // when the WebScriptPortletRequest is created
    String portalUser = (String)req.getPortletSession().getAttribute(WebScriptPortletRequest.ALFPORTLETUSERNAME);
    if (portalUser == null)
    {
        portalUser = req.getRemoteUser();
    }
    
    if (logger.isDebugEnabled())
    {
        logger.debug("JSR-168 Remote user: " + portalUser);
    }
    
    if (isGuest || portalUser == null)
    {
        if (logger.isDebugEnabled())
            logger.debug("Authenticating as Guest");
        
        // authenticate as guest
        AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
    }
    else
    {
        if (logger.isDebugEnabled())
            logger.debug("Authenticating as user " + portalUser);

        UserTransaction txn = null;
        try
        {
        	txn = txnService.getUserTransaction();
        	txn.begin();

        	if (!unprotAuthenticationService.authenticationExists(portalUser))
        	{
        		throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
        	}
        	AuthenticationUtil.setFullyAuthenticatedUser(portalUser);
        }
        catch (Throwable err)
        {
        	throw new AlfrescoRuntimeException("Error authenticating user: " + portalUser, err);
        }
        finally
        {
        	try
        	{
        		if (txn != null)
        		{
        			txn.rollback();
        		}
        	}
        	catch (Exception tex)
        	{
        		// nothing useful we can do with this
        	}
        }
    }
    
    return true;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:62,代碼來源:JSR168PortletAuthenticatorFactory.java

示例11: execute

@Override
public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of template vars (params)
    final Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    
    try
    {
        Pair<String, NodeRef> pair = quickShareSerivce.getTenantNodeRefFromSharedId(sharedId);
        final String tenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();

        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
        {
            public Void doWork() throws Exception
            {
                if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
                {
                    throw new InvalidNodeRefException(nodeRef);
                }
                
                executeImpl(nodeRef, params, req, res, null);
                
                return null;
            }
        }, tenantDomain);
        
        if (logger.isDebugEnabled())
        {
            logger.debug("QuickShare - retrieved content: "+sharedId+" ["+nodeRef+"]");
        }

    }
    catch (InvalidSharedIdException ex)
    {
        logger.error("Unable to find: "+sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:54,代碼來源:QuickShareContentGet.java

示例12: executeImpl

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    
    try
    {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        final String tenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        
        String siteId = siteService.getSiteShortName(nodeRef);
        
        Map<String, Object> model = new HashMap<String, Object>(3);
        model.put("sharedId", sharedId);
        model.put("nodeRef", nodeRef.toString());
        model.put("siteId", siteId);
        model.put("tenantDomain", tenantDomain);
        
        if (logger.isInfoEnabled())
        {
            logger.info("QuickShare - get shared context: "+sharedId+" ["+model+"]");
        }
        
        return model;
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:43,代碼來源:ShareContentGet.java

示例13: executeImpl

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }

    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }

    try
    {
        NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();

        String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
        if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy))
        {
            throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId);
        }
        quickShareService.unshareContent(sharedId);

        Map<String, Object> model = new HashMap<>(1);
        model.put("success", Boolean.TRUE);
        return model;
    }
    catch (InvalidSharedIdException ex)
    {
        logger.error("Unable to find: " + sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:42,代碼來源:UnshareContentDelete.java

示例14: patchProperties

protected void patchProperties(FileInfo nodeInfo, String path) throws WebDAVServerException
{
    failedProperty = null;
    for (PropertyAction action : m_propertyActions)
    {
        if (action.getProperty().isProtected())
        {
            failedProperty = action.getProperty();
            break;
        }
    }

    Map<QName, String> deadProperties = null;
    for (PropertyAction propertyAction : m_propertyActions)
    {
        int statusCode;
        String statusCodeDescription;
        WebDAVProperty property = propertyAction.getProperty();

        if (failedProperty == null)
        {
            PropertyDefinition propDef = getDAVHelper().getDictionaryService().getProperty(property.createQName());
            
            boolean deadProperty = propDef == null || (!propDef.getContainerClass().isAspect() && !getDAVHelper().getDictionaryService().isSubClass(getNodeService().getType(nodeInfo.getNodeRef()), 
                    propDef.getContainerClass().getName()));
            
            if (deadProperty && deadProperties == null)
            {
                deadProperties = loadDeadProperties(nodeInfo.getNodeRef());
            }

            if (PropertyAction.SET == propertyAction.getAction())
            {
                if (deadProperty)
                {
                    deadProperties.put(property.createQName(), property.getValue());
                }
                else
                {
                    getNodeService().setProperty(nodeInfo.getNodeRef(), property.createQName(), property.getValue());
                }
            }
            else if (PropertyAction.REMOVE == propertyAction.getAction())
            {
                if (deadProperty)
                {
                    deadProperties.remove(property.createQName());
                }
                else
                {
                    getNodeService().removeProperty(nodeInfo.getNodeRef(), property.createQName());
                }
            }
            else
            {
                throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
            }
            statusCode = HttpServletResponse.SC_OK;
            statusCodeDescription = WebDAV.SC_OK_DESC;
        }
        else if (failedProperty == property)
        {
            statusCode = HttpServletResponse.SC_FORBIDDEN;
            statusCodeDescription = WebDAV.SC_FORBIDDEN_DESC;
        }
        else
        {
            statusCode = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY;
            statusCodeDescription = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY_DESC;
        }

        propertyAction.setResult(statusCode, statusCodeDescription);
    }
    if (deadProperties != null)
    {
        persistDeadProperties(nodeInfo.getNodeRef(), deadProperties);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:78,代碼來源:PropPatchMethod.java


注:本文中的javax.servlet.http.HttpServletResponse.SC_FORBIDDEN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。