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


Java Status.UNAUTHORIZED屬性代碼示例

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


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

示例1: filter

@Override
    public ContainerRequest filter(ContainerRequest containerRequest) throws WebApplicationException {

//        String method = containerRequest.getMethod();
//        String path = containerRequest.getPath(true);
 
        String auth = containerRequest.getHeaderValue("authorization");
        if(auth == null){
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
 
        String[] credentials = decode(auth);
 
        if(credentials == null || credentials.length != 2){
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
 
        String uid = UserAuthentication.authenticate(credentials[0], credentials[1]);
 
        if(uid == null){
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
 
        containerRequest.getRequestHeaders().add("uid", uid);
        
        return containerRequest;
    }
 
開發者ID:NLPReViz,項目名稱:emr-nlp-server,代碼行數:27,代碼來源:AuthFilter.java

示例2: getAuthenticatedUser

protected String getAuthenticatedUser(SecurityContext securityContext) {
    String user = null;
    if (securityContext.getUserPrincipal() != null) {
        user = securityContext.getUserPrincipal().getName();
    } else {
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }
    LOGGER.debug("Authenticated user is: " + user);
    return user;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:10,代碼來源:OperationsApiServiceImpl.java

示例3: buildAuthenticationErrorResponse

/**
 * Build an authentication error response
 * @param schemes Optional allowed authentication schemes
 * @param errorCode Optional error code
 * @param errorDescription Optional error description
 * @param statusCode HTTP status code
 * @param realmName Optional realm name
 * @return Authentication error response
 */
public static Response buildAuthenticationErrorResponse(String[] schemes, String errorCode, String errorDescription,
		int statusCode, String realmName) {

	// status
	Status status = Status.UNAUTHORIZED;
	if (statusCode > 0) {
		Status errorStatus = Status.fromStatusCode(statusCode);
		if (errorStatus != null) {
			status = errorStatus;
		}
	}

	// response
	ResponseBuilder responseBuilder = Response.status(status);

	if (schemes != null && schemes.length > 0) {
		for (String scheme : schemes) {
			responseBuilder.header(HttpHeaders.WWW_AUTHENTICATE,
					buildAuthenticationErrorHeader(scheme, errorCode, errorDescription, realmName));
		}
	}

	// response
	return responseBuilder.header(HttpHeaders.CACHE_CONTROL, "no-store").header(HttpHeaders.PRAGMA, "no-cache")
			.build();
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:35,代碼來源:ResponseUtils.java

示例4: lockTaxonomy

@POST
@Path("/{uuid}/lock")
@ApiOperation(value = "Lock taxonomy")
public Response lockTaxonomy(
	@ApiParam(value = "Taxonomy uuid", required = true) @PathParam("uuid") String taxonomyUuid)
{
	try
	{
		final Taxonomy taxonomy = ensureTaxonomy(taxonomyUuid, PrivCheck.EDIT);
		lockingService.lockEntity(taxonomy);
	}
	catch( LockedException ex )
	{
		if( CurrentUser.getUserID().equals(ex.getUserID()) )
		{
			throw new WebApplicationException(
				"Taxonomy is locked in a different session.  Call unlockTaxonomy with a force parameter value of true.",
				Status.UNAUTHORIZED);
		}
		else
		{
			throw new WebApplicationException("Taxonomy is locked by another user: " + ex.getUserID(),
				Status.UNAUTHORIZED);
		}
	}
	return Response.ok().build();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:27,代碼來源:TaxonomyResource.java

示例5: unlockTaxonomy

@DELETE
@Path("/{uuid}/lock")
@Produces("application/json")
@ApiOperation(value = "unlock taxonomy")
public Response unlockTaxonomy(
	@ApiParam(value = "Taxonomy uuid", required = true) @PathParam("uuid") String taxonomyUuid,
	@ApiParam(value = "force unlock", required = false) @QueryParam("force") boolean force)
{
	try
	{
		final Taxonomy taxonomy = ensureTaxonomy(taxonomyUuid, PrivCheck.EDIT);
		lockingService.unlockEntity(taxonomy, force);
	}
	catch( LockedException ex )
	{
		if( CurrentUser.getUserID().equals(ex.getUserID()) )
		{
			throw new WebApplicationException(
				"Taxonomy is locked in a different session.  Call unlockTaxonomy with a force parameter value of true.",
				Status.UNAUTHORIZED);
		}
		else
		{
			throw new WebApplicationException(
				"You do not own the lock on this taxonomy.  It is held by user ID " + ex.getUserID(),
				Status.UNAUTHORIZED);
		}
	}
	return Response.ok().build();

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:31,代碼來源:TaxonomyResource.java

示例6: toResponse

@Override
public Response toResponse(AccessDeniedException exception) {
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();

    // if the user was authenticated - forbidden, otherwise unauthorized... the user may be null if the
    // AccessDeniedException was thrown from a /access endpoint that isn't subject to the security
    // filter chain. for instance, one that performs kerberos negotiation
    final Status status;
    if (user == null || user.isAnonymous()) {
        status = Status.UNAUTHORIZED;
    } else {
        status = Status.FORBIDDEN;
    }

    final String identity;
    if (user == null) {
        identity = "<no user found>";
    } else {
        identity = user.toString();
    }

    logger.info(String.format("%s does not have permission to access the requested resource. %s Returning %s response.", identity, exception.getMessage(), status));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Response.status(status)
            .entity(String.format("%s Contact the system administrator.", exception.getMessage()))
            .type("text/plain")
            .build();
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:33,代碼來源:AccessDeniedExceptionMapper.java

示例7: checkAccess

private void checkAccess(Job job, HttpServletRequest request) {
  if (!hasAccess(job, request)) {
    throw new WebApplicationException(Status.UNAUTHORIZED);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:5,代碼來源:HsWebServices.java

示例8: unauthorized

/**
 * Creates a builder for a unauthorized request
 * 
 * @return the exception builder
 */
public static ExceptionBuilder unauthorized() {
    return new ExceptionBuilder(Status.UNAUTHORIZED);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:8,代碼來源:WebException.java

示例9: checkAccess

/**
 * check for job access.
 *
 * @param job
 *          the job that is being accessed
 */
void checkAccess(Job job, HttpServletRequest request) {
  if (!hasAccess(job, request)) {
    throw new WebApplicationException(Status.UNAUTHORIZED);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:11,代碼來源:AMWebServices.java


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