Package org.springframework.security

Examples of org.springframework.security.Authentication


      final String newPassword, final boolean justRemove) {

    final SecurityContext securityContext = SecurityContextHolder.getContext();
    if(securityContext == null) return;

    final Authentication authentication = securityContext.getAuthentication();
    if(authentication == null) return;

    final Object principal = authentication.getPrincipal();
    if(principal instanceof User == false) return;
    final User user = (User) authentication.getPrincipal();

    if(user.getUsername().equals(originalUsername)) {
      if(userCache != null) {
        userCache.removeUserFromCache(originalUsername);
      }
      if(justRemove) {
        SecurityContextHolder.clearContext();
      }
      else {
        final UsernamePasswordAuthenticationToken token =
          new UsernamePasswordAuthenticationToken(newUsername, newPassword);
        token.setDetails(authentication.getDetails());
        SecurityContextHolder.getContext().setAuthentication(token);
      }
      log.info((justRemove ? "Removed" : "Reset") + " security context for user: " + originalUsername);
    }
View Full Code Here


     * @param authentication token to use
     * @param exceptionType Type of exception that should be thrown
     */
    private void doOneFailed(Authentication authentication, Class exceptionType) {
        ApplicationSecurityManager asm = (ApplicationSecurityManager)ApplicationServicesLocator.services().getService(ApplicationSecurityManager.class);
        Authentication current = asm.getAuthentication();

        eventCounter.resetCounters();
        try {
            asm.doLogin( authentication );
            fail( exceptionType.getName() + " should have been thrown" );
View Full Code Here

     * @throws SpringSecurityException If the authentication attempt fails
     */
    public Authentication doLogin(Authentication authentication) {
        final ApplicationContext appCtx = Application.instance().getApplicationContext();

        Authentication result = null;

        try {
            result = getAuthenticationManager().authenticate( authentication );
        } catch( SpringSecurityException e ) {
            logger.info( "authentication failed: " + e.getMessage() );
View Full Code Here

     * @return true if the user has the role requested
     */
    public boolean isUserInRole(String role) {
        boolean inRole = false;

        Authentication authentication = getAuthentication();
        if( authentication != null ) {
            GrantedAuthority[] authorities = authentication.getAuthorities();
            for( int i = 0; i < authorities.length; i++ ) {
                if( role.equals( authorities[i].getAuthority() ) ) {
                    inRole = true;
                    break;
                }
View Full Code Here

     * {@link AuthenticationEvent} followed by a {@link LogoutEvent}.
     * @return Authentication token that was in place prior to the logout.
     * @see org.springframework.richclient.security.ApplicationSecurityManager#doLogout()
     */
    public Authentication doLogout() {
        Authentication existing = getAuthentication();

        // Make the Authentication object null if a SecureContext exists
        SecurityContextHolder.getContext().setAuthentication( null );
        setAuthentication( null );

View Full Code Here

        assertFalse( "Object should not be authorized", cmdWrite.isAuthorized() );
        assertFalse( "Object should not be authorized", cmdAdmin.isAuthorized() );
        assertFalse( "Object should not be authorized", cmdAdminAlias.isAuthorized() );

        // Now login with ROLE_WRITE
        Authentication auth = TestAuthenticationManager.makeAuthentication( "test", "test", "ROLE_WRITE" );
        securityManager.doLogin( auth );

        assertTrue( "Object should be authorized", cmdWrite.isAuthorized() );
        assertFalse( "Object should not be authorized", cmdAdmin.isAuthorized() );
        assertFalse( "Object should not be authorized", cmdAdminAlias.isAuthorized() );
View Full Code Here

        // Try to enable them, should not happen
        cmdWrite.setEnabled( true );
        assertFalse( "Object should not be enabled", cmdWrite.isEnabled() );

        // Now authorize it
        Authentication auth = TestAuthenticationManager.makeAuthentication( "test", "test", "ROLE_WRITE" );
        securityManager.doLogin( auth );

        assertTrue( "Object should be authorized", cmdWrite.isAuthorized() );
        assertTrue( "Object should be enabled", cmdWrite.isEnabled() );
View Full Code Here

        controller.addControlledObject( a1 );
        assertFalse( "Object should not be authorized", a1.isAuthorized() );

        // Now set the authentication token so that it contains one of these roles
        Authentication auth = new TestingAuthenticationToken( "USER1", "FOO",
            new GrantedAuthority[] { new GrantedAuthorityImpl( "ROLE_1" ) } );
        controller.setAuthenticationToken( auth );

        assertTrue( "Object should be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 2 );
View Full Code Here

            if (userAttributes != null)
            {
                setUserAttributes(userAttributes);
            }
        }
        Authentication auth = (Authentication) event.getSource();
        propertyChangeSupport.firePropertyChange(USER, null, auth);
    }
View Full Code Here

     *            the logoutEvent that triggered this handler.
     */
    protected void handleLogoutEvent(LogoutEvent event)
    {
        clearUser();
        Authentication auth = (Authentication) event.getSource();
        propertyChangeSupport.firePropertyChange(USER, auth, null);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.Authentication

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.