Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.TestingAuthenticationToken


    }

    @Test
    public void testOperationWhenPrincipalIsNull() throws JspException {
        SecurityContextHolder.getContext().setAuthentication(
                new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES ));

        authenticationTag.setProperty("principal");
        assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
        assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
    }
View Full Code Here


        }
    }

    @Test
    public void htmlEscapingIsUsedByDefault() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
        authenticationTag.setProperty("name");
        authenticationTag.doStartTag();
        authenticationTag.doEndTag();
        assertEquals("&lt;&gt;&amp;&#32;", authenticationTag.getLastMessage());
    }
View Full Code Here

        assertEquals("&lt;&gt;&amp;&#32;", authenticationTag.getLastMessage());
    }

    @Test
    public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
        authenticationTag.setProperty("name");
        authenticationTag.setHtmlEscape("false");
        authenticationTag.doStartTag();
        authenticationTag.doEndTag();
        assertEquals("<>& ", authenticationTag.getLastMessage());
View Full Code Here

     * abstract parent enforces that logic, which is extensively tested separately.
     */
    @Test
    public void testSuccessfulInvocation() throws Throwable {
        // Setup a Context
        Authentication token = new TestingAuthenticationToken("Test", "Password", "NOT_USED");
        SecurityContextHolder.getContext().setAuthentication(token);

        FilterInvocation fi = createinvocation();

        when(ods.getAttributes(fi)).thenReturn(SecurityConfig.createList("MOCK_OK"));
View Full Code Here

        verify(publisher, never()).publishEvent(any(AuthorizedEvent.class));
    }

    @Test
    public void afterInvocationIsNotInvokedIfExceptionThrown() throws Exception {
        Authentication token = new TestingAuthenticationToken("Test", "Password", "NOT_USED");
        SecurityContextHolder.getContext().setAuthentication(token);

        FilterInvocation fi = createinvocation();
        FilterChain chain = fi.getChain();
View Full Code Here

    // SEC-1967
    @Test
    @SuppressWarnings("unchecked")
    public void finallyInvocationIsInvokedIfExceptionThrown() throws Exception {
        SecurityContext ctx = SecurityContextHolder.getContext();
        Authentication token = new TestingAuthenticationToken("Test", "Password", "NOT_USED");
        token.setAuthenticated(true);
        ctx.setAuthentication(token);

        RunAsManager runAsManager = mock(RunAsManager.class);
        when(runAsManager.buildRunAs(eq(token), any(), anyCollection())).thenReturn(new RunAsUserToken("key", "someone", "creds", token.getAuthorities(), token.getClass()));
        interceptor.setRunAsManager(runAsManager);

        FilterInvocation fi = createinvocation();
        FilterChain chain = fi.getChain();
View Full Code Here

     * SEC-655
     */
    @Test
    @Transactional
    public void childrenAreClearedFromCacheWhenParentIsUpdated() throws Exception {
        Authentication auth = new TestingAuthenticationToken("ben", "ignored","ROLE_ADMINISTRATOR");
        auth.setAuthenticated(true);
        SecurityContextHolder.getContext().setAuthentication(auth);

        ObjectIdentity parentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(104));
        ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(105));

View Full Code Here

     * SEC-655
     */
    @Test
    @Transactional
    public void childrenAreClearedFromCacheWhenParentisUpdated2() throws Exception {
        Authentication auth = new TestingAuthenticationToken("system", "secret","ROLE_IGNORED");
        SecurityContextHolder.getContext().setAuthentication(auth);
        ObjectIdentityImpl rootObject = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(1));

        MutableAcl parent = jdbcMutableAclService.createAcl(rootObject);
        MutableAcl child = jdbcMutableAclService.createAcl(new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)));
View Full Code Here

    }

    @Test
    @Transactional
    public void cumulativePermissions() {
       Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_ADMINISTRATOR");
       auth.setAuthenticated(true);
       SecurityContextHolder.getContext().setAuthentication(auth);

       ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(110));
       MutableAcl topParent = jdbcMutableAclService.createAcl(topParentOid);
View Full Code Here

        getRoot().getAuthentication();
    }

    @Test
    public void getRootObjectSecurityContextHolderAuthentication() {
        TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
        SecurityContextHolder.getContext().setAuthentication(authentication);

        assertThat(getRoot().getAuthentication()).isSameAs(authentication);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.TestingAuthenticationToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.