Tabnine Logo
OpenIDAuthenticationToken.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.springframework.security.openid.OpenIDAuthenticationToken
constructor

Best Java code snippets using org.springframework.security.openid.OpenIDAuthenticationToken.<init> (Showing top 11 results out of 315)

origin: spring-projects/spring-security

  return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE,
      id == null ? "Unknown" : id.getIdentifier(),
      "Verification status message: [" + verification.getStatusMsg() + "]",
    verification.getAuthResponse(), attributesToFetch);
return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,
    verified.getIdentifier(), "some message", attributes);
origin: spring-projects/spring-security

/**
 * Handles the creation of the final <tt>Authentication</tt> object which will be
 * returned by the provider.
 * <p>
 * The default implementation just creates a new OpenIDAuthenticationToken from the
 * original, but with the UserDetails as the principal and including the authorities
 * loaded by the UserDetailsService.
 *
 * @param userDetails the loaded UserDetails object
 * @param auth the token passed to the authenticate method, containing
 * @return the token which will represent the authenticated user.
 */
protected Authentication createSuccessfulAuthentication(UserDetails userDetails,
    OpenIDAuthenticationToken auth) {
  return new OpenIDAuthenticationToken(userDetails,
      this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()),
      auth.getIdentityUrl(), auth.getAttributes());
}
origin: spring-projects/spring-security

@Test
public void testAuthenticateSuccess() {
  OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
  provider.setUserDetailsService(new MockUserDetailsService());
  Authentication preAuth = new OpenIDAuthenticationToken(
      OpenIDAuthenticationStatus.SUCCESS, USERNAME, "", null);
  assertThat(preAuth.isAuthenticated()).isFalse();
  Authentication postAuth = provider.authenticate(preAuth);
  assertThat(postAuth).isNotNull();
  assertThat(postAuth instanceof OpenIDAuthenticationToken).isTrue();
  assertThat(postAuth.isAuthenticated()).isTrue();
  assertThat(postAuth.getPrincipal()).isNotNull();
  assertThat(postAuth.getPrincipal() instanceof UserDetails).isTrue();
  assertThat(postAuth.getAuthorities()).isNotNull();
  assertThat(postAuth.getAuthorities().size() > 0).isTrue();
  assertThat(
      ((OpenIDAuthenticationToken) postAuth).getStatus() == OpenIDAuthenticationStatus.SUCCESS).isTrue();
  assertThat(((OpenIDAuthenticationToken) postAuth).getMessage() == null).isTrue();
}
origin: spring-projects/spring-security

@Test
public void testAuthenticateError() {
  OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
  provider.setUserDetailsService(new MockUserDetailsService());
  Authentication preAuth = new OpenIDAuthenticationToken(
      OpenIDAuthenticationStatus.ERROR, USERNAME, "", null);
  assertThat(preAuth.isAuthenticated()).isFalse();
  try {
    provider.authenticate(preAuth);
    fail("Should throw an AuthenticationException");
  }
  catch (AuthenticationServiceException expected) {
    assertThat(expected.getMessage()).isEqualTo("Error message from server: ");
  }
}
origin: spring-projects/spring-security

@Test
public void testAuthenticateSetupNeeded() {
  OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
  provider.setUserDetailsService(new MockUserDetailsService());
  Authentication preAuth = new OpenIDAuthenticationToken(
      OpenIDAuthenticationStatus.SETUP_NEEDED, USERNAME, "", null);
  assertThat(preAuth.isAuthenticated()).isFalse();
  try {
    provider.authenticate(preAuth);
    fail("Should throw an AuthenticationException");
  }
  catch (AuthenticationServiceException expected) {
    assertThat(
        "The server responded setup was needed, which shouldn't happen").isEqualTo(
            expected.getMessage());
  }
}
origin: spring-projects/spring-security

@Test
public void testAuthenticateCancel() {
  OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
  provider.setUserDetailsService(new MockUserDetailsService());
  provider.setAuthoritiesMapper(new NullAuthoritiesMapper());
  Authentication preAuth = new OpenIDAuthenticationToken(
      OpenIDAuthenticationStatus.CANCELLED, USERNAME, "", null);
  assertThat(preAuth.isAuthenticated()).isFalse();
  try {
    provider.authenticate(preAuth);
    fail("Should throw an AuthenticationException");
  }
  catch (AuthenticationCancelledException expected) {
    assertThat(expected.getMessage()).isEqualTo("Log in cancelled");
  }
}
origin: spring-projects/spring-security

@Test
public void testAuthenticateFailure() {
  OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
  provider.setAuthenticationUserDetailsService(
      new UserDetailsByNameServiceWrapper<>(
          new MockUserDetailsService()));
  Authentication preAuth = new OpenIDAuthenticationToken(
      OpenIDAuthenticationStatus.FAILURE, USERNAME, "", null);
  assertThat(preAuth.isAuthenticated()).isFalse();
  try {
    provider.authenticate(preAuth);
    fail("Should throw an AuthenticationException");
  }
  catch (BadCredentialsException expected) {
    assertThat("Log in failed - identity could not be verified").isEqualTo(
        expected.getMessage());
  }
}
origin: org.motechproject/motech-platform-web-security

@Override
public void validateTokenAndLoginUser(String token, HttpServletRequest request, HttpServletResponse response) throws IOException {
  PasswordRecovery recovery = allPasswordRecoveries.findForToken(token);
  if (validateRecovery(recovery)) {
    MotechUser user = allMotechUsers.findUserByEmail(recovery.getEmail());
    OpenIDAuthenticationToken openIDToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, user.getOpenId(), "one time login ", new ArrayList<OpenIDAttribute>());
    Authentication authentication = authenticationManager.authenticate(openIDToken);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    request.getSession(true).setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
    allPasswordRecoveries.remove(recovery);
    redirectStrategy.sendRedirect(request, response, "/server/home");
  } else {
    redirectStrategy.sendRedirect(request, response, "/server/login");
  }
}
origin: org.springframework.security/spring-security-openid

  return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE,
      id == null ? "Unknown" : id.getIdentifier(),
      "Verification status message: [" + verification.getStatusMsg() + "]",
    verification.getAuthResponse(), attributesToFetch);
return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS,
    verified.getIdentifier(), "some message", attributes);
origin: org.springframework.security/spring-security-openid

/**
 * Handles the creation of the final <tt>Authentication</tt> object which will be
 * returned by the provider.
 * <p>
 * The default implementation just creates a new OpenIDAuthenticationToken from the
 * original, but with the UserDetails as the principal and including the authorities
 * loaded by the UserDetailsService.
 *
 * @param userDetails the loaded UserDetails object
 * @param auth the token passed to the authenticate method, containing
 * @return the token which will represent the authenticated user.
 */
protected Authentication createSuccessfulAuthentication(UserDetails userDetails,
    OpenIDAuthenticationToken auth) {
  return new OpenIDAuthenticationToken(userDetails,
      this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()),
      auth.getIdentityUrl(), auth.getAttributes());
}
origin: org.motechproject/motech-platform-web-security

private AbstractAuthenticationToken getToken(Authentication authentication, MotechUser user) {
  AbstractAuthenticationToken token = null;
  if (authentication instanceof UsernamePasswordAuthenticationToken) {
    UsernamePasswordAuthenticationToken oldToken = (UsernamePasswordAuthenticationToken) authentication;
    token = new UsernamePasswordAuthenticationToken(oldToken.getPrincipal(),
        oldToken.getCredentials(), authoritiesService.authoritiesFor(user));
  } else if (authentication instanceof OpenIDAuthenticationToken) {
    OpenIDAuthenticationToken oldToken = (OpenIDAuthenticationToken) authentication;
    token = new OpenIDAuthenticationToken(oldToken.getPrincipal(), authoritiesService.authoritiesFor(user),
        user.getOpenId(), oldToken.getAttributes());
  }
  return token;
}
org.springframework.security.openidOpenIDAuthenticationToken<init>

Javadoc

Created by the OpenIDAuthenticationProvider on successful authentication.

Popular methods of OpenIDAuthenticationToken

  • getAttributes
  • getIdentityUrl
  • getStatus
  • getMessage
  • setAuthenticated
  • setDetails
  • getAuthorities
  • getName
  • getPrincipal
    Returns the principal value.

Popular in Java

  • Reading from database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • requestLocationUpdates (LocationManager)
  • Path (java.nio.file)
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • BoxLayout (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now