本文整理汇总了Java中org.pac4j.core.exception.RequiresHttpAction类的典型用法代码示例。如果您正苦于以下问题:Java RequiresHttpAction类的具体用法?Java RequiresHttpAction怎么用?Java RequiresHttpAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequiresHttpAction类属于org.pac4j.core.exception包,在下文中一共展示了RequiresHttpAction类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: commence
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response,
final AuthenticationException authException) throws IOException, ServletException {
logger.debug("client : {}", this.client);
final WebContext context = new J2EContext(request, response);
// Check if client is a web browser
try {
if (isBrowser(MediaType.parseMediaTypes(request.getHeader("Accept"))) && isHTMLinfo(request.getRequestURI())) {
this.client.redirect(context, true, false);
} else {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied");
}
} catch (final RequiresHttpAction e) {
logger.debug("extra HTTP action required : {}", e.getCode());
}
}
开发者ID:conwetlab,项目名称:Repository-RI,代码行数:18,代码来源:FiwareClientAuthenticationEntryPoint.java
示例2: shouldRedirectIfClientNameIsSet
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Test
public void shouldRedirectIfClientNameIsSet() throws RequiresHttpAction {
Session session = mock(Session.class);
when(session.getId()).thenReturn(UUID.randomUUID().toString());
Response response = mock(Response.class);
JaxrsWebContext webContext = mock(JaxrsWebContext.class);
when(webContext.getResponse()).thenReturn(response);
doNothing().when(basicClient).redirect(webContext, false, false);
doReturn(basicClient).when(filter).getClient(webContext);
doReturn(false).when(filter).isAuthenticated(session);
doReturn(session).when(filter).getSession(context, true);
doReturn(webContext).when(filter).getContext(context, session);
filter.filter(context);
verify(basicClient).redirect(webContext, false, false);
verify(webContext, atLeast(1)).setResponseHeader(eq(HttpHeaders.LOCATION), any(String.class));
verify(webContext).setResponseHeader(HttpHeaders.SET_COOKIE, new NewCookie(AuthenticationFilter.AUTH_COOKIE, session.getId(), "/", null, null, NewCookie.DEFAULT_MAX_AGE, false).toString());
verify(context).abortWith(response);
}
开发者ID:minnal,项目名称:minnal,代码行数:19,代码来源:AuthenticationFilterTest.java
示例3: shouldReturnOkIfClientNameIsSet
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Test
public void shouldReturnOkIfClientNameIsSet() throws RequiresHttpAction {
Session session = mock(Session.class);
Response response = mock(Response.class);
JaxrsWebContext webContext = mock(JaxrsWebContext.class);
when(webContext.getResponse()).thenReturn(response);
doReturn(session).when(filter).getSession(context, true);
doReturn(webContext).when(filter).getContext(context, session);
doReturn(client).when(filter).getClient(session);
Credentials credentials = mock(Credentials.class);
HttpProfile profile = mock(HttpProfile.class);
when(client.getCredentials(webContext)).thenReturn(credentials);
when(client.getUserProfile(credentials, webContext)).thenReturn(profile);
filter.filter(context);
verify(session).addAttribute(AuthenticationFilter.PRINCIPAL, profile);
verify(session).addAttribute(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "client1");
verify(sessionStore).save(session);
verify(webContext).setResponseStatus(Response.Status.OK.getStatusCode());
verify(listener).authSuccess(session, profile);
verify(context).abortWith(response);
}
开发者ID:minnal,项目名称:minnal,代码行数:22,代码来源:CallbackFilterTest.java
示例4: callback
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
public Result callback(Context context , @Request HttpServletRequest request) {
NinjaWebContext nwContext = new NinjaWebContext(context);
Client client = clientsFactory.build().findClient(nwContext);
logger.debug("client : {}" , client);
Credentials credentials;
try {
credentials = client.getCredentials(nwContext);
} catch (RequiresHttpAction requiresHttpAction) {
logger.debug("extra HTTP action required : {}" , requiresHttpAction);
return nwContext.getResult();
}
logger.debug("credentials : {}" , credentials);
CommonProfile profile = (CommonProfile) client.getUserProfile(credentials);
logger.debug("profile : {}", profile);
if (profile != null) {
// only save profile when it's not null
userUtils.setProfile(context , profile);
}
String requestedUrl = (String) nwContext.getSessionAttribute(Pac4jFileter.ORIGINAL_REQUESTED_URL);
logger.debug("requestedUrl : {}", requestedUrl);
if (CommonHelper.isNotBlank(requestedUrl)) {
return Results.redirect(requestedUrl);
} else {
return Results.redirect(this.defaultUrl);
}
}
开发者ID:makotan,项目名称:ninja-pac4j,代码行数:30,代码来源:CallbackController.java
示例5: filter
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext request) {
Session session = getSession(request, true);
request.setProperty(SESSION, session);
if (isWhiteListed(request)) {
logger.debug("Request path {} is in whitelisted set of urls. Skipping authentication", request.getUriInfo());
return;
}
if (isAuthenticated(session)) {
logger.debug("Session is already authenticated. Skipping authentication");
return;
}
JaxrsWebContext context = getContext(request, session);
Client client = getClient(context);
if (client != null) {
session.addAttribute(Clients.DEFAULT_CLIENT_NAME_PARAMETER, client.getName());
getConfiguration().getSessionStore().save(session);
try {
client.redirect(context, false, false);
} catch (RequiresHttpAction e) {
logger.error("Failed while redirecting the request", e);
context.setResponseStatus(e.getCode());
}
} else {
context.setResponseStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}
context.setResponseHeader(HttpHeaders.SET_COOKIE, createSessionCookie(session).toString());
request.abortWith(context.getResponse());
}
开发者ID:minnal,项目名称:minnal,代码行数:34,代码来源:AuthenticationFilter.java
示例6: filter
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext request) {
URI uri = URI.create(getClients().getCallbackUrl());
if (! HttpUtil.structureUrl(request.getUriInfo().getPath()).equalsIgnoreCase(uri.getPath())) {
logger.debug("Request path {} doesn't match callback url. Skipping", request.getUriInfo().getPath());
return;
}
Session session = getSession(request, true);
JaxrsWebContext context = getContext(request, session);
Client client = getClient(session);
if (client == null) {
client = getClient(context);
}
if (client == null) {
context.setResponseStatus(422);
if (listener != null) {
listener.authFailed(session);
}
} else {
try {
Credentials credentials = client.getCredentials(context);
UserProfile userProfile = client.getUserProfile(credentials, context);
session.addAttribute(Clients.DEFAULT_CLIENT_NAME_PARAMETER, client.getName());
session.addAttribute(PRINCIPAL, userProfile);
if (listener != null) {
listener.authSuccess(session, userProfile);
}
getConfiguration().getSessionStore().save(session);
context.setResponseStatus(Response.Status.OK.getStatusCode());
} catch (RequiresHttpAction e) {
context.setResponseStatus(e.getCode());
if (listener != null) {
listener.authFailed(session);
}
}
}
request.abortWith(context.getResponse());
}
开发者ID:minnal,项目名称:minnal,代码行数:40,代码来源:CallbackFilter.java
示例7: shouldSetClientNameParamInSessionIfNotAuthenticated
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的package包/类
@Test
public void shouldSetClientNameParamInSessionIfNotAuthenticated() throws RequiresHttpAction {
Session session = mock(Session.class);
Response response = mock(Response.class);
JaxrsWebContext webContext = mock(JaxrsWebContext.class);
when(webContext.getResponse()).thenReturn(response);
doReturn(basicClient).when(filter).getClient(webContext);
doReturn(false).when(filter).isAuthenticated(session);
doReturn(session).when(filter).getSession(context, true);
doReturn(webContext).when(filter).getContext(context, session);
filter.filter(context);
verify(session).addAttribute(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "client1");
verify(sessionStore).save(session);
}
开发者ID:minnal,项目名称:minnal,代码行数:15,代码来源:AuthenticationFilterTest.java
示例8: doExecute
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的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();
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:70,代码来源:ClientAction.java
示例9: doExecute
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的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();
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:68,代码来源:ClientAction.java
示例10: doExecute
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的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();
}
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:71,代码来源:ClientAction.java
示例11: doExecute
import org.pac4j.core.exception.RequiresHttpAction; //导入依赖的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();
}
开发者ID:kevin3061,项目名称:cas-4.0.1,代码行数:62,代码来源:ClientAction.java
注:本文中的org.pac4j.core.exception.RequiresHttpAction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论