List of usage examples for org.springframework.security.core Authentication toString
public String toString();
From source file:od.lti.LTIAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { log.info(authentication.toString()); // Nothing to do, just return it return authentication; }
From source file:net.kamhon.ieagle.security.AuthenticationUtil.java
@Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException, ServletException { if (log.isDebugEnabled()) { log.debug("Authentication success: " + authResult.toString()); }/*from w w w. ja va 2 s. c om*/ SecurityContextHolder.getContext().setAuthentication(authResult); if (log.isDebugEnabled()) { log.debug( "Updated SecurityContextHolder to contain the following Authentication: '" + authResult + "'"); } /* * if (invalidateSessionOnSuccessfulAuthentication) { * SessionUtils.startNewSessionIfRequired(request, * migrateInvalidatedSessionAttributes, sessionRegistry); } * * String targetUrl = determineTargetUrl(request); * * if (log.isDebugEnabled()) { * log.debug("Redirecting to target URL from HTTP Session (or default): " * + targetUrl); } */ // onSuccessfulAuthentication(request, response, authResult); getRememberMeServices().loginSuccess(request, response, authResult); // Fire event if (this.eventPublisher != null) { eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass())); } }
From source file:de.knightsoftnet.validators.server.security.AuthSuccessHandler.java
@Override public void onAuthenticationSuccess(final HttpServletRequest prequest, final HttpServletResponse presponse, final Authentication pauthentication) throws IOException, ServletException { this.csrfCookieHandler.setCookie(prequest, presponse); if (pauthentication.isAuthenticated()) { presponse.setStatus(HttpServletResponse.SC_OK); LOGGER.info("User is authenticated!"); LOGGER.debug(pauthentication.toString()); final PrintWriter writer = presponse.getWriter(); this.mapper.writeValue(writer, this.userDetailsConverter.convert((UserDetails) pauthentication.getPrincipal())); writer.flush();/*w w w . j a va 2 s .c o m*/ } else { presponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } }
From source file:com.javaforge.tapestry.acegi.service.impl.SecurityUtilsImpl.java
public void checkSecurity(Object object, Collection<ConfigAttribute> attr) { Assert.notNull(object, "Object was null"); if (attr != null) { if (getLog().isDebugEnabled()) { getLog().debug("Secure object: " + object.toString() + "; ConfigAttributes: " + attr.toString()); }/*from w w w. ja v a2 s . co m*/ // We check for just the property we're interested in (we do // not call Context.validate() like the ContextInterceptor) if (SecurityContextHolder.getContext().getAuthentication() == null) { throw new AuthenticationCredentialsNotFoundException( messages.getMessage("AbstractSecurityInterceptor.authenticationNotFound", "An Authentication object was not found in the SecurityContext")); } // Attempt authentication if not already authenticated, or user always wants reauthentication Authentication authenticated; SecurityContext ctx = SecurityContextHolder.getContext(); if (ctx.getAuthentication() == null || !ctx.getAuthentication().isAuthenticated() || alwaysReauthenticate) { authenticated = this.authenticationManager .authenticate(SecurityContextHolder.getContext().getAuthentication()); // We don't authenticated.setAuthentication(true), because each provider should do that if (getLog().isDebugEnabled()) { getLog().debug("Successfully Authenticated: " + authenticated.toString()); } SecurityContextHolder.getContext().setAuthentication(authenticated); } else { authenticated = SecurityContextHolder.getContext().getAuthentication(); if (getLog().isDebugEnabled()) { getLog().debug("Previously Authenticated: " + authenticated.toString()); } } // Attempt authorization this.accessDecisionManager.decide(authenticated, object, attr); if (getLog().isDebugEnabled()) { getLog().debug("Authorization successful"); } // Attempt to run as a different user Authentication runAs = this.runAsManager.buildRunAs(authenticated, object, attr); if (runAs == null) { if (getLog().isDebugEnabled()) { getLog().debug("RunAsManager did not change Authentication object"); } } else { if (getLog().isDebugEnabled()) { getLog().debug("Switching to RunAs Authentication: " + runAs.toString()); } SecurityContextHolder.getContext().setAuthentication(runAs); } } else { if (getLog().isDebugEnabled()) { getLog().debug("Public object - authentication not attempted"); } } }
From source file:org.apache.nifi.web.security.NiFiAuthenticationFilter.java
private void authenticate(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { String dnChain = null;/*from w w w . jav a 2 s .c om*/ try { final Authentication authenticationRequest = attemptAuthentication(request); if (authenticationRequest != null) { // log the request attempt - response details will be logged later log.info(String.format("Attempting request for (%s) %s %s (source ip: %s)", authenticationRequest.toString(), request.getMethod(), request.getRequestURL().toString(), request.getRemoteAddr())); // attempt to authorize the user final Authentication authenticated = authenticationManager.authenticate(authenticationRequest); successfulAuthorization(request, response, authenticated); } // continue chain.doFilter(request, response); } catch (final AuthenticationException ae) { // invalid authentication - always error out unsuccessfulAuthorization(request, response, ae); } }
From source file:org.orcid.core.security.DefaultPermissionChecker.java
private void performPermissionChecks(Authentication authentication, ScopePathType requiredScope, String orcid, OrcidMessage orcidMessage) {//from w w w . j ava2 s . c o m // We can trust that this will return a not-null Authentication object Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); if (authoritiesHasRole(authorities, "ROLE_SYSTEM")) { return; } else if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) { OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) authentication; checkScopes(oAuth2Authentication, requiredScope); performSecurityChecks(oAuth2Authentication, requiredScope, orcidMessage, orcid); } else { throw new AccessControlException( "Cannot access method with authentication type " + authentication != null ? authentication.toString() : ", as it's null!"); } }
From source file:org.springframework.security.access.intercept.MethodInvocationPrivilegeEvaluator.java
public boolean isAllowed(MethodInvocation mi, Authentication authentication) { Assert.notNull(mi, "MethodInvocation required"); Assert.notNull(mi.getMethod(), "MethodInvocation must provide a non-null getMethod()"); Collection<ConfigAttribute> attrs = securityInterceptor.obtainSecurityMetadataSource().getAttributes(mi); if (attrs == null) { if (securityInterceptor.isRejectPublicInvocations()) { return false; }//from w w w . j a v a 2 s. com return true; } if (authentication == null || authentication.getAuthorities().isEmpty()) { return false; } try { securityInterceptor.getAccessDecisionManager().decide(authentication, mi, attrs); } catch (AccessDeniedException unauthorized) { if (logger.isDebugEnabled()) { logger.debug(mi.toString() + " denied for " + authentication.toString(), unauthorized); } return false; } return true; }
From source file:org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor.java
/** * Called every time a HTTP invocation is made. * <p>//from w w w .j a v a2 s . c om * Simply allows the parent to setup the connection, and then adds an * <code>Authorization</code> HTTP header property that will be used for BASIC * authentication. * </p> * <p> * The <code>SecurityContextHolder</code> is used to obtain the relevant principal and * credentials. * </p> * * @param con the HTTP connection to prepare * @param contentLength the length of the content to send * * @throws IOException if thrown by HttpURLConnection methods */ protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException { super.prepareConnection(con, contentLength); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null) && !trustResolver.isAnonymous(auth)) { String base64 = auth.getName() + ":" + auth.getCredentials().toString(); con.setRequestProperty("Authorization", "Basic " + new String(Base64.getEncoder().encode(base64.getBytes()))); if (logger.isDebugEnabled()) { logger.debug( "HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived: " + auth.toString()); } } else { if (logger.isDebugEnabled()) { logger.debug("Unable to set BASIC authentication header as SecurityContext did not provide " + "valid Authentication: " + auth); } } doPrepareConnection(con, contentLength); }
From source file:org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator.java
/** * Determines whether the user represented by the supplied <tt>Authentication</tt> * object is allowed to invoke the supplied URI, with the given . * <p>/*from www . j a va 2 s . c om*/ * Note the default implementation of <tt>FilterInvocationSecurityMetadataSource</tt> * disregards the <code>contextPath</code> when evaluating which secure object * metadata applies to a given request URI, so generally the <code>contextPath</code> * is unimportant unless you are using a custom * <code>FilterInvocationSecurityMetadataSource</code>. * * @param uri the URI excluding the context path * @param contextPath the context path (may be null, in which case a default value * will be used). * @param method the HTTP method (or null, for any method) * @param authentication the <tt>Authentication</tt> instance whose authorities should * be used in evaluation whether access should be granted. * @return true if access is allowed, false if denied */ public boolean isAllowed(String contextPath, String uri, String method, Authentication authentication) { Assert.notNull(uri, "uri parameter is required"); FilterInvocation fi = new FilterInvocation(contextPath, uri, method); Collection<ConfigAttribute> attrs = securityInterceptor.obtainSecurityMetadataSource().getAttributes(fi); if (attrs == null) { if (securityInterceptor.isRejectPublicInvocations()) { return false; } return true; } if (authentication == null) { return false; } try { securityInterceptor.getAccessDecisionManager().decide(authentication, fi, attrs); } catch (AccessDeniedException unauthorized) { if (logger.isDebugEnabled()) { logger.debug(fi.toString() + " denied for " + authentication.toString(), unauthorized); } return false; } return true; }
From source file:ubic.gemma.security.authentication.ManualAuthenticationServiceImpl.java
/** * @param authResult//from ww w . j av a2 s .c o m * @throws IOException */ protected void successfulAuthentication(Authentication authResult) { if (log.isDebugEnabled()) { log.debug("Authentication success: " + authResult.toString()); } // Fire event assert context != null; if (this.context != null) { context.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass())); } else { log.fatal("No context in which to place the authentication object"); } }