use of com.serotonin.m2m2.web.mvc.spring.security.permissions.AnonymousAccess in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method saveView.
@DwrPermission(user = true)
public ProcessResult saveView(String name, String xid, int anonymousAccess, String readPermission, String setPermission, String editPermission) {
ProcessResult result = new ProcessResult();
User user = Common.getUser();
GraphicalView view = GraphicalViewsCommon.getUserEditView(user);
view.setName(name);
view.setXid(xid);
view.setAnonymousAccess(anonymousAccess);
view.setReadPermission(readPermission);
view.setSetPermission(setPermission);
view.setEditPermission(editPermission);
view.validate(result);
if (!result.getHasMessages()) {
view.setUserId(user.getId());
new GraphicalViewDao().saveView(view);
result.addData("view", view);
}
return result;
}
use of com.serotonin.m2m2.web.mvc.spring.security.permissions.AnonymousAccess in project ma-modules-public by infiniteautomation.
the class LoginRestController method loginPost.
/**
* <p>The actual authentication for the login occurs in the core, by the time this
* end point is actually reached the user is either already authenticated or not.
* The Spring Security authentication success handler forwards the request here.</p>
*
* <p>Authentication exceptions are re-thrown and mapped to rest bodies in {@link com.infiniteautomation.mango.rest.latest.exception.RestExceptionHandler MangoSpringExceptionHandler}</p>
*
* <p>Ensure that the URLs in MangoSecurityConfiguration are changed if you change the @RequestMapping value</p>
*/
@ApiOperation(value = "Login", notes = "Used to login using POST and JSON credentials")
@RequestMapping(method = RequestMethod.POST)
@AnonymousAccess
public ResponseEntity<UserModel> loginPost(@AuthenticationPrincipal User user, HttpServletRequest request, HttpServletResponse response) {
AuthenticationException ex = (AuthenticationException) request.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
if (ex != null) {
throw ex;
}
if (user == null) {
return new ResponseEntity<>(HttpStatus.OK);
} else {
LoginUriInfo info = pageResolver.getDefaultUriInfo(request, response, user);
response.setHeader(LOGIN_DEFAULT_URI_HEADER, info.getUri());
response.setHeader(LOGIN_LAST_UPGRADE_HEADER, Long.toString(installedModulesDao.lastUpgradeTime().toEpochMilli() / 1000));
if (info.isRequired())
response.setHeader(LOGIN_DEFAULT_URI_REQUIRED_HEADER, Boolean.TRUE.toString());
return new ResponseEntity<>(new UserModel(user), HttpStatus.OK);
}
}
use of com.serotonin.m2m2.web.mvc.spring.security.permissions.AnonymousAccess in project ma-modules-public by infiniteautomation.
the class TranslationsController method publicNamespacedTranslations.
@ApiOperation(value = "Get translations for public namespaces", notes = "Namespace must be base , ie public not public.messages. Returns sub-namespaces too. For > 1 use comma common,public")
@RequestMapping(method = RequestMethod.GET, value = "/public/{namespaces}")
@AnonymousAccess
public TranslationsModel publicNamespacedTranslations(@ApiParam(value = "Message Namespaces, simmilar to java package structure", allowMultiple = true) @PathVariable String[] namespaces, @ApiParam(value = "Language for translation (must have language pack installed)", allowMultiple = false) @RequestParam(value = "language", required = false) String language, @ApiParam(value = "Use server language for translation", allowMultiple = false) @RequestParam(value = "server", required = false, defaultValue = "false") boolean server, @RequestParam(value = "browser", required = false, defaultValue = "false") boolean browser, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
// Confirm the requested namespace is indeed public
for (String namespace : namespaces) {
if (!this.publicNamespaces.contains(namespace)) {
throw new BadRequestException();
}
}
TranslationsModel resultMap = new TranslationsModel();
Locale locale = this.getLocale(language, server, browser, request, user);
resultMap.setLocale(locale.toLanguageTag());
resultMap.setTranslations(getTranslationMap(namespaces, locale));
resultMap.setNamespaces(namespaces);
return resultMap;
}
use of com.serotonin.m2m2.web.mvc.spring.security.permissions.AnonymousAccess in project ma-modules-public by infiniteautomation.
the class GraphicalView method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
if (isNew()) {
String username = jsonObject.getString("user");
if (StringUtils.isBlank(username))
throw new TranslatableJsonException("emport.error.missingValue", "user");
User user = UserDao.instance.getUser(username);
if (user == null)
throw new TranslatableJsonException("emport.error.missingUser", username);
userId = user.getId();
}
JsonArray components = jsonObject.getJsonArray("viewComponents");
if (components != null) {
viewComponents.clear();
for (JsonValue jv : components) addViewComponent(reader.read(ViewComponent.class, jv));
}
String text = jsonObject.getString("anonymousAccess");
if (text != null) {
anonymousAccess = ShareUser.ACCESS_CODES.getId(text);
if (anonymousAccess == -1)
throw new TranslatableJsonException("emport.error.invalid", "anonymousAccess", text, ShareUser.ACCESS_CODES.getCodeList());
}
}
use of com.serotonin.m2m2.web.mvc.spring.security.permissions.AnonymousAccess in project ma-modules-public by infiniteautomation.
the class EmailVerificationController method publicRegisterUser.
/**
* CAUTION: This method is public!
* However the token's signature is cryptographically verified.
*/
@ApiOperation(value = "Registers a new user if the token's signature can be verified", notes = "The new user is created disabled and must be approved by an administrator.")
@RequestMapping(method = RequestMethod.POST, value = "/public/register")
@AnonymousAccess
public ResponseEntity<UserModel> publicRegisterUser(@RequestBody PublicRegistrationRequest body) {
body.ensureValid();
User newUser = body.getUser().toVO();
try {
User created = emailVerificationService.publicRegisterNewUser(body.getToken(), newUser);
return new ResponseEntity<>(new UserModel(created), HttpStatus.OK);
} catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | IllegalArgumentException | SignatureException | MissingClaimException | IncorrectClaimException e) {
throw new BadRequestException(new TranslatableMessage("rest.error.invalidEmailVerificationToken"), e);
} catch (ValidationException e) {
e.getValidationResult().prefixContextKey("user");
throw e;
}
}
Aggregations