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 { public class AuthenticationInfo {
private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE; private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE;
private String message;
private String username; private String username;
private String tenantDomain; private String tenantDomain;
private int tenantId = -1; private int tenantId = -1;
@ -43,6 +44,14 @@ public class AuthenticationInfo {
return username; return username;
} }
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }

@ -74,12 +74,12 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId()); privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId());
privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain()); privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain());
privilegedCarbonContext.setUsername(authenticationInfo.getUsername()); privilegedCarbonContext.setUsername(authenticationInfo.getUsername());
this.processRequest(request, response, compositeValve, authenticationInfo.getStatus()); this.processRequest(request, response, compositeValve, authenticationInfo);
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }
} else { } 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, private void processRequest(Request request, Response response, CompositeValve compositeValve,
WebappAuthenticator.Status status) { AuthenticationInfo authenticationInfo) {
switch (status) { switch (authenticationInfo.getStatus()) {
case SUCCESS: case SUCCESS:
case CONTINUE: case CONTINUE:
this.getNext().invoke(request, response, compositeValve); this.getNext().invoke(request, response, compositeValve);
break; break;
case FAILURE: case FAILURE:
String msg = "Failed to authorize incoming request"; 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); log.error(msg);
AuthenticationFrameworkUtil AuthenticationFrameworkUtil
.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, .handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED,

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

Loading…
Cancel
Save