Search in sources :

Example 1 with AuthMethodNotSupportedException

use of org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException in project thingsboard by thingsboard.

the class RestPublicLoginProcessingFilter method attemptAuthentication.

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    if (!HttpMethod.POST.name().equals(request.getMethod())) {
        if (log.isDebugEnabled()) {
            log.debug("Authentication method not supported. Request method: " + request.getMethod());
        }
        throw new AuthMethodNotSupportedException("Authentication method not supported");
    }
    PublicLoginRequest loginRequest;
    try {
        loginRequest = objectMapper.readValue(request.getReader(), PublicLoginRequest.class);
    } catch (Exception e) {
        throw new AuthenticationServiceException("Invalid public login request payload");
    }
    if (StringUtils.isBlank(loginRequest.getPublicId())) {
        throw new AuthenticationServiceException("Public Id is not provided");
    }
    UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.PUBLIC_ID, loginRequest.getPublicId());
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, "");
    return this.getAuthenticationManager().authenticate(token);
}
Also used : AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ServletException(javax.servlet.ServletException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) IOException(java.io.IOException) AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) AuthenticationException(org.springframework.security.core.AuthenticationException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) UserPrincipal(org.thingsboard.server.service.security.model.UserPrincipal)

Example 2 with AuthMethodNotSupportedException

use of org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException in project thingsboard by thingsboard.

the class RefreshTokenProcessingFilter method attemptAuthentication.

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    if (!HttpMethod.POST.name().equals(request.getMethod())) {
        if (log.isDebugEnabled()) {
            log.debug("Authentication method not supported. Request method: " + request.getMethod());
        }
        throw new AuthMethodNotSupportedException("Authentication method not supported");
    }
    RefreshTokenRequest refreshTokenRequest;
    try {
        refreshTokenRequest = objectMapper.readValue(request.getReader(), RefreshTokenRequest.class);
    } catch (Exception e) {
        throw new AuthenticationServiceException("Invalid refresh token request payload");
    }
    if (StringUtils.isBlank(refreshTokenRequest.getRefreshToken())) {
        throw new AuthenticationServiceException("Refresh token is not provided");
    }
    RawAccessJwtToken token = new RawAccessJwtToken(refreshTokenRequest.getRefreshToken());
    return this.getAuthenticationManager().authenticate(new RefreshAuthenticationToken(token));
}
Also used : AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) RefreshAuthenticationToken(org.thingsboard.server.service.security.auth.RefreshAuthenticationToken) RawAccessJwtToken(org.thingsboard.server.service.security.model.token.RawAccessJwtToken) ServletException(javax.servlet.ServletException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) IOException(java.io.IOException) AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) AuthenticationException(org.springframework.security.core.AuthenticationException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 3 with AuthMethodNotSupportedException

use of org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException in project thingsboard by thingsboard.

the class RestLoginProcessingFilter method attemptAuthentication.

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    if (!HttpMethod.POST.name().equals(request.getMethod())) {
        if (log.isDebugEnabled()) {
            log.debug("Authentication method not supported. Request method: " + request.getMethod());
        }
        throw new AuthMethodNotSupportedException("Authentication method not supported");
    }
    LoginRequest loginRequest;
    try {
        loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class);
    } catch (Exception e) {
        throw new AuthenticationServiceException("Invalid login request payload");
    }
    if (StringUtils.isBlank(loginRequest.getUsername()) || StringUtils.isBlank(loginRequest.getPassword())) {
        throw new AuthenticationServiceException("Username or Password not provided");
    }
    UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, loginRequest.getUsername());
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, loginRequest.getPassword());
    return this.getAuthenticationManager().authenticate(token);
}
Also used : AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ServletException(javax.servlet.ServletException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) IOException(java.io.IOException) AuthMethodNotSupportedException(org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException) AuthenticationException(org.springframework.security.core.AuthenticationException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) UserPrincipal(org.thingsboard.server.service.security.model.UserPrincipal)

Aggregations

IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 AuthMethodNotSupportedException (org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 UserPrincipal (org.thingsboard.server.service.security.model.UserPrincipal)2 RefreshAuthenticationToken (org.thingsboard.server.service.security.auth.RefreshAuthenticationToken)1 RawAccessJwtToken (org.thingsboard.server.service.security.model.token.RawAccessJwtToken)1