org.springframework.webflow.core.collection.MutableAttributeMap Java Examples

The following examples show how to use org.springframework.webflow.core.collection.MutableAttributeMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceThemeResolverTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyGetServiceThemeDoesNotExist() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setTheme("myTheme");
    r.setId(1000);
    r.setName("Test Service");
    r.setServiceId("myServiceId");

    this.servicesManager.save(r);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    final RequestContext ctx = mock(RequestContext.class);
    final MutableAttributeMap scope = new LocalAttributeMap();
    scope.put("service", TestUtils.getService(r.getServiceId()));
    when(ctx.getFlowScope()).thenReturn(scope);
    RequestContextHolder.setRequestContext(ctx);
    request.addHeader("User-Agent", "Mozilla");
    assertEquals("test", this.serviceThemeResolver.resolveThemeName(request));
}
 
Example #2
Source File: MultiFactorRequestContextUtils.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the principal id.
 *
 * @param context the context
 * @return the principal id
 */
public static Principal getMultiFactorPrimaryPrincipal(final RequestContext context) {
    if (context != null) {
        final FlowSession flowSession = context.getFlowExecutionContext().getActiveSession();
        final MutableAttributeMap map = flowSession.getScope();
        final MultiFactorCredentials creds = (MultiFactorCredentials) map.get(CAS_MFA_CREDENTIALS_ATTR_NAME);

        if (creds == null || creds.getPrincipal() == null) {
            throw new IllegalArgumentException("Cannot locate credential object in the flow session map. Credentials missing...");
        }
        final Principal principalId = creds.getPrincipal();
        LOGGER.debug("Determined principal name to use [{}] for authentication", principalId.getId());
        return principalId;
    }
    throw new IllegalArgumentException("Request context could not be retrieved from the webflow.");
}
 
Example #3
Source File: ClientActionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ClientAction.THEME, MY_THEME);
    mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE);
    mockRequest.setParameter(ClientAction.METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE));
    assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    assertTrue(((String) flowScope.get("FacebookClientUrl"))
            .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
                    + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
    assertEquals(MY_LOGIN_URL + "?" + Clients.DEFAULT_CLIENT_NAME_PARAMETER
            + "=TwitterClient&needs_client_redirection=true", flowScope.get("TwitterClientUrl"));
}
 
Example #4
Source File: ClientActionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyFinishAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");

    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute(ClientAction.THEME, MY_THEME);
    mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE);
    mockSession.setAttribute(ClientAction.METHOD, MY_METHOD);
    final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE);
    mockSession.setAttribute(ClientAction.SERVICE, service);
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final FacebookClient facebookClient = new MockFacebookClient();
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient);

    final TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TGT_ID, mock(Authentication.class), mock(ExpirationPolicy.class));
    final CentralAuthenticationService casImpl = mock(CentralAuthenticationService.class);
    when(casImpl.createTicketGrantingTicket(any(Credential.class))).thenReturn(tgt);
    final ClientAction action = new ClientAction(casImpl, clients);
    final Event event = action.execute(mockRequestContext);
    assertEquals("success", event.getId());
    assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME));
    assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE));
    assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD));
    assertEquals(MY_SERVICE, mockRequest.getAttribute(ClientAction.SERVICE));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final MutableAttributeMap requestScope = mockRequestContext.getRequestScope();
    assertEquals(service, flowScope.get(ClientAction.SERVICE));
    assertEquals(TGT_ID, flowScope.get(TGT_NAME));
    assertEquals(TGT_ID, requestScope.get(TGT_NAME));
}
 
Example #5
Source File: ClientActionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ClientAction.THEME, MY_THEME);
    mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE);
    mockRequest.setParameter(ClientAction.METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE));
    assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    assertTrue(((String) flowScope.get("FacebookClientUrl"))
            .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
                    + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
    assertEquals(MY_LOGIN_URL + "?" + Clients.DEFAULT_CLIENT_NAME_PARAMETER
            + "=TwitterClient&needs_client_redirection=true", flowScope.get("TwitterClientUrl"));
}
 
Example #6
Source File: ClientActionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testFinishAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");

    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute(ClientAction.THEME, MY_THEME);
    mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE);
    mockSession.setAttribute(ClientAction.METHOD, MY_METHOD);
    final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE);
    mockSession.setAttribute(ClientAction.SERVICE, service);
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final FacebookClient facebookClient = new MockFacebookClient();
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient);

    final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients);
    final Event event = action.execute(mockRequestContext);
    assertEquals("success", event.getId());
    assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME));
    assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE));
    assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    assertEquals(service, flowScope.get(ClientAction.SERVICE));
}
 
Example #7
Source File: AddSoRPersonFlowTests.java    From openregistry with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartFlow() {
    ReconciliationCriteria criteria = constructReconciliationCriteria(RUDYARD, KIPLING, null, EMAIL_ADDRESS, PHONE_NUMBER, new Date(0), OR_WEBAPP_IDENTIFIER);
    MutableAttributeMap input = new LocalAttributeMap();
    input.put("personSearch", criteria);
    ExternalContext context = new MockExternalContext();

    startFlow(context);
    assertCurrentStateEquals("addPerson");
}
 
Example #8
Source File: GenerateMultiFactorCredentialsActionTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    this.action = new GenerateMultiFactorCredentialsAction();

    final AuthenticationSupport support = mock(AuthenticationSupport.class);
    when(support.getAuthenticationFrom(TGT_ID)).thenReturn(this.authentication);
    this.action.setAuthenticationSupport(support);

    final MutableAttributeMap requestScope = mock(MutableAttributeMap.class);
    when(requestContext.getRequestScope()).thenReturn(requestScope);

    final MutableAttributeMap flowScope = mock(MutableAttributeMap.class);
    when(requestContext.getFlowScope()).thenReturn(flowScope);

    when(principal.getId()).thenReturn("user");
    when(authentication.getPrincipal()).thenReturn(this.principal);

    when(requestContext.getFlowExecutionContext()).thenReturn(this.flowExecutionContext);
    when(requestContext.getFlowExecutionContext().getActiveSession()).thenReturn(this.flowSession);
    when(requestContext.getActiveFlow()).thenReturn(this.flowDefinition);
    when(requestContext.getFlowExecutionContext().getActiveSession().getState()).thenReturn(this.stateDefinition);

    when(requestContext.getActiveFlow().getId()).thenReturn("loginWebflow");
    when(requestContext.getFlowExecutionContext().getActiveSession().getState().getId()).thenReturn("MFA");
    when(requestContext.getFlowExecutionContext().getActiveSession().getScope()).thenReturn(this.sessionFlowScope);

}
 
Example #9
Source File: ValidateInitialMultiFactorAuthenticationRequestActionTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    final AuthenticationSupport support = mock(AuthenticationSupport.class);
    when(support.getAuthenticationFrom(TGT_ID)).thenReturn(authentication);

    final SortedSet<AuthenticationMethod> validAuthenticationMethods =
            new TreeSet<>();
    validAuthenticationMethods.add(new AuthenticationMethod("sample_two_factor", 2));
    validAuthenticationMethods.add(new AuthenticationMethod("strong_two_factor", 4));

    final JsonBackedAuthenticationMethodConfigurationProvider loader =
            new JsonBackedAuthenticationMethodConfigurationProvider(validAuthenticationMethods);

    this.action = new ValidateInitialMultiFactorAuthenticationRequestAction(support,
            new OrderedMultiFactorMethodRankingStrategy(loader));

    mockFlowScope = mock(MutableAttributeMap.class);
    when(requestContext.getFlowScope()).thenReturn(mockFlowScope);
    when(requestContext.getConversationScope()).thenReturn(mockFlowScope);

    final ParameterMap requestParams = mock(ParameterMap.class);
    when(requestContext.getRequestParameters()).thenReturn(requestParams);

    /*when(requestContext.getConversationScope().get(MultiFactorAuthenticationTransactionContext.class.getSimpleName()))
            .thenReturn(mfaTx);*/

}
 
Example #10
Source File: InitiatingMultiFactorAuthenticationViaFormActionTests.java    From cas-mfa with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {

    MockitoAnnotations.initMocks(this);

    this.authViaFormAction.setCentralAuthenticationService(this.cas);
    this.authViaFormAction.setWarnCookieGenerator(this.cookieGenerator);

    final MutableAttributeMap flowScope = mock(MutableAttributeMap.class);

    when(ctx.getFlowScope()).thenReturn(flowScope);
    when(ctx.getRequestScope()).thenReturn(flowScope);
    when(ctx.getConversationScope()).thenReturn(flowScope);
    when(ctx.getMessageContext()).thenReturn(this.msgCtx);

    MultiFactorAuthenticationSupportingWebApplicationService svc = null;
    svc = mock(MultiFactorAuthenticationSupportingWebApplicationService.class);
    when(svc.getAuthenticationMethod()).thenReturn(AUTHN_METHOD);

    when(ctx.getFlowScope().get("service")).thenReturn(svc);
    when(ctx.getFlowScope().remove("loginTicket")).thenReturn(LOGIN_TICKET);

    when(ctx.getRequestScope().get("ticketGrantingTicketId")).thenReturn(TGT_ID);
    when(ctx.getFlowScope().get("ticketGrantingTicketId")).thenReturn(TGT_ID);
    when(ctx.getFlowScope().get("credential")).thenReturn(getCredentials());

    when(ctx.getRequestParameters()).thenReturn(mock(ParameterMap.class));
    when(ctx.getRequestParameters().get("lt")).thenReturn(LOGIN_TICKET);

    when(ctx.getConversationScope().get(MultiFactorAuthenticationTransactionContext.class.getSimpleName()))
            .thenReturn(new MultiFactorAuthenticationTransactionContext("test service"));

    when(manager.authenticate(any(Credential.class))).thenReturn(this.authentication);

    final SortedSet<AuthenticationMethod> validAuthenticationMethods =
            new TreeSet<>();
    validAuthenticationMethods.add(new AuthenticationMethod("sample_two_factor", 2));
    validAuthenticationMethods.add(new AuthenticationMethod("strong_two_factor", 4));

    final JsonBackedAuthenticationMethodConfigurationProvider loader =
            new JsonBackedAuthenticationMethodConfigurationProvider(validAuthenticationMethods);

    this.action = new InitiatingMultiFactorAuthenticationViaFormAction(multiFactorAuthenticationRequestResolver,
            authenticationSupport, verifier, authViaFormAction, new OrderedMultiFactorMethodRankingStrategy(loader),
            "https://sso.school.edu");

    this.action.setCentralAuthenticationService(this.cas);
    this.action.setWarnCookieGenerator(this.cookieGenerator);
    this.action.setMultiFactorAuthenticationManager(manager);
}
 
Example #11
Source File: WebUtils.java    From springboot-shiro-cas-mybatis with MIT License 2 votes vote down vote up
/**
 * Put ticket granting ticket into map that is either backed by the flow/request scope.
 * Will override the previous value and blank out the setting if value is null or empty.
 * @param map the map
 * @param ticketValue the ticket value
 */
private static void putTicketGrantingTicketIntoMap(final MutableAttributeMap map,
                                                   @NotNull final String ticketValue) {
    map.put("ticketGrantingTicketId", ticketValue);
}
 
Example #12
Source File: OIDCUtils.java    From shibboleth-oidc with Apache License 2.0 2 votes vote down vote up
/**
 * Put post authorization attributes into scope.
 *
 * @param attributes the attributes
 * @param context    the context
 */
public static void putPostAuthorizationAttributesIntoScope(final Map attributes, 
                                                           final MutableAttributeMap context) {
    context.put("postAuthorizationAttributes", attributes);
}
 
Example #13
Source File: OIDCUtils.java    From shibboleth-oidc with Apache License 2.0 2 votes vote down vote up
/**
 * Put authorization request into scope.
 *
 * @param authorizationRequest the authorization request
 * @param context              the context
 */
public static void putAuthorizationRequestIntoScope(final AuthorizationRequest authorizationRequest,
                                                    final MutableAttributeMap context) {
    context.put("authorizationRequest", authorizationRequest);
}
 
Example #14
Source File: OIDCUtils.java    From shibboleth-oidc with Apache License 2.0 2 votes vote down vote up
/**
 * Put oidc response into scope.
 *
 * @param response the response
 * @param context  the context
 */
public static void putOIDCResponseIntoScope(final OIDCResponse response, final MutableAttributeMap context) {
    context.put("oidcResponse", response);
}
 
Example #15
Source File: OIDCUtils.java    From shibboleth-oidc with Apache License 2.0 2 votes vote down vote up
/**
 * Put csrf into scope.
 *
 * @param csrf    the csrf
 * @param context the context
 */
public static void putCsrfIntoScope(final Object csrf, final MutableAttributeMap context) {
    context.put("csrf", csrf);
}