Skip to content
Snippets Groups Projects
Commit b4555d2a authored by pgiertych's avatar pgiertych
Browse files

add name to access token

parent 8e0478f7
No related branches found
No related tags found
3 merge requests!65Resolve "Prevent users from adding an existing SSH key",!601.6.5 fix processing bulk,!2added token management
......@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -33,9 +34,9 @@ public class CustomAccessTokenController {
}
@PostMapping()
public AccessToken createNewToken(Principal principal) {
public AccessToken createNewToken(Principal principal, @RequestBody String name) {
User user = getUser(principal);
return accessTokenService.createToken(user.getId());
return accessTokenService.createToken(user.getId(), name);
}
@PutMapping("/{id}")
......
......@@ -23,6 +23,8 @@ public class AccessToken {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private Long userId;
private String tokenValue;
......
......@@ -7,7 +7,7 @@ import java.util.List;
public interface CustomAccessTokenService {
void invalidate(Long id);
AccessToken createToken(Long userId);
AccessToken createToken(Long userId, String name);
List<AccessToken> getAll(Long userId);
}
......@@ -24,8 +24,8 @@ public class CustomAccessTokenServiceImpl implements CustomAccessTokenService {
}
@Override
public AccessToken createToken(Long userId) {
AccessToken token = createNewToken(userId);
public AccessToken createToken(Long userId, String name) {
AccessToken token = createNewToken(userId, name);
return accessTokenRepository.save(token);
}
......@@ -34,8 +34,9 @@ public class CustomAccessTokenServiceImpl implements CustomAccessTokenService {
return accessTokenRepository.findAllByUserId(userId);
}
private AccessToken createNewToken(Long userId) {
private AccessToken createNewToken(Long userId, String name) {
AccessToken token = new AccessToken();
token.setName(name);
token.setUserId(userId);
token.setTokenValue(generateToken());
token.setValid(true);
......
......@@ -1155,13 +1155,25 @@
"HEADER": "Tokens",
"TABLE": {
"ID": "ID",
"NAME": "Name",
"VALUE": "Value",
"VALID": "Valid",
"ACTIONS": "Actions"
},
"MODAL": {
"HEADER": "Add new access token",
"NAME": "Name",
"BUTTON_ADD": "Submit",
"BUTTON_CANCEL": "Cancel",
"ERROR": {
"NAME_REQUIRED": "Name is required",
"NAME_MINLENGTH": "Name must have at least 1 character",
"NAME_MAXLENGTH": "Name cannot be longer than 16 characters"
}
},
"BUTTON_INVALIDATE": "Invalidate",
"NO_TOKENS": "No tokens",
"NEW_TOKEN": "New token"
"NEW_TOKEN": "Add new token"
},
"JSON_EDIT": {
"INVALID_JSON": "Invalid JSON format. Changes made to the content of the wizard will not be persisted."
......
......@@ -1157,13 +1157,25 @@
"HEADER": "Tokens",
"TABLE": {
"ID": "ID",
"NAME": "Name",
"VALUE": "Value",
"VALID": "Valid",
"ACTIONS": "Actions"
},
"MODAL": {
"HEADER": "Add new access token",
"NAME": "Name",
"BUTTON_ADD": "Submit",
"BUTTON_CANCEL": "Cancel",
"ERROR": {
"NAME_REQUIRED": "Name is required",
"NAME_MINLENGTH": "Name must have at least 1 character",
"NAME_MAXLENGTH": "Name cannot be longer than 16 characters"
}
},
"BUTTON_INVALIDATE": "Invalidate",
"NO_TOKENS": "No tokens",
"NEW_TOKEN": "New token"
"NEW_TOKEN": "Add new token"
},
"JSON_EDIT": {
"INVALID_JSON": "Invalid JSON format. Changes made to the content of the wizard will not be persisted."
......
......@@ -1151,18 +1151,30 @@
}
}
},
"TOKENS": {
"HEADER": "Tokens",
"TABLE": {
"ID": "ID",
"VALUE": "Value",
"VALID": "Valid",
"ACTIONS": "Actions"
},
"BUTTON_INVALIDATE": "Invalidate",
"NO_TOKENS": "No tokens",
"NEW_TOKEN": "New token"
""TOKENS": {
"HEADER": "Tokens",
"TABLE": {
"ID": "ID",
"NAME": "Name",
"VALUE": "Value",
"VALID": "Valid",
"ACTIONS": "Actions"
},
"MODAL": {
"HEADER": "Add new access token",
"NAME": "Name",
"BUTTON_ADD": "Submit",
"BUTTON_CANCEL": "Cancel",
"ERROR": {
"NAME_REQUIRED": "Name is required",
"NAME_MINLENGTH": "Name must have at least 1 character",
"NAME_MAXLENGTH": "Name cannot be longer than 16 characters"
}
},
"BUTTON_INVALIDATE": "Invalidate",
"NO_TOKENS": "No tokens",
"NEW_TOKEN": "Add new token"
},
"JSON_EDIT": {
"INVALID_JSON": "Invalid JSON format. Changes made to the content of the wizard will not be persisted."
},
......
......@@ -1156,13 +1156,25 @@
"HEADER": "Tokens",
"TABLE": {
"ID": "ID",
"NAME": "Name",
"VALUE": "Value",
"VALID": "Valid",
"ACTIONS": "Actions"
},
"MODAL": {
"HEADER": "Add new access token",
"NAME": "Name",
"BUTTON_ADD": "Submit",
"BUTTON_CANCEL": "Cancel",
"ERROR": {
"NAME_REQUIRED": "Name is required",
"NAME_MINLENGTH": "Name must have at least 1 character",
"NAME_MAXLENGTH": "Name cannot be longer than 16 characters"
}
},
"BUTTON_INVALIDATE": "Invalidate",
"NO_TOKENS": "No tokens",
"NEW_TOKEN": "New token"
"NEW_TOKEN": "Add new token"
},
"JSON_EDIT": {
"INVALID_JSON": "Niewłaściwy format JSON. Zmiany wprowadzone do zawartości formularza nie zostaną zapisane."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment