javax.security.auth.login.AccountException Java Examples

The following examples show how to use javax.security.auth.login.AccountException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemLoginController.java    From cms with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "${web.adminPath}/login", method = RequestMethod.POST)
    public String showLoginForm(HttpServletRequest request, Model model) {
        String error = null;
        String exceptionClassName = (String)request.getAttribute(FormAuthenticationCaptchaFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);

        if(AccountException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名";
        }  else if(UnknownAccountException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名不存在";
        } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名/密码错误";
        }  else if(CaptchaException.class.getName().equals(exceptionClassName)) {
            error="对不起,您输入验证码错误";
        } else if(LockedAccountException.class.getName().equals(exceptionClassName)) {
            error="对不起,您账号被冻结,请联系管理员";
        } else if(ExcessiveAttemptsException.class.getName().equals(exceptionClassName)){
            error="重复密码错误超过5次,请等待30分钟...";
        }else if(exceptionClassName != null) {
            error = "登录系统错误";
        }

        model.addAttribute("error",  error);

        return getRemoteView("login_signin");
//        return "redirect:/"+getTemplate()+"/login";
    }
 
Example #2
Source File: LoginController.java    From cms with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "login", method = RequestMethod.POST)
    public String showLoginForm(HttpServletRequest request, Model model) {
        String error = null;
        String exceptionClassName = (String)request.getAttribute(FormAuthenticationCaptchaFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);

        if(AccountException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名";
        }  else if(UnknownAccountException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名不存在";
        } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)){
            error = "对不起,您输入用户名/密码错误";
        }  else if(CaptchaException.class.getName().equals(exceptionClassName)) {
            error="对不起,您输入验证码错误";
        } else if(LockedAccountException.class.getName().equals(exceptionClassName)) {
            error="对不起,您账号被冻结,请联系管理员";
        } else if(ExcessiveAttemptsException.class.getName().equals(exceptionClassName)){
            error="重复密码错误超过5次,请等待30分钟...";
        }else if(exceptionClassName != null) {
            error = "登录系统错误";
        }

        model.addAttribute("error",  error);

        return getRemoteView("login");
//        return "redirect:/"+getTemplate()+"/login";
    }
 
Example #3
Source File: DemoOauth2Application.java    From Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token with MIT License 6 votes vote down vote up
@Bean
CommandLineRunner init(
		AccountService accountService
) {
	return (evt) -> Arrays.asList(
			"user,admin,john,robert,ana".split(",")).forEach(
					username -> {
						Account acct = new Account();
						acct.setUsername(username);
						if ( username.equals("user")) acct.setPassword("password");
						else acct.setPassword(passwordEncoder().encode("password"));
						acct.setFirstName(username);
						acct.setLastName("LastName");
						acct.grantAuthority("ROLE_USER");
						if ( username.equals("admin") )
							acct.grantAuthority("ROLE_ADMIN");
						try {
							accountService.register(acct);
						} catch (AccountException e) {
							e.printStackTrace();
						}
					}
	);
}
 
Example #4
Source File: ApiController.java    From Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token with MIT License 5 votes vote down vote up
@PostMapping(path = "/api/register", produces = "application/json")
public ResponseEntity<?> register(@RequestBody Account account) {
    try {
        account.grantAuthority("ROLE_USER");
        return new ResponseEntity<Object>(
                accountService.register( account ), HttpStatus.OK);
    } catch (AccountException e) {
        e.printStackTrace();
        return new ResponseEntity<RestError>(new RestError(e.getMessage()),HttpStatus.BAD_REQUEST );
    }
}
 
Example #5
Source File: AccountService.java    From Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token with MIT License 5 votes vote down vote up
public Account register(Account account) throws AccountException {
    if ( accountRepo.countByUsername( account.getUsername() ) == 0 ) {
        account.setPassword(passwordEncoder.encode(account.getPassword()));
        return accountRepo.save( account );
    } else {
        throw new AccountException(String.format("Username[%s] already taken.", account.getUsername()));
    }
}
 
Example #6
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #7
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();

    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}
 
Example #8
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #9
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #10
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if(!capcha.equalsIgnoreCase(right)){
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}
 
Example #11
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #12
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #13
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example #14
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #15
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #16
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #17
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #18
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #19
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #20
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #21
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #22
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #23
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    UsernamePasswordCredential usernamePasswordCredentia = (UsernamePasswordCredential) credential;

    String username = usernamePasswordCredentia.getUsername();
    String password = usernamePasswordCredentia.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredentia,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}
 
Example #24
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example #25
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    UsernamePasswordCredential usernamePasswordCredentia = (UsernamePasswordCredential) credential;

    String username = usernamePasswordCredentia.getUsername();
    String password = usernamePasswordCredentia.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredentia,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}