Package org.beangle.security.auth

Examples of org.beangle.security.auth.UsernamePasswordAuthentication


    String username = get("username");
    String password = get("password");
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { return "failure"; }
    username = username.trim();
    HttpServletRequest request = getRequest();
    UsernamePasswordAuthentication auth = new UsernamePasswordAuthentication(username, password);
    auth.setDetails(authenticationDetailsSource.buildDetails(request));
    Authentication authRequest = auth;
    try {
      authRequest = authenticationManager.authenticate(authRequest);
      sessionRegistry.register(authRequest, request.getSession().getId());
      SecurityContextHolder.getContext().setAuthentication(authRequest);
View Full Code Here


  private CasAuthentication authenticateNow(CasAuthentication auth) throws AuthenticationException {
    try {
      final Assertion assertion = ticketValidator.validate(auth.getCredentials().toString(),
          auth.getLoginUrl());
      String name = assertion.getPrincipal().getName();
      final UserDetail userDetail = userDetailService.loadDetail(new UsernamePasswordAuthentication(
          name, null));
      if (null == userDetail) {
        logger.error("cannot load {}'s detail from system", name);
        throw new UsernameNotFoundException(StrUtils.concat("user ", name, " not found in system"));
      }
View Full Code Here

      password = "";
    }

    username = username.trim();

    UsernamePasswordAuthentication authRequest = new UsernamePasswordAuthentication(username, password);

    // Place the last username attempted into HttpSession for views
    HttpSession session = request.getSession(false);

    if (session != null || getAllowSessionCreation()) {
View Full Code Here

    return createSuccessAuthentication(principalToReturn, authentication, user);
  }

  protected Authentication createSuccessAuthentication(Object principal, Authentication authentication,
      UserDetail user) {
    UsernamePasswordAuthentication result = new UsernamePasswordAuthentication(principal,
        authentication.getCredentials(), user.getAuthorities());
    result.setDetails(authentication.getDetails());
    return result;
  }
View Full Code Here

    return createSuccessAuthentication(principalToReturn, authentication, user);
  }

  protected Authentication createSuccessAuthentication(Object principal,
      Authentication authentication, UserDetail user) {
    UsernamePasswordAuthentication result = new UsernamePasswordAuthentication(principal,
        authentication.getCredentials(), user.getAuthorities());
    result.setDetails(authentication.getDetails());
    return result;
  }
View Full Code Here

  protected String doLogin() {
    String username = get("username");
    String password = get("password");
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { return "failure"; }
    username = username.trim();
    UsernamePasswordAuthentication auth= new UsernamePasswordAuthentication(username,
        password);
    auth.setDetails(authenticationDetailsSource.buildDetails(request));
    Authentication authRequest =auth;
    try {
      authRequest= authenticationManager.authenticate(authRequest);
      sessionStrategy.onAuthentication(authRequest, request, null);
      SecurityContextHolder.getContext().setAuthentication(authRequest);
View Full Code Here

  private CasAuthentication authenticateNow(CasAuthentication auth) throws AuthenticationException {
    try {
      final Assertion assertion = ticketValidator.validate(auth.getCredentials().toString(),
          auth.getLoginUrl());
      String name = assertion.getPrincipal();
      final UserDetail userDetail = userDetailService.loadDetail(new UsernamePasswordAuthentication(
          name, null));
      if (null == userDetail) {
        logger.error("cannot load {}'s detail from system", name);
        throw new UsernameNotFoundException(StrUtils.concat("user ", name, " not found in system"));
      }
View Full Code Here

    String username = get("username");
    String password = get("password");
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { return "failure"; }
    username = username.trim();
    HttpServletRequest request = getRequest();
    UsernamePasswordAuthentication auth = new UsernamePasswordAuthentication(username, password);
    auth.setDetails(authenticationDetailsSource.buildDetails(request));
    Authentication authRequest = auth;
    try {
      authRequest = authenticationManager.authenticate(authRequest);
      sessionRegistry.register(authRequest, request.getSession().getId());
      SecurityContextHolder.getContext().setAuthentication(authRequest);
View Full Code Here

      password = "";
    }

    username = username.trim();

    UsernamePasswordAuthentication authRequest = new UsernamePasswordAuthentication(username,
        password);

    // Place the last username attempted into HttpSession for views
    HttpSession session = request.getSession(false);
View Full Code Here

import org.testng.annotations.Test;

@Test
public class UsernamePasswordAuthenticationTest {
  public void testAuthenticated() {
    UsernamePasswordAuthentication token = new UsernamePasswordAuthentication("Test",
        "Password", null);

    // check default given we passed some GrantedAuthorty[]s (well, we
    // passed null)
    assertTrue(token.isAuthenticated());

    // check explicit set to untrusted (we can safely go from trusted to
    // untrusted, but not the reverse)
    token.setAuthenticated(false);
    assertTrue(!token.isAuthenticated());

    // Now let's create a UsernamePasswordAuthentication without any
    // GrantedAuthorty[]s (different constructor)
    token = new UsernamePasswordAuthentication("Test", "Password");

    assertTrue(!token.isAuthenticated());

    // check we're allowed to still set it to untrusted
    token.setAuthenticated(false);
    assertTrue(!token.isAuthenticated());

    // check denied changing it to trusted
    try {
      token.setAuthenticated(true);
      fail("Should have prohibited setAuthenticated(true)");
    } catch (IllegalArgumentException expected) {
      assertTrue(true);
    }
  }
View Full Code Here

TOP

Related Classes of org.beangle.security.auth.UsernamePasswordAuthentication

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.