use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20InvalidAuthorizationResponseBuilderTests method verifyRequestWithCallbackAndDescription.
@Test
public void verifyRequestWithCallbackAndDescription() {
val request = new MockHttpServletRequest();
request.addParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
request.addParameter(OAuth20Constants.REDIRECT_URI, "https://github.com/apereo/cas");
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
assertFalse(oauthInvalidAuthorizationBuilder.supports(context));
context.setRequestAttribute(OAuth20Constants.ERROR, OAuth20Constants.INVALID_REQUEST);
context.setRequestAttribute(OAuth20Constants.ERROR_DESCRIPTION, "Invalid Request Description");
context.setRequestAttribute(OAuth20Constants.ERROR_WITH_CALLBACK, true);
assertTrue(oauthInvalidAuthorizationBuilder.supports(context));
val mv = oauthInvalidAuthorizationBuilder.build(context);
assertTrue(mv.getView() instanceof RedirectView);
val mvView = (RedirectView) mv.getView();
assertEquals(mvView.getUrl(), "https://github.com/apereo/cas");
assertTrue(mv.getModel().containsKey(OAuth20Constants.ERROR));
assertTrue(mv.getModel().containsKey(OAuth20Constants.ERROR_DESCRIPTION));
assertFalse(mv.getModel().containsKey(OAuth20Constants.STATE));
val error = mv.getModel().get(OAuth20Constants.ERROR).toString();
assertEquals(error, OAuth20Constants.INVALID_REQUEST);
val errorDescription = mv.getModel().get(OAuth20Constants.ERROR_DESCRIPTION).toString();
assertEquals(errorDescription, "Invalid Request Description");
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20InvalidAuthorizationResponseBuilderTests method verifyRequestWithCallbackWithoutDescription.
@Test
public void verifyRequestWithCallbackWithoutDescription() {
val request = new MockHttpServletRequest();
request.addParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
request.addParameter(OAuth20Constants.REDIRECT_URI, "https://github.com/apereo/cas");
request.addParameter(OAuth20Constants.STATE, "abcdefgh");
request.addParameter(OAuth20Constants.RESPONSE_MODE, OAuth20ResponseModeTypes.FORM_POST.getType());
request.addParameter("ParameterWhichShouldNotComingBack", "notAtAll");
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
assertFalse(oauthInvalidAuthorizationBuilder.supports(context));
context.setRequestAttribute(OAuth20Constants.ERROR, OAuth20Constants.INVALID_REQUEST);
context.setRequestAttribute(OAuth20Constants.ERROR_WITH_CALLBACK, true);
assertTrue(oauthInvalidAuthorizationBuilder.supports(context));
val mv = oauthInvalidAuthorizationBuilder.build(context);
assertEquals(mv.getViewName(), CasWebflowConstants.VIEW_ID_POST_RESPONSE);
assertTrue(mv.getModel().containsKey("originalUrl"));
assertTrue(mv.getModel().containsKey("parameters"));
val originalUrl = mv.getModel().get("originalUrl");
assertEquals(originalUrl, "https://github.com/apereo/cas");
val parameters = (Map) mv.getModel().get("parameters");
assertTrue(parameters.containsKey(OAuth20Constants.ERROR));
assertFalse(parameters.containsKey(OAuth20Constants.ERROR_DESCRIPTION));
assertTrue(parameters.containsKey(OAuth20Constants.STATE));
assertEquals(parameters.get(OAuth20Constants.ERROR), OAuth20Constants.INVALID_REQUEST);
assertEquals(parameters.get(OAuth20Constants.STATE), "abcdefgh");
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20InvalidAuthorizationResponseBuilderTests method verifyRequestWithoutCallback.
@Test
public void verifyRequestWithoutCallback() {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
assertFalse(oauthInvalidAuthorizationBuilder.supports(context));
context.setRequestAttribute(OAuth20Constants.ERROR, OAuth20Constants.INVALID_REQUEST);
assertTrue(oauthInvalidAuthorizationBuilder.supports(context));
assertEquals(oauthInvalidAuthorizationBuilder.build(context).getViewName(), CasWebflowConstants.VIEW_ID_SERVICE_ERROR);
context.setRequestAttribute(OAuth20Constants.ERROR_WITH_CALLBACK, false);
assertEquals(oauthInvalidAuthorizationBuilder.build(context).getViewName(), CasWebflowConstants.VIEW_ID_SERVICE_ERROR);
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20RefreshTokenGrantTypeTokenRequestValidatorTests method verifyOperationClientSecretPost.
@Test
public void verifyOperationClientSecretPost() throws Exception {
val request = new MockHttpServletRequest();
val profile = new CommonProfile();
profile.setClientName(Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN);
profile.setId(RequestValidatorTestUtils.SUPPORTING_CLIENT_ID);
val session = request.getSession(true);
assertNotNull(session);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val response = new MockHttpServletResponse();
request.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.REFRESH_TOKEN.getType());
request.setParameter(OAuth20Constants.CLIENT_ID, RequestValidatorTestUtils.SUPPORTING_CLIENT_ID);
request.setParameter(OAuth20Constants.CLIENT_SECRET, RequestValidatorTestUtils.SHARED_SECRET);
request.setParameter(OAuth20Constants.REFRESH_TOKEN, SUPPORTING_TICKET);
assertTrue(validator.validate(new JEEContext(request, response)));
profile.setId(RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
request.setParameter(OAuth20Constants.CLIENT_ID, RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID);
request.setParameter(OAuth20Constants.CLIENT_SECRET, RequestValidatorTestUtils.SHARED_SECRET);
request.setParameter(OAuth20Constants.REFRESH_TOKEN, NON_SUPPORTING_TICKET);
assertFalse(validator.validate(new JEEContext(request, response)));
profile.setId(RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
request.setParameter(OAuth20Constants.CLIENT_ID, RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID);
request.setParameter(OAuth20Constants.CLIENT_SECRET, RequestValidatorTestUtils.SHARED_SECRET);
request.setParameter(OAuth20Constants.REFRESH_TOKEN, PROMISCUOUS_TICKET);
assertTrue(this.validator.validate(new JEEContext(request, response)));
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20RefreshTokenGrantTypeTokenRequestValidatorTests method verifyOperationClientSecretBasic.
@Test
public void verifyOperationClientSecretBasic() throws Exception {
val request = new MockHttpServletRequest();
val profile = new CommonProfile();
profile.setClientName(Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN);
profile.setId(RequestValidatorTestUtils.SUPPORTING_CLIENT_ID);
val session = request.getSession(true);
assertNotNull(session);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val response = new MockHttpServletResponse();
request.addHeader("Authorization", "Basic " + EncodingUtils.encodeBase64(RequestValidatorTestUtils.SUPPORTING_CLIENT_ID + ':' + RequestValidatorTestUtils.SHARED_SECRET));
request.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.REFRESH_TOKEN.getType());
request.setParameter(OAuth20Constants.REFRESH_TOKEN, SUPPORTING_TICKET);
assertTrue(this.validator.validate(new JEEContext(request, response)));
profile.setId(RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
request.removeHeader("Authorization");
request.addHeader("Authorization", "Basic " + EncodingUtils.encodeBase64(RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID + ':' + RequestValidatorTestUtils.SHARED_SECRET));
request.setParameter(OAuth20Constants.REFRESH_TOKEN, NON_SUPPORTING_TICKET);
assertFalse(validator.validate(new JEEContext(request, response)));
profile.setId(RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID);
session.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
request.removeHeader("Authorization");
request.addHeader("Authorization", "Basic " + EncodingUtils.encodeBase64(RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID + ':' + RequestValidatorTestUtils.SHARED_SECRET));
request.setParameter(OAuth20Constants.REFRESH_TOKEN, PROMISCUOUS_TICKET);
assertTrue(validator.validate(new JEEContext(request, response)));
}
Aggregations