本文整理汇总了Java中org.springframework.webflow.context.ExternalContextHolder类的典型用法代码示例。如果您正苦于以下问题:Java ExternalContextHolder类的具体用法?Java ExternalContextHolder怎么用?Java ExternalContextHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExternalContextHolder类属于org.springframework.webflow.context包,在下文中一共展示了ExternalContextHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Before
public void setUp() {
this.fbClient = new MockFacebookClient();
final Clients clients = new Clients(CALLBACK_URL, fbClient);
this.handler = new ClientAuthenticationHandler();
this.handler.setClients(clients);
final Credentials credentials = new OAuthCredentials(null, MockFacebookClient.CLIENT_NAME);
this.clientCredential = new ClientCredential(credentials);
ExternalContextHolder.setExternalContext(mock(ServletExternalContext.class));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:ClientAuthenticationHandlerTests.java
示例2: getHttpServletRequest
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* Gets the http servlet request from the current servlet context.
*
* @return the http servlet request
*/
public static HttpServletRequest getHttpServletRequest() {
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
if (servletExternalContext != null) {
return (HttpServletRequest) servletExternalContext.getNativeRequest();
} else {
return null;
}
}
示例3: getHttpServletResponse
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* Gets the http servlet response from the current servlet context.
*
* @return the http servlet response
*/
public static HttpServletResponse getHttpServletResponse() {
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
if (servletExternalContext != null) {
return (HttpServletResponse) servletExternalContext.getNativeResponse();
} else {
return null;
}
}
示例4: doAuthentication
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final ClientCredential clientCredentials = (ClientCredential) credential;
logger.debug("clientCredentials : {}", clientCredentials);
final Credentials credentials = clientCredentials.getCredentials();
final String clientName = credentials.getClientName();
logger.debug("clientName : {}", clientName);
// get client
final Client<Credentials, UserProfile> client = this.clients.findClient(clientName);
logger.debug("client : {}", client);
// web context
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();
final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();
final WebContext webContext = new J2EContext(request, response);
// get user profile
final UserProfile userProfile = client.getUserProfile(credentials, webContext);
logger.debug("userProfile : {}", userProfile);
if (userProfile != null) {
return createResult(clientCredentials, userProfile);
}
throw new FailedLoginException("Provider did not produce a user profile for: " + clientCredentials);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:30,代码来源:AbstractClientAuthenticationHandler.java
示例5: setUp
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Before
public void setUp() {
this.fbClient = new MockFacebookClient();
final Clients clients = new Clients(CALLBACK_URL, fbClient);
this.handler = new ClientAuthenticationHandler(clients);
final Credentials credentials = new OAuthCredentials(null, MockFacebookClient.CLIENT_NAME);
this.clientCredential = new ClientCredential(credentials);
ExternalContextHolder.setExternalContext(mock(ServletExternalContext.class));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:10,代码来源:ClientAuthenticationHandlerTests.java
示例6: setUp
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Before
public void setUp() {
this.fbClient = new FacebookClient();
final Clients clients = new Clients(CALLBACK_URL, fbClient);
this.handler = new ClientAuthenticationHandler("", mock(ServicesManager.class), null, clients);
this.handler.setTypedIdUsed(true);
final Credentials credentials = new OAuth20Credentials(null, fbClient.getName());
this.clientCredential = new ClientCredential(credentials);
ExternalContextHolder.setExternalContext(mock(ServletExternalContext.class));
}
示例7: getHttpServletRequest
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* Gets the http servlet request from the current servlet context.
*
* @return the http servlet request
*/
public static HttpServletRequest getHttpServletRequest() {
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
if (servletExternalContext != null) {
return (HttpServletRequest) servletExternalContext.getNativeRequest();
}
return null;
}
示例8: getHttpServletResponse
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* Gets the http servlet response from the current servlet context.
*
* @return the http servlet response
*/
public static HttpServletResponse getHttpServletResponse() {
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
if (servletExternalContext != null) {
return (HttpServletResponse) servletExternalContext.getNativeResponse();
}
return null;
}
示例9: doAuthentication
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final ClientCredential clientCredentials = (ClientCredential) credential;
logger.debug("clientCredentials : {}", clientCredentials);
final String clientName = clientCredentials.getCredentials().getClientName();
logger.debug("clientName : {}", clientName);
// get client
final Client<org.pac4j.core.credentials.Credentials, UserProfile> client = this.clients.findClient(clientName);
logger.debug("client : {}", client);
// web context
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();
final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();
final WebContext webContext = new J2EContext(request, response);
// get user profile
final UserProfile userProfile = client.getUserProfile(clientCredentials.getCredentials(), webContext);
logger.debug("userProfile : {}", userProfile);
if (userProfile != null && StringUtils.isNotBlank(userProfile.getTypedId())) {
clientCredentials.setUserProfile(userProfile);
return new HandlerResult(
this,
new BasicCredentialMetaData(credential),
new SimplePrincipal(userProfile.getTypedId(), userProfile.getAttributes()));
}
throw new FailedLoginException("Provider did not produce profile for " + clientCredentials);
}
示例10: doAuthentication
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final ClientCredential clientCredentials = (ClientCredential) credential;
final OpenIdCredentials openIdCredentials = clientCredentials.getOpenIdCredentials();
logger.debug("Client credentials : '{}'", clientCredentials);
final String clientName = openIdCredentials.getClientName();
logger.debug("Client name : '{}'", clientName);
// Web context
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();
final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();
final WebContext webContext = new J2EContext(request, response);
// Get user profile
final UserProfile userProfile = this.client.getUserProfile(openIdCredentials, webContext);
logger.debug("userProfile : {}", userProfile);
if (userProfile != null) {
final String id = userProfile.getId();
if (StringHelper.isNotEmpty(id)) {
openIdCredentials.setUserProfile(userProfile);
return new HandlerResult(this, clientCredentials, new SimplePrincipal(id, userProfile.getAttributes()));
}
}
throw new FailedLoginException("Provider did not produce profile for " + clientCredentials);
}
示例11: doAuthentication
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* {@InheritDoc}
*/
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final ClientCredential clientCredentials = (ClientCredential) credential;
final OpenIdCredentials openIdCredentials = clientCredentials.getOpenIdCredentials();
logger.debug("Client credentials : '{}'", clientCredentials);
final String clientName = openIdCredentials.getClientName();
logger.debug("Client name : '{}'", clientName);
// Web context
final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();
final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();
final WebContext webContext = new J2EContext(request, response);
// Get user profile
final UserProfile userProfile = this.client.getUserProfile(openIdCredentials, webContext);
logger.debug("userProfile : {}", userProfile);
if (userProfile != null) {
final String id = userProfile.getId();
if (StringHelper.isNotEmpty(id)) {
openIdCredentials.setUserProfile(userProfile);
return new HandlerResult(this, clientCredentials, new SimplePrincipal(id, userProfile.getAttributes()));
}
}
throw new FailedLoginException("Provider did not produce profile for " + clientCredentials);
}
示例12: doExecute
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
@Override
protected Event doExecute(final RequestContext context) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
final HttpSession session = request.getSession();
// web context
final WebContext webContext = new J2EContext(request, response);
// get client
final String clientName = request.getParameter(this.clients.getClientNameParameter());
logger.debug("clientName: {}", clientName);
// it's an authentication
if (StringUtils.isNotBlank(clientName)) {
// get client
final BaseClient<Credentials, CommonProfile> client =
(BaseClient<Credentials, CommonProfile>) this.clients
.findClient(clientName);
logger.debug("client: {}", client);
// Only supported protocols
final ClientType clientType = client.getClientType();
if (!SUPPORTED_PROTOCOLS.contains(clientType)) {
throw new TechnicalException("Only CAS, OAuth, OpenID and SAML protocols are supported: " + client);
}
// get credentials
final Credentials credentials;
try {
credentials = client.getCredentials(webContext);
logger.debug("credentials: {}", credentials);
} catch (final RequiresHttpAction e) {
logger.debug("requires http action: {}", e);
response.flushBuffer();
final ExternalContext externalContext = ExternalContextHolder.getExternalContext();
externalContext.recordResponseComplete();
return new Event(this, "stop");
}
// retrieve parameters from web session
final Service service = (Service) session.getAttribute(CasProtocolConstants.PARAMETER_SERVICE);
context.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, service);
logger.debug("retrieve service: {}", service);
if (service != null) {
request.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
}
restoreRequestAttribute(request, session, ThemeChangeInterceptor.DEFAULT_PARAM_NAME);
restoreRequestAttribute(request, session, LocaleChangeInterceptor.DEFAULT_PARAM_NAME);
restoreRequestAttribute(request, session, CasProtocolConstants.PARAMETER_METHOD);
// credentials not null -> try to authenticate
if (credentials != null) {
final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder(
this.authenticationSystemSupport.getPrincipalElectionStrategy());
final AuthenticationTransaction transaction = AuthenticationTransaction.wrap(new ClientCredential(credentials));
this.authenticationSystemSupport.getAuthenticationTransactionManager().handle(transaction, builder);
final AuthenticationContext authenticationContext = builder.build(service);
final TicketGrantingTicket tgt = this.centralAuthenticationService.createTicketGrantingTicket(authenticationContext);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
return success();
}
}
// no or aborted authentication : go to login page
prepareForLoginPage(context);
return error();
}
示例13: doExecute
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Event doExecute(final RequestContext context) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
final HttpSession session = request.getSession();
// web context
final WebContext webContext = new J2EContext(request, response);
// get client
final String clientName = request.getParameter(this.clients.getClientNameParameter());
logger.debug("clientName: {}", clientName);
// it's an authentication
if (StringUtils.isNotBlank(clientName)) {
// get client
final BaseClient<Credentials, CommonProfile> client =
(BaseClient<Credentials, CommonProfile>) this.clients
.findClient(clientName);
logger.debug("client: {}", client);
// Only supported protocols
final Mechanism mechanism = client.getMechanism();
if (!SUPPORTED_PROTOCOLS.contains(mechanism)) {
throw new TechnicalException("Only CAS, OAuth, OpenID and SAML protocols are supported: " + client);
}
// get credentials
final Credentials credentials;
try {
credentials = client.getCredentials(webContext);
logger.debug("credentials: {}", credentials);
} catch (final RequiresHttpAction e) {
logger.debug("requires http action: {}", e);
response.flushBuffer();
final ExternalContext externalContext = ExternalContextHolder.getExternalContext();
externalContext.recordResponseComplete();
return new Event(this, "stop");
}
// retrieve parameters from web session
final Service service = (Service) session.getAttribute(SERVICE);
context.getFlowScope().put(SERVICE, service);
logger.debug("retrieve service: {}", service);
if (service != null) {
request.setAttribute(SERVICE, service.getId());
}
restoreRequestAttribute(request, session, THEME);
restoreRequestAttribute(request, session, LOCALE);
restoreRequestAttribute(request, session, METHOD);
// credentials not null -> try to authenticate
if (credentials != null) {
final TicketGrantingTicket tgt =
this.centralAuthenticationService.createTicketGrantingTicket(new ClientCredential(credentials));
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
return success();
}
}
// no or aborted authentication : go to login page
prepareForLoginPage(context);
return error();
}
示例14: doExecute
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Event doExecute(final RequestContext context) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
final HttpSession session = request.getSession();
// web context
final WebContext webContext = new J2EContext(request, response);
// get client
//final String clientName = request.getParameter(this.clients.getClientNameParameter());
final String clientName = request.getParameter("state");
//logger.debug("clientName : {}", clientName);
logger.info("clientName : {}", clientName);
// it's an authentication
if (StringUtils.isNotBlank(clientName)) {
// get client
final BaseClient<Credentials, CommonProfile> client =
(BaseClient<Credentials, CommonProfile>) this.clients
.findClient(clientName);
logger.info("client : {}", client);
// Only supported protocols
final Mechanism mechanism = client.getMechanism();
logger.info("mechanism == " + mechanism.name());
if (!SUPPORTED_PROTOCOLS.contains(mechanism)) {
throw new TechnicalException("Only CAS, OAuth, OpenID and SAML protocols are supported: " + client);
}
// get credentials
final Credentials credentials;
try {
credentials = client.getCredentials(webContext);
logger.info("credentials : {}", credentials);
} catch (final RequiresHttpAction e) {
logger.info("requires http action : {}", e);
response.flushBuffer();
ExternalContext externalContext = ExternalContextHolder.getExternalContext();
externalContext.recordResponseComplete();
return new Event(this, "stop");
}
// retrieve parameters from web session
final Service service = (Service) session.getAttribute(SERVICE);
context.getFlowScope().put(SERVICE, service);
logger.info("retrieve service: {}", service);
if (service != null) {
request.setAttribute(SERVICE, service.getId());
}
restoreRequestAttribute(request, session, THEME);
restoreRequestAttribute(request, session, LOCALE);
restoreRequestAttribute(request, session, METHOD);
// credentials not null -> try to authenticate
if (credentials != null) {
logger.info("credentials is not null : {}", credentials);
WebUtils.putTicketGrantingTicketInRequestScope(context,
this.centralAuthenticationService.createTicketGrantingTicket(new ClientCredential(credentials)));
return success();
}
}
// no or aborted authentication : go to login page
prepareForLoginPage(context);
return error();
}
示例15: doExecute
import org.springframework.webflow.context.ExternalContextHolder; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Event doExecute(final RequestContext context) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
final HttpSession session = request.getSession();
// web context
final WebContext webContext = new J2EContext(request, response);
// get client
final String clientName = request.getParameter(this.clients.getClientNameParameter());
logger.debug("clientName : {}", clientName);
// it's an authentication
if (StringUtils.isNotBlank(clientName)) {
// get client
final BaseClient<Credentials, CommonProfile> client =
(BaseClient<Credentials, CommonProfile>) this.clients
.findClient(clientName);
logger.debug("client : {}", client);
// HTTP protocol not allowed
if (client.getProtocol() == Protocol.HTTP) {
throw new TechnicalException("HTTP protocol client not supported : " + client);
}
// get credentials
final Credentials credentials;
try {
credentials = client.getCredentials(webContext);
logger.debug("credentials : {}", credentials);
} catch (final RequiresHttpAction e) {
logger.info("requires http action : {}", e);
response.flushBuffer();
ExternalContext externalContext = ExternalContextHolder.getExternalContext();
externalContext.recordResponseComplete();
return new Event(this, "stop");
}
// retrieve parameters from web session
final Service service = (Service) session.getAttribute(SERVICE);
context.getFlowScope().put(SERVICE, service);
restoreRequestAttribute(request, session, THEME);
restoreRequestAttribute(request, session, LOCALE);
restoreRequestAttribute(request, session, METHOD);
// credentials not null -> try to authenticate
if (credentials != null) {
WebUtils.putTicketGrantingTicketInRequestScope(context,
this.centralAuthenticationService.createTicketGrantingTicket(new ClientCredential(credentials)));
return success();
}
}
// no or aborted authentication : go to login page
prepareForLoginPage(context);
return error();
}