当前位置: 首页>>代码示例>>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;未经允许,请勿转载。