Java Code Examples for org.springframework.http.HttpHeaders#AUTHORIZATION

The following examples show how to use org.springframework.http.HttpHeaders#AUTHORIZATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccoutJwtResource.java    From albedo with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * @return org.springframework.http.ResponseEntity
 * @description 登出
 * @Param: [authHeader, request, response]
 * @author somewhere
 * @date 2020/5/30
 */
@AnonymousAccess
@GetMapping(value = "/logout")
@ApiOperation("登出")
public ResponseEntity logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader,
							 HttpServletRequest request, HttpServletResponse response) {
	String tokenValue = authHeader.replace("Bearer ", StrUtil.EMPTY).trim();
	RedisUtil.delete(tokenValue);
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	if (auth != null) {
		new SecurityContextLogoutHandler().logout(request, response, auth);
	}
	WebUtil.removeCookie(response, HttpHeaders.AUTHORIZATION);
	request.getSession().invalidate();
	return ResponseEntityBuilder.buildOk("退出登录成功");

}
 
Example 2
Source File: UserAuthenticationController.java    From cerberus with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/user", method = GET)
public AuthResponse authenticate(
    @RequestHeader(value = HttpHeaders.AUTHORIZATION) String authHeader) {
  final UserCredentials credentials = extractCredentials(authHeader);

  AuthResponse authResponse;
  try {
    authResponse = authenticationService.authenticate(credentials);
  } catch (ApiException e) {
    auditLoggingFilterDetails.setAction("Failed to authenticate");
    throw e;
  }

  auditLoggingFilterDetails.setAction("Authenticated");

  return authResponse;
}
 
Example 3
Source File: HomeController.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 清除token(注销登录)
 */
@SysLog("登出")
@DeleteMapping("/logout")
@ApiOperation(value = "登出")
public ApiResponse logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
    if (StringUtils.isBlank(authHeader)) {
        return fail("退出失败,token 为空");
    }
    //注销当前用户
    String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StringUtils.EMPTY).trim();
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
    tokenStore.removeAccessToken(accessToken);
    OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
    tokenStore.removeRefreshToken(refreshToken);
    return success("注销成功");
}
 
Example 4
Source File: HomeController.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 清除token(注销登录)
 */
@SysLog("登出")
@DeleteMapping("/logout")
@ApiOperation(value = "登出")
public ApiResponse logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
    if (StringUtils.isBlank(authHeader)) {
        return fail("退出失败,token 为空");
    }
    //注销当前用户
    String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StringUtils.EMPTY).trim();
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
    tokenStore.removeAccessToken(accessToken);
    OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
    tokenStore.removeRefreshToken(refreshToken);
    return success("注销成功");
}
 
Example 5
Source File: SmakerTokenEndpoint.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 退出token
 *
 * @param authHeader Authorization
 */
@GetMapping("/removeToken")
public SmakerResult<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
	if (StringUtils.hasText(authHeader)) {
		String tokenValue = authHeader.replace("Bearer", "").trim();
		OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
		if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
			return new SmakerResult<>(false, "退出失败,token 为空");
		}
		tokenStore.removeAccessToken(accessToken);
	}

	return new SmakerResult<>(Boolean.TRUE);
}
 
Example 6
Source File: SctTokenEndpoint.java    From cloud-template with MIT License 5 votes vote down vote up
@DeleteMapping("/logout")
public Result logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
    log.info("Logout  >>  ....");
    if (StringUtils.isBlank(authHeader)) {
        return new Result(CommonEnums.LOGOUT_ERROR);
    }
    String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE.toLowerCase(), "").trim();
    OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(tokenValue);
    if (oAuth2AccessToken == null || StringUtils.isBlank(oAuth2AccessToken.getValue())) {
        return new Result(CommonEnums.LOGOUT_ERROR);
    }
    tokenStore.removeAccessToken(oAuth2AccessToken);
    return new Result();
}
 
Example 7
Source File: ConfigController.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
@PostMapping("/refresh/{appName}")
public Mono<String> refresh(@PathVariable(name = "appName") String appName,
                            @RequestParam(name = "ip", required = false) String ip,
                            @RequestParam(name = "id", required = false) String id,
                            @RequestHeader(name = HttpHeaders.AUTHORIZATION) String jwtToken,
                            @RequestBody String body) {
    RSocketAppPrincipal appPrincipal = parseAppPrincipal(jwtToken);
    if (appPrincipal != null && appPrincipal.getSubject().equalsIgnoreCase("rsocket-admin")) {
        //update config for ip or id
        if (ip != null || id != null) {
            CloudEventImpl<ConfigEvent> configEvent = CloudEventBuilder.<ConfigEvent>builder()
                    .withId(UUID.randomUUID().toString())
                    .withTime(ZonedDateTime.now())
                    .withSource(URI.create("broker://" + RSocketAppContext.ID))
                    .withType(ConfigEvent.class.getCanonicalName())
                    .withDataContentType("text/x-java-properties")
                    .withData(new ConfigEvent(appName, "text/x-java-properties", body))
                    .build();
            return Flux.fromIterable(handlerRegistry.findByAppName(appName)).filter(handler -> {
                AppMetadata appMetadata = handler.getAppMetadata();
                return appMetadata.getUuid().equals(id) || appMetadata.getIp().equals(ip);
            }).flatMap(handler -> handler.fireCloudEventToPeer(configEvent)).then(Mono.just("success"));
        } else {
            return configurationService.put(appName + ":application.properties", body).map(aVoid -> "success");
        }
    } else {
        return Mono.error(new InvalidException(RsocketErrorCode.message("RST-500403")));
    }
}
 
Example 8
Source File: ConfigController.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
@GetMapping("/last/{appName}")
public Mono<String> fetch(@PathVariable(name = "appName") String appName, @RequestHeader(name = HttpHeaders.AUTHORIZATION) String jwtToken) {
    RSocketAppPrincipal appPrincipal = parseAppPrincipal(jwtToken);
    if (appPrincipal != null && (appName.equalsIgnoreCase(appPrincipal.getSubject()) || appPrincipal.getSubject().equalsIgnoreCase("rsocket-admin"))) {
        return configurationService.get(appName + ":application.properties");
    } else {
        return Mono.error(new InvalidException(RsocketErrorCode.message("RST-500403")));
    }
}
 
Example 9
Source File: HomeController.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
/**
 * 清除token(注销登录)
 */
@DeleteMapping("/logout")
public ApiResponse logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
    if (StringUtils.isBlank(authHeader)) {
        return fail("退出失败,token 为空");
    }
    //注销当前用户
    String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StringUtils.EMPTY).trim();
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
    tokenStore.removeAccessToken(accessToken);
    OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
    tokenStore.removeRefreshToken(refreshToken);
    return success("注销成功");
}
 
Example 10
Source File: Swagger2.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
private ApiKey apiKey() {
    return new ApiKey("Token Access", HttpHeaders.AUTHORIZATION, "header");
}
 
Example 11
Source File: AuthServiceRpc.java    From codeway_service with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 调用签权服务,判断用户是否有权限
 */
@PostMapping(value = "oauth/permission")
JsonData authPermission(@RequestParam("url") String url,
                        @RequestParam("method") String method,
						@RequestHeader(HttpHeaders.AUTHORIZATION) String authentication);
 
Example 12
Source File: AISApi.java    From XS2A-Sandbox with Apache License 2.0 4 votes vote down vote up
@GetMapping(path = "/auth", params = {"redirectId", "encryptedConsentId"})
@ApiOperation(value = "Entry point for authenticating ais consent requests.")
ResponseEntity<AuthorizeResponse> aisAuth(
    @RequestParam(name = "redirectId") String redirectId,
    @RequestParam(name = "encryptedConsentId") String encryptedConsentId,
    @RequestHeader(name = HttpHeaders.AUTHORIZATION, required = false) String token);
 
Example 13
Source File: AuthServiceRpc.java    From codeway_service with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 调用签权服务,判断用户是否有权限
 */
@PostMapping(value = "oauth/permission")
JsonData authPermission(@RequestParam("url") String url,
                        @RequestParam("method") String method,
						@RequestHeader(HttpHeaders.AUTHORIZATION) String authentication);
 
Example 14
Source File: PISApi.java    From XS2A-Sandbox with Apache License 2.0 3 votes vote down vote up
/**
 * STEP-P0: payment Entry Point
 * <p>
 * Receptions a payment authorization link. Generate an eca-id associated with the login process.
 *
 * @param redirectId         the redirect is
 * @param encryptedPaymentId the enc payment idf
 * @return AuthorizeResponse
 */
@GetMapping(path = "/auth", params = {"redirectId", "encryptedPaymentId"})
@ApiOperation(value = "Entry point for authenticating payment requests.")
ResponseEntity<AuthorizeResponse> pisAuth(
    @RequestParam(name = "redirectId") String redirectId,
    @RequestParam(name = "encryptedPaymentId") String encryptedPaymentId,
    @RequestHeader(name = HttpHeaders.AUTHORIZATION, required = false) String token);
 
Example 15
Source File: LoginLogServiceRpc.java    From codeway_service with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 增加登录日志
 *
 * @param loginLog 登录日志实体
 * @return JsonData
 */
@PostMapping
JsonData<Void> insertLoginLog(@RequestHeader(HttpHeaders.AUTHORIZATION) String auth, @RequestBody LoginLog loginLog);
 
Example 16
Source File: AuthProvider.java    From JetfireCloud with Apache License 2.0 2 votes vote down vote up
/**
 * 调用签权服务,判断用户是否有权限
 *
 * @param authentication
 * @param url
 * @param method
 * @return <pre>
 * Result:
 * {
 *   code:"000000"
 *   mesg:"请求成功"
 *   data: true/false
 * }
 * </pre>
 */
@PostMapping(value = "/auth/permission")
Result auth(@RequestHeader(HttpHeaders.AUTHORIZATION) String authentication, @RequestParam("url") String url, @RequestParam("method") String method);
 
Example 17
Source File: AuthProvider.java    From SpringCloud with Apache License 2.0 2 votes vote down vote up
/**
 * 调用签权服务,判断用户是否有权限
 *
 * @param authentication
 * @param url
 * @param method
 * @return <pre>
 * Result:
 * {
 *   code:"000000"
 *   mesg:"请求成功"
 *   data: true/false
 * }
 * </pre>
 */
@PostMapping(value = "/auth/permission")
Result auth(@RequestHeader(HttpHeaders.AUTHORIZATION) String authentication, @RequestParam("url") String url, @RequestParam("method") String method);
 
Example 18
Source File: LoginLogServiceRpc.java    From codeway_service with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 增加登录日志
 *
 * @param loginLog 登录日志实体
 * @return JsonData
 */
@PostMapping
JsonData<Void> insertLoginLog(@RequestHeader(HttpHeaders.AUTHORIZATION) String auth, @RequestBody LoginLog loginLog);