use of io.hops.hopsworks.api.filter.JWTNotRequired in project hopsworks by logicalclocks.
the class AuthService method passwordRecovery.
@POST
@Path("/reset/password")
@Produces(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response passwordRecovery(@FormParam("key") String key, @FormParam("newPassword") String newPassword, @FormParam("confirmPassword") String confirmPassword, @Context HttpServletRequest req) throws UserException, MessagingException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
userController.changePassword(key, newPassword, confirmPassword);
json.setSuccessMessage(ResponseMessages.PASSWORD_CHANGED);
return Response.ok(json).build();
}
use of io.hops.hopsworks.api.filter.JWTNotRequired in project hopsworks by logicalclocks.
the class AuthService method register.
@POST
@Path("register")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response register(UserDTO newUser, @Context HttpServletRequest req) throws UserException {
if (settings.isRegistrationDisabled()) {
throw new UserException(RESTCodes.UserErrorCode.ACCOUNT_REGISTRATION_ERROR, Level.FINE, "Registration not " + "allowed.");
}
RESTApiJsonResponse json = new RESTApiJsonResponse();
String linkUrl = FormatUtils.getUserURL(req) + settings.getEmailVerificationEndpoint();
QrCode qrCode = userController.registerUser(newUser, linkUrl);
if (authController.isTwoFactorEnabled(newUser.isTwoFactor())) {
return Response.ok(qrCode).build();
} else {
json.setSuccessMessage("We registered your account request. Please validate you email and we will " + "review your account within 48 hours.");
}
return Response.ok(json).build();
}
use of io.hops.hopsworks.api.filter.JWTNotRequired in project hopsworks by logicalclocks.
the class AuthService method serviceLogin.
@POST
@Path("/service")
@Produces(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response serviceLogin(@FormParam("email") String email, @FormParam("password") String password, @Context HttpServletRequest request) throws UserException, GeneralSecurityException, SigningKeyNotFoundException, DuplicateSigningKeyException, HopsSecurityException {
if (Strings.isNullOrEmpty(email)) {
throw new IllegalArgumentException("Email cannot be null or empty");
}
if (Strings.isNullOrEmpty(password)) {
throw new IllegalArgumentException("Password cannot be null or empty");
}
Users user = userFacade.findByEmail(email);
if (user == null) {
throw new LoginException("Could not find registered user with email " + email);
}
if (!needLogin(request, user)) {
return Response.ok().build();
}
if (!userController.isUserInRole(user, "AGENT")) {
throw new HopsSecurityException(RESTCodes.SecurityErrorCode.REST_ACCESS_CONTROL, Level.FINE, "Users are not allowed to access this endpoint, use auth/login instead", "User " + user.getUsername() + " tried to login but they don't have AGENT role");
}
request.getSession();
Collection roles = user.getBbcGroupCollection();
if (roles == null || roles.isEmpty()) {
throw new UserException(RESTCodes.UserErrorCode.NO_ROLE_FOUND, Level.FINE);
}
statusValidator.checkStatus(user.getStatus());
String saltedPassword = authController.preCustomRealmLoginCheck(user, password, null);
try {
request.login(user.getEmail(), saltedPassword);
} catch (ServletException ex) {
authController.registerAuthenticationFailure(user);
throw new UserException(RESTCodes.UserErrorCode.AUTHENTICATION_FAILURE, Level.FINE, null, ex.getMessage(), ex);
}
// First generate the one-time tokens for renewal of master token
String renewalKeyName = jwtController.getServiceOneTimeJWTSigningKeyname(user.getUsername(), request.getRemoteHost());
LocalDateTime masterExpiration = DateUtils.getNow().plus(settings.getServiceJWTLifetimeMS(), ChronoUnit.MILLIS);
LocalDateTime notBefore = jwtController.computeNotBefore4ServiceRenewalTokens(masterExpiration);
LocalDateTime expiresAt = notBefore.plus(settings.getServiceJWTLifetimeMS(), ChronoUnit.MILLIS);
List<String> userRoles = userController.getUserRoles(user);
JsonWebToken renewalJWTSpec = new JsonWebToken();
renewalJWTSpec.setSubject(user.getUsername());
renewalJWTSpec.setIssuer(settings.getJWTIssuer());
renewalJWTSpec.setAudience(JWTHelper.SERVICE_RENEW_JWT_AUDIENCE);
renewalJWTSpec.setKeyId(renewalKeyName);
renewalJWTSpec.setNotBefore(DateUtils.localDateTime2Date(notBefore));
renewalJWTSpec.setExpiresAt(DateUtils.localDateTime2Date(expiresAt));
Map<String, Object> claims = new HashMap<>(4);
claims.put(Constants.RENEWABLE, false);
claims.put(Constants.EXPIRY_LEEWAY, 3600);
claims.put(Constants.ROLES, userRoles.toArray(new String[1]));
String[] oneTimeRenewalTokens = jwtController.generateOneTimeTokens4ServiceJWTRenewal(renewalJWTSpec, claims, settings.getJWTSigningKeyName());
// Then generate the master service token
try {
String signingKeyID = jwtController.getSignKeyID(oneTimeRenewalTokens[0]);
claims.clear();
// The rest of JWT claims will be added by JWTHelper
claims.put(Constants.RENEWABLE, false);
claims.put(Constants.SERVICE_JWT_RENEWAL_KEY_ID, signingKeyID);
String token = jWTHelper.createToken(user, settings.getJWTIssuer(), claims);
ServiceJWTDTO renewTokensResponse = new ServiceJWTDTO();
renewTokensResponse.setRenewTokens(oneTimeRenewalTokens);
return Response.ok().header(AUTHORIZATION, Constants.BEARER + token).entity(renewTokensResponse).build();
} catch (Exception ex) {
jwtController.deleteSigningKey(renewalKeyName);
throw ex;
}
}
use of io.hops.hopsworks.api.filter.JWTNotRequired in project hopsworks by logicalclocks.
the class VariablesService method getFileNameValidatorRegex.
@GET
@Path("filename-regex")
@Produces(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response getFileNameValidatorRegex(@QueryParam("type") String type) throws GenericException {
FileNameRegexDTO fileNameRegexDTO = new FileNameRegexDTO();
if (type == null || type.equals("project")) {
fileNameRegexDTO.setRegex(FolderNameValidator.getProjectNameRegexStr(settings.getReservedProjectNames()));
fileNameRegexDTO.setReservedWords(settings.getProjectNameReservedWords().toUpperCase());
} else if (type.equals("dataset")) {
fileNameRegexDTO.setRegex(FolderNameValidator.getDatasetNameRegexStr());
} else {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "Type QueryParam should be:" + "project|dataset|subdir");
}
return Response.ok(fileNameRegexDTO).build();
}
use of io.hops.hopsworks.api.filter.JWTNotRequired in project hopsworks by logicalclocks.
the class VariablesService method getAuthenticationStatus.
@GET
@Path("authenticationStatus")
@Produces(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response getAuthenticationStatus() {
boolean remoteAuthEnabled = remoteUserHelper.isRemoteUserAuthAvailable();
List<OpenIdProvider> providers = new ArrayList<>();
if (remoteAuthEnabled) {
List<OauthClient> oauthClients = oauthClientFacade.findAll();
for (OauthClient client : oauthClients) {
providers.add(new OpenIdProvider(client.getProviderName(), client.getProviderDisplayName(), client.getProviderLogoURI()));
}
}
AuthenticationStatus authenticationStatus = new AuthenticationStatus(OTPAuthStatus.fromTwoFactorMode(settings.getTwoFactorAuth()), settings.isLdapEnabled(), settings.isKrbEnabled(), settings.isOAuthEnabled(), providers, settings.isPasswordLoginDisabled(), settings.isRegistrationUIDisabled(), remoteAuthEnabled);
return Response.ok(authenticationStatus).build();
}
Aggregations