本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例7: checkAccess
private void checkAccess(Job job, HttpServletRequest request) {
if (!hasAccess(job, request)) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
}
示例8: unauthorized
/**
* Creates a builder for a unauthorized request
*
* @return the exception builder
*/
public static ExceptionBuilder unauthorized() {
return new ExceptionBuilder(Status.UNAUTHORIZED);
}
示例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);
}
}