use of com.haulmont.restapi.auth.OAuthTokenIssuer.OAuth2AccessTokenResult in project cuba by cuba-platform.
the class LdapAuthController method postAccessToken.
@RequestMapping(value = "/v2/ldap/token", method = RequestMethod.POST)
public ResponseEntity<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters, HttpServletRequest request) throws HttpRequestMethodNotSupportedException {
if (!ldapConfig.getLdapEnabled()) {
log.debug("LDAP authentication is disabled. Property cuba.rest.ldap.enabled is false");
throw new InvalidGrantException("LDAP is not supported");
}
if (!(principal instanceof Authentication)) {
throw new InsufficientAuthenticationException("There is no client authentication. Try adding an appropriate authentication filter.");
}
String grantType = parameters.get(OAuth2Utils.GRANT_TYPE);
if (!"password".equals(grantType)) {
throw new InvalidGrantException("grant type not supported for ldap/token endpoint");
}
String username = parameters.get("username");
if (restApiConfig.getStandardAuthenticationUsers().contains(username)) {
log.info("User {} is not allowed to use external login in REST API", username);
throw new BadCredentialsException("Bad credentials");
}
String ipAddress = request.getRemoteAddr();
String password = parameters.get("password");
OAuth2AccessTokenResult tokenResult = authenticate(username, password, request.getLocale(), ipAddress, parameters);
return ResponseEntity.ok(tokenResult.getAccessToken());
}
use of com.haulmont.restapi.auth.OAuthTokenIssuer.OAuth2AccessTokenResult in project cuba by cuba-platform.
the class IdpAuthController method postAccessToken.
@PostMapping(value = "/v2/idp/token")
public ResponseEntity<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters, HttpServletRequest request) throws HttpRequestMethodNotSupportedException {
if (!idpConfig.getIdpEnabled()) {
log.debug("IDP authentication is disabled. Property cuba.rest.idp.enabled is false");
throw new InvalidGrantException("IDP is not supported");
}
if (!(principal instanceof Authentication)) {
throw new InsufficientAuthenticationException("There is no client authentication. Try adding an appropriate authentication filter.");
}
// we cannot perform brute-force check here, since we don't know username
String idpTicket = parameters.get("idp_ticket");
String ipAddress = request.getRemoteAddr();
OAuth2AccessTokenResult tokenResult = authenticate(idpTicket, request.getLocale(), ipAddress, parameters);
return ResponseEntity.ok(tokenResult.getAccessToken());
}
Aggregations