本文整理汇总了Java中org.pac4j.core.context.WebContext.setSessionAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java WebContext.setSessionAttribute方法的具体用法?Java WebContext.setSessionAttribute怎么用?Java WebContext.setSessionAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pac4j.core.context.WebContext
的用法示例。
在下文中一共展示了WebContext.setSessionAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Override
public String get(final WebContext context) {
String token = (String) context.getSessionAttribute(Pac4jConstants.CSRF_TOKEN);
if (token == null) {
synchronized (this) {
token = (String) context.getSessionAttribute(Pac4jConstants.CSRF_TOKEN);
if (token == null) {
token = java.util.UUID.randomUUID().toString();
context.setSessionAttribute(Pac4jConstants.CSRF_TOKEN, token);
}
}
}
return token;
}
示例2: getCredentials
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
/**
* <p>Get the credentials from the web context. In some cases, a {@link HttpAction} may be thrown:</p>
* <ul>
* <li>if the <code>CasClient</code> receives a logout request, it returns a 200 HTTP status code</li>
* <li>for the <code>IndirectBasicAuthClient</code>, if no credentials are sent to the callback url, an unauthorized response (401 HTTP status
* code) is returned to request credentials through a popup.</li>
* </ul>
*
* @param context the current web context
* @return the credentials
* @throws HttpAction whether an additional HTTP action is required
*/
@Override
public final C getCredentials(final WebContext context) throws HttpAction {
init(context);
final C credentials = retrieveCredentials(context);
// no credentials -> save this authentication has already been tried and failed
if (credentials == null) {
context.setSessionAttribute(getName() + ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
} else {
cleanAttemptedAuthentication(context);
}
return credentials;
}
示例3: addStateAndNonceParameters
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
protected void addStateAndNonceParameters(final WebContext context, final Map<String, String> params) {
// Init state for CSRF mitigation
State state = new State();
params.put(OidcConfiguration.STATE, state.getValue());
context.setSessionAttribute(OidcConfiguration.STATE_SESSION_ATTRIBUTE, state);
// Init nonce for replay attack mitigation
if (configuration.isUseNonce()) {
Nonce nonce = new Nonce();
params.put(OidcConfiguration.NONCE, nonce.getValue());
context.setSessionAttribute(OidcConfiguration.NONCE_SESSION_ATTRIBUTE, nonce.getValue());
}
}
示例4: getStateParameter
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Override
protected String getStateParameter(final WebContext webContext) {
final String relayState = (String) webContext.getSessionAttribute(SAML_RELAY_STATE_ATTRIBUTE);
// clean from session after retrieving it
webContext.setSessionAttribute(SAML_RELAY_STATE_ATTRIBUTE, "");
return (relayState == null) ? computeFinalCallbackUrl(webContext) : relayState;
}
示例5: testRelayState
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Test
public void testRelayState() throws HttpAction {
final SAML2Client client = getClient();
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
context.setSessionAttribute(SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
final RedirectAction action = client.getRedirectAction(context);
assertTrue(action.getContent().contains("<input type=\"hidden\" name=\"RelayState\" value=\"relayState\"/>"));
}
示例6: testRelayState
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Test
public void testRelayState() throws Exception {
final SAML2Client client = getClient();
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
context.setSessionAttribute(SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
final RedirectAction action = client.getRedirectAction(context);
assertTrue(action.getLocation().contains("RelayState=relayState"));
}
示例7: retrieveAuthorizationUrl
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Override
protected String retrieveAuthorizationUrl(final WebContext context) throws HttpAction {
final OAuth1RequestToken requestToken = this.service.getRequestToken();
logger.debug("requestToken: {}", requestToken);
// save requestToken in user session
context.setSessionAttribute(getRequestTokenSessionAttributeName(), requestToken);
final String authorizationUrl = this.service.getAuthorizationUrl(requestToken);
logger.debug("authorizationUrl: {}", authorizationUrl);
return authorizationUrl;
}
示例8: buildOAuthConfig
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Override
protected OAuthConfig buildOAuthConfig(WebContext context) {
final String state = getStateParameter(context);
logger.debug("save sessionState: {}", state);
// the state is held in a specific context.
context.setSessionAttribute(getName() + STATE_PARAMETER, state);
return new OAuthConfig(this.getKey(), this.getSecret(), computeFinalCallbackUrl(context),
SignatureType.Header, getOAuthScope(), null, this.getConnectTimeout(), this.getReadTimeout(), hasOAuthGrantType() ? "authorization_code" : null, state, this.getResponseType());
}
示例9: retrieveRedirectAction
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
protected RedirectAction retrieveRedirectAction(final WebContext context) throws HttpAction {
final String userIdentifier = getUser(context);
CommonHelper.assertNotBlank("openIdUser", userIdentifier);
try {
// perform discovery on the user-supplied identifier
final List discoveries = this.consumerManager.discover(userIdentifier);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
final DiscoveryInformation discoveryInformation = this.consumerManager.associate(discoveries);
// save discovery information in session
context.setSessionAttribute(getDiscoveryInformationSessionAttributeName(), discoveryInformation);
// create authentication request to be sent to the OpenID provider
final AuthRequest authRequest = this.consumerManager.authenticate(discoveryInformation,
computeFinalCallbackUrl(context));
// create fetch request for attributes
final FetchRequest fetchRequest = getFetchRequest();
if (fetchRequest != null) {
authRequest.addExtension(fetchRequest);
}
final String redirectionUrl = authRequest.getDestinationUrl(true);
logger.debug("redirectionUrl: {}", redirectionUrl);
return RedirectAction.redirect(redirectionUrl);
} catch (final OpenIDException e) {
throw new TechnicalException("OpenID exception", e);
}
}
示例10: cleanRequestedUrl
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
private void cleanRequestedUrl(final WebContext context) {
context.setSessionAttribute(Pac4jConstants.REQUESTED_URL, "");
}
示例11: cleanAttemptedAuthentication
import org.pac4j.core.context.WebContext; //导入方法依赖的package包/类
private void cleanAttemptedAuthentication(final WebContext context) {
context.setSessionAttribute(getName() + ATTEMPTED_AUTHENTICATION_SUFFIX, "");
}