✨ 添加新特性。 oauth execption response format
This commit is contained in:
1 parent
955fd80929
commit
517c86b900
20 files changed
+88
-47
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import com.pig4cloud.pigx.common.security.exception.PigxAuth2Exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/11/16
|
||||
* <p>
|
||||
* OAuth2 异常格式化
|
||||
*/
|
||||
public class PigxAuth2ExceptionSerializer extends StdSerializer<PigxAuth2Exception> {
|
||||
public PigxAuth2ExceptionSerializer() {
|
||||
super(PigxAuth2Exception.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PigxAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeObjectField("code", 1);
|
||||
gen.writeStringField("message", value.getMessage());
|
||||
gen.writeStringField("data", value.getOAuth2ErrorCode());
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class ForbiddenException extends PigxAuth2Exception {
|
||||
|
||||
public ForbiddenException(String msg, Throwable t) {
|
||||
|
||||
+4
@@ -17,10 +17,14 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class InvalidException extends PigxAuth2Exception {
|
||||
|
||||
public InvalidException(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class MethodNotAllowed extends PigxAuth2Exception {
|
||||
|
||||
public MethodNotAllowed(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,7 @@ import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
|
||||
* @date 2018/7/8
|
||||
* 自定义OAuth2Exception
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class PigxAuth2Exception extends OAuth2Exception {
|
||||
|
||||
public PigxAuth2Exception(String msg) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class ServerErrorException extends PigxAuth2Exception {
|
||||
|
||||
public ServerErrorException(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class UnauthorizedException extends PigxAuth2Exception {
|
||||
|
||||
public UnauthorizedException(String msg, Throwable t) {
|
||||
|
||||
+1
-1
@@ -102,6 +102,6 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
|
||||
// 构造security用户
|
||||
|
||||
return new PigxUser(user.getUserId(), user.getDeptId(), user.getTenantId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
|
||||
true, true, true, authorities);
|
||||
true, true, !CommonConstant.STATUS_LOCK.equals(user.getLockFlag()), authorities);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user