Package org.acegisecurity

Examples of org.acegisecurity.Authentication


    protected DefaultTransaction getDatastoreTransaction(TransactionType request)
        throws IOException {
        DefaultTransaction transaction = new DefaultTransaction();
        // use handle as the log messages
        String username = "anonymous";
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if(authentication != null) {
            Object principal = authentication.getPrincipal();
            if(principal instanceof UserDetails) {
                username = ((UserDetails) principal).getUsername();
            }
        }
        transaction.putProperty(VersionedPostgisDataStore.AUTHOR, username);
View Full Code Here


    public static GeoServerSession get() {
        return (GeoServerSession)Session.get();
    }

    public Authentication getAuthentication(){
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null &&
                auth.getAuthorities().length == 1 &&
                "ROLE_ANONYMOUS".equals(auth.getAuthorities()[0].getAuthority())
           ) return null;

        return auth;
    }
View Full Code Here

public  class Login  extends ActionSupport implements SessionAware{

  private Map session;
    public String execute() throws Exception {
        String returnStr;
         Authentication authentication =  SecurityContextHolder.getContext().getAuthentication();
         if(authentication!=null){
           GrantedAuthority[] ga= authentication.getAuthorities();
           getSession().put(SessionVars.USER_ROLE, ga[0]);
           if(ga[0].equals(Roles.ADMIN.name()))
             returnStr = "adminLoggedIn";
           else if(ga[0].equals(Roles.BUYER.name()))
             returnStr = "buyerLoggedIn";
View Full Code Here

    DBCredentials dbCredentials = new DBCredentials();
    dbCredentials.preparaDb();
    DBRoles dbRoles = new DBRoles();
    dbRoles.preparaDb();

    Authentication authentication = new UsernamePasswordAuthenticationToken(
        "max", "max");
    Authentication authenticated = _dao.authenticate(authentication);
    assertNotNull(authenticated);
    GrantedAuthority[] authorities = authenticated.getAuthorities();
    assertNotNull(authorities);
    assertEquals(1, authorities.length);
    assertEquals(Constant.ROLE_ADMIN, authorities[0].getAuthority());

    dbRoles.pulisciDb();
View Full Code Here

    DBCredentials dbCredentials = new DBCredentials();
    dbCredentials.preparaDb();
    DBRoles dbRoles = new DBRoles();
    dbRoles.preparaDb();

    Authentication authentication = new UsernamePasswordAuthenticationToken(
        "pippo", "pippo");
    Authentication authenticated = _dao.authenticate(authentication);
    assertNotNull(authenticated);
    GrantedAuthority[] authorities = authenticated.getAuthorities();
    assertNotNull(authorities);
    assertEquals(1, authorities.length);
    assertEquals(Constant.ROLE_USER, authorities[0].getAuthority());

    dbRoles.pulisciDb();
View Full Code Here

    DBCredentials dbCredentials = new DBCredentials();
    dbCredentials.preparaDb();
    DBRoles dbRoles = new DBRoles();
    dbRoles.preparaDb();

    Authentication authentication = new UsernamePasswordAuthenticationToken(
        "gargoile", "notredame");
    boolean flag = false;
    try {
      _dao.authenticate(authentication);
    } catch (BadCredentialsException e) {
View Full Code Here

        boolean bAuthenticated = false;
        SecurityContext context = (SecurityContext)
                request.getSession().getAttribute(HttpSessionContextIntegrationFilter.ACEGI_SECURITY_CONTEXT_KEY);

        if (context != null) {
            Authentication auth = context.getAuthentication();

            if ((auth != null) && auth instanceof UsernamePasswordAuthenticationToken) {
                UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) auth;
                bAuthenticated = token.isAuthenticated();
            }
View Full Code Here

            if (authenticationIsRequired(username)) {
                UsernamePasswordAuthenticationToken authRequest =
                        new UsernamePasswordAuthenticationToken(username, password);
                authRequest.setDetails(authenticationDetailsSource.buildDetails((HttpServletRequest) request));

                Authentication authResult;

                try {
                    authResult = authenticationManager.authenticate(authRequest);
                } catch (AuthenticationException failed) {
                    // Authentication failed
                    if (logger.isDebugEnabled()) {
                        logger.debug("Authentication request for user: " + username + " failed: " + failed.toString());
                    }

                    SecurityContextHolder.getContext().setAuthentication(null);

                    if (rememberMeServices != null) {
                        rememberMeServices.loginFail(httpRequest, httpResponse);
                    }

                    if (ignoreFailure) {
                        chain.doFilter(request, response);
                    } else {
                        authenticationEntryPoint.commence(request, response, failed);
                    }

                    return;
                }

                // Authentication success
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication success: " + authResult.toString());
                }

                SecurityContextHolder.getContext().setAuthentication(authResult);

                if (rememberMeServices != null) {
View Full Code Here

    }

    private boolean authenticationIsRequired(String username) {
        // Only reauthenticate if username doesn't match SecurityContextHolder and user isn't authenticated
        // (see SEC-53)
        Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();

        if(existingAuth == null || !existingAuth.isAuthenticated()) {
            return true;
        }

        // Limit username comparison to providers which use usernames (ie UsernamePasswordAuthenticationToken)
        // (see SEC-348)

        if (existingAuth instanceof UsernamePasswordAuthenticationToken && !existingAuth.getName().equals(username)) {
            return true;
        }
       
        // Handle unusual condition where an AnonymousAuthenticationToken is already present
        // This shouldn't happen very often, as BasicProcessingFitler is meant to be earlier in the filter
View Full Code Here

        if (logger.isDebugEnabled()) {
            logger.debug("Checking secure context token: " + SecurityContextHolder.getContext().getAuthentication());
        }

        if (SecurityContextHolder.getContext().getAuthentication() == null) {
            Authentication authResult = null;
            X509Certificate clientCertificate = extractClientCertificate(httpRequest);

            try {
                X509AuthenticationToken authRequest = new X509AuthenticationToken(clientCertificate);
View Full Code Here

TOP

Related Classes of org.acegisecurity.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.