本文整理汇总了Java中org.pac4j.core.exception.HttpAction类的典型用法代码示例。如果您正苦于以下问题:Java HttpAction类的具体用法?Java HttpAction怎么用?Java HttpAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpAction类属于org.pac4j.core.exception包,在下文中一共展示了HttpAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAuthorized
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
public boolean isAuthorized(final WebContext context, final List<CommonProfile> profiles) throws HttpAction {
final String url = context.getFullRequestURL().toLowerCase();
if (!url.endsWith(".css")
&& !url.endsWith(".js")
&& !url.endsWith(".png")
&& !url.endsWith(".jpg")
&& !url.endsWith(".ico")
&& !url.endsWith(".jpeg")
&& !url.endsWith(".bmp")
&& !url.endsWith(".gif")) {
context.setResponseHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
context.setResponseHeader("Pragma", "no-cache");
context.setResponseHeader("Expires", "0");
}
return true;
}
示例2: getUserProfile
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
public final U getUserProfile(final C credentials, final WebContext context) throws HttpAction {
init(context);
logger.debug("credentials : {}", credentials);
if (credentials == null) {
return null;
}
final U profile = retrieveUserProfile(credentials, context);
if (profile != null) {
profile.setClientName(getName());
if (this.authorizationGenerators != null) {
for (AuthorizationGenerator<U> authorizationGenerator : this.authorizationGenerators) {
authorizationGenerator.generate(profile);
}
}
}
return profile;
}
示例3: testOk
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void testOk() throws HttpAction {
final OAuth10Credentials credentials = (OAuth10Credentials) getClient()
.getCredentials(MockWebContext
.create()
.addRequestParameter(BaseOAuth10Client.OAUTH_VERIFIER, VERIFIER)
.addRequestParameter(BaseOAuth10Client.OAUTH_TOKEN, TOKEN)
.addSessionAttribute(getClient().getName() + "#" + BaseOAuth10Client.REQUEST_TOKEN,
new OAuth1RequestToken(TOKEN, SECRET)));
assertNotNull(credentials);
assertEquals(TOKEN, credentials.getToken());
assertEquals(VERIFIER, credentials.getVerifier());
final OAuth1RequestToken tokenRequest = (OAuth1RequestToken) credentials.getRequestToken();
assertEquals(TOKEN, tokenRequest.getToken());
assertEquals(SECRET, tokenRequest.getTokenSecret());
}
示例4: computeRedirectionToServerIfNecessary
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
private void computeRedirectionToServerIfNecessary(final WebContext context) throws HttpAction {
final String relayStateValue = context.getRequestParameter(CasConfiguration.RELAY_STATE_PARAMETER);
// if we have a state value -> redirect to the CAS server to continue the logout process
if (CommonUtils.isNotBlank(relayStateValue)) {
final StringBuilder buffer = new StringBuilder();
buffer.append(configuration.getPrefixUrl());
if (!configuration.getPrefixUrl().endsWith("/")) {
buffer.append("/");
}
buffer.append("logout?_eventId=next&");
buffer.append(CasConfiguration.RELAY_STATE_PARAMETER);
buffer.append("=");
buffer.append(CommonUtils.urlEncode(relayStateValue));
final String redirectUrl = buffer.toString();
logger.debug("Redirection url to the CAS server: {}", redirectUrl);
throw HttpAction.redirect("Force redirect to CAS server for front channel logout", context, redirectUrl);
}
}
示例5: testFullAuthentication
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void testFullAuthentication() throws HttpAction {
// luminous-smoke1
final StormpathAuthenticator authenticator = new StormpathAuthenticator("77NW47MHGJV5DA8R5UA5YORE0",
"nPCDRYPPxhBNpq1HT9Gr85hB7fCACQXSHx0aCuG6D/Q", "2MahZGmC0Rcl7gYkVIea94");
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("leleuj", "Pac4jtest", CLIENT_NAME);
authenticator.validate(credentials, null);
final StormpathProfile profile = (StormpathProfile) credentials.getUserProfile();
assertNotNull(profile);
assertEquals("leleuj", profile.getId());
assertEquals("LELEU", profile.getFamilyName());
assertEquals("Jerome", profile.getFirstName());
assertEquals("Jr", profile.getMiddleName());
final GroupList groups = profile.getGroups();
assertEquals("https://api.stormpath.com/v1/accounts/33t9mYagXIJyddNMZV5489/groups", groups.getHref());
final GroupMembershipList groupMemberships = profile.getGroupMemberships();
assertEquals("https://api.stormpath.com/v1/accounts/33t9mYagXIJyddNMZV5489/groupMemberships", groupMemberships.getHref());
assertEquals("[email protected]", profile.getEmail());
}
示例6: extractUserProfile
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
protected FoursquareProfile extractUserProfile(String body) throws HttpAction {
FoursquareProfile profile = new FoursquareProfile();
JsonNode json = JsonHelper.getFirstNode(body);
if (json == null) {
return profile;
}
JsonNode response = (JsonNode) JsonHelper.getElement(json, "response");
if (response == null) {
return profile;
}
JsonNode user = (JsonNode) JsonHelper.getElement(response, "user");
if (user != null) {
profile.setId(JsonHelper.getElement(user, "id"));
for (final String attribute : profile.getAttributesDefinition().getPrimaryAttributes()) {
profile.addAttribute(attribute, JsonHelper.getElement(user, attribute));
}
}
return profile;
}
示例7: retrieveCredentials
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
/**
* Retrieve the credentials.
*
* @param context the web context
* @return the credentials
* @throws HttpAction whether an additional HTTP action is required
*/
protected CompletableFuture<C> retrieveCredentials(final AsyncWebContext context) throws HttpAction {
return this.credentialsExtractor.extract(context)
.thenCompose(creds -> {
return Optional.ofNullable(creds)
.map(c -> this.authenticator.validate(creds, context).thenApply(v -> creds))
.orElse(CompletableFuture.completedFuture(creds)); // The orElse leaves any null returns
})
// Now translate a CredentialsException to null
.handle(ExceptionSoftener.softenBiFunction((creds, throwable) -> {
// throwable being non-null means creds will be null, so we can make this check here
logger.info("In handle call");
if (throwable == null || throwable instanceof CredentialsException) {
return creds;
} else {
throw throwable;
}
}));
}
示例8: retrieveRedirectAction
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
protected RedirectAction retrieveRedirectAction(final WebContext wc) throws HttpAction {
final SAML2MessageContext context = this.contextProvider.buildContext(wc);
final String relayState = getStateParameter(wc);
final AuthnRequest authnRequest = this.saml2ObjectBuilder.build(context);
this.profileHandler.send(context, authnRequest, relayState);
final Pac4jSAMLResponse adapter = context.getProfileRequestContextOutboundMessageTransportResponse();
if (this.configuration.getDestinationBindingType().equalsIgnoreCase(SAMLConstants.SAML2_POST_BINDING_URI)) {
final String content = adapter.getOutgoingContent();
return RedirectAction.success(content);
}
final String location = adapter.getRedirectUrl();
return RedirectAction.redirect(location);
}
示例9: firstProfileNoResultSecondProfileResult
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void firstProfileNoResultSecondProfileResult() {
when(firstProfile.getClientName()).thenReturn("client1");
when(secondProfile.getClientName()).thenReturn("client1");
when(clients.findClient(eq("client1"))).thenReturn(client);
when(client.getLogoutAction(any(AsyncWebContext.class), eq(firstProfile), anyString())).thenReturn(null);
when(client.getLogoutAction(any(AsyncWebContext.class), eq(secondProfile), anyString())).thenReturn(RedirectAction.redirect(LOGOUT_URL_2));
final HttpAction centralLogoutAction = CENTRAL_LOGOUT.getCentralLogoutAction(clients, Arrays.asList(firstProfile, secondProfile), null, webContext)
.map(o -> o.get())
.orElse(null);
assertThat(centralLogoutAction, is(notNullValue()));
assertThat(centralLogoutAction.getCode(), is(HttpConstants.TEMP_REDIRECT));
assertThat(status.get(), is(HttpConstants.TEMP_REDIRECT));
assertThat(responseHeaders.get(HttpConstants.LOCATION_HEADER), is(LOGOUT_URL_2));
}
示例10: testReturnNewProfile
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void testReturnNewProfile() throws HttpAction {
final CommonProfile profile = new CommonProfile();
profile.setId(ID);
profile.addAttribute(KEY, VALUE);
profile.setRemembered(false);
profile.addRole(NAME);
profile.addPermission(VALUE);
profile.setClientName(CLIENT_NAME);
final Credentials credentials = new TokenCredentials(TOKEN, CLIENT_NAME);
credentials.setUserProfile(profile);
final AuthenticatorProfileCreator creator = new AuthenticatorProfileCreator();
creator.setProfileFactory(MyCommonProfile::new);
final CommonProfile profile2 = creator.create(credentials, null);
assertTrue(profile2 instanceof MyCommonProfile);
assertEquals(profile.getId(), profile2.getId());
assertEquals(profile.getAttributes(), profile2.getAttributes());
assertEquals(profile.getRoles(), profile2.getRoles());
assertEquals(profile.getPermissions(), profile2.getPermissions());
assertEquals(profile.isRemembered(), profile2.isRemembered());
assertEquals(profile.getClientName(), profile2.getClientName());
}
示例11: validate
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
public void validate(final T credentials, final WebContext context) throws HttpAction {
init(context);
try {
final CommonProfile profile = this.cache.get(credentials, () -> {
logger.debug("Delegating authentication to {}...", delegate);
delegate.validate(credentials, context);
return credentials.getUserProfile();
});
credentials.setUserProfile(profile);
logger.debug("Found cached credential. Using cached profile {}...", profile);
} catch (Exception e) {
throw new CredentialsException(e);
}
}
示例12: testPlainJwtWithSignatureConfigurations
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test(expected = CredentialsException.class)
public void testPlainJwtWithSignatureConfigurations() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
assertToken(profile, token);
}
示例13: retrieveUserProfile
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Override
protected GaeUserServiceProfile retrieveUserProfile(GaeUserCredentials credentials, WebContext context) throws HttpAction {
User user = credentials.getUser();
if (user != null) {
GaeUserServiceProfile gaeUserProfile = new GaeUserServiceProfile();
gaeUserProfile.setId(user.getEmail());
gaeUserProfile.addAttribute(GaeUserServiceAttributesDefinition.EMAIL, user.getEmail());
gaeUserProfile.addAttribute(GaeUserServiceAttributesDefinition.DISPLAYNAME, user.getNickname());
if (service.isUserAdmin()) {
gaeUserProfile.addRole(GaeUserServiceProfile.PAC4J_GAE_GLOBAL_ADMIN_ROLE);
}
return gaeUserProfile;
}
return null;
}
示例14: testNoCode
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void testNoCode() throws HttpAction {
try {
getClient().getCredentials(MockWebContext.create());
fail("should not get credentials");
} catch (final TechnicalException e) {
assertEquals("No credential found", e.getMessage());
}
}
示例15: testGetCredentialsMissingSemiColon
import org.pac4j.core.exception.HttpAction; //导入依赖的package包/类
@Test
public void testGetCredentialsMissingSemiColon() throws HttpAction, UnsupportedEncodingException {
final IndirectBasicAuthClient basicAuthClient = getBasicAuthClient();
final MockWebContext context = getContextWithAuthorizationHeader(
"Basic " + Base64.getEncoder().encodeToString("fake".getBytes(HttpConstants.UTF8_ENCODING)));
verifyGetCredentialsFailsWithAuthenticationRequired(basicAuthClient, context);
}