Added oauth response messages

revert-70aa11f8
harshanl 9 years ago
parent d2b8224f31
commit 8f982722fb

@ -26,6 +26,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthen
public class AuthenticationInfo {
private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE;
private String message;
private String username;
private String tenantDomain;
private int tenantId = -1;
@ -43,6 +44,14 @@ public class AuthenticationInfo {
return username;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setUsername(String username) {
this.username = username;
}

@ -74,12 +74,12 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId());
privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain());
privilegedCarbonContext.setUsername(authenticationInfo.getUsername());
this.processRequest(request, response, compositeValve, authenticationInfo.getStatus());
this.processRequest(request, response, compositeValve, authenticationInfo);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
} else {
this.processRequest(request, response, compositeValve, authenticationInfo.getStatus());
this.processRequest(request, response, compositeValve, authenticationInfo);
}
}
@ -113,14 +113,18 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
}
private void processRequest(Request request, Response response, CompositeValve compositeValve,
WebappAuthenticator.Status status) {
switch (status) {
AuthenticationInfo authenticationInfo) {
switch (authenticationInfo.getStatus()) {
case SUCCESS:
case CONTINUE:
this.getNext().invoke(request, response, compositeValve);
break;
case FAILURE:
String msg = "Failed to authorize incoming request";
if(authenticationInfo.getMessage() != null && !authenticationInfo.getMessage().isEmpty()) {
msg = authenticationInfo.getMessage();
response.setHeader("WWW-Authenticate", msg);
}
log.error(msg);
AuthenticationFrameworkUtil
.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED,

@ -117,6 +117,8 @@ public class OAuthAuthenticator implements WebappAuthenticator {
if (oAuth2TokenValidationResponseDTO.isValid()) {
authenticationInfo.setStatus(Status.CONTINUE);
}
} else {
authenticationInfo.setMessage(oAuth2TokenValidationResponseDTO.getErrorMsg());
}
}
} catch (AuthenticationException e) {

Loading…
Cancel
Save