Search in sources :

Example 6 with ErrorVO

use of org.olat.restapi.support.vo.ErrorVO in project openolat by klemens.

the class CatalogWebService method getLockedResponse.

private Response getLockedResponse(LockResult lock, HttpServletRequest request) {
    Locale locale = null;
    UserRequest ureq = getUserRequest(request);
    if (ureq != null) {
        locale = LocaleNegotiator.getPreferedLocale(ureq);
    }
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }
    Translator translator = Util.createPackageTranslator(CatalogNodeManagerController.class, locale);
    String ownerName = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(lock.getOwner());
    String translation = translator.translate("catalog.locked.by", new String[] { ownerName });
    ErrorVO vo = new ErrorVO("org.olat.catalog.ui", "catalog.locked.by", translation);
    ErrorVO[] voes = new ErrorVO[] { vo };
    return Response.ok(voes).status(Status.UNAUTHORIZED).build();
}
Also used : Locale(java.util.Locale) ErrorVO(org.olat.restapi.support.vo.ErrorVO) Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest)

Example 7 with ErrorVO

use of org.olat.restapi.support.vo.ErrorVO in project OpenOLAT by OpenOLAT.

the class CatalogWebService method getLockedResponse.

private Response getLockedResponse(LockResult lock, HttpServletRequest request) {
    Locale locale = null;
    UserRequest ureq = getUserRequest(request);
    if (ureq != null) {
        locale = LocaleNegotiator.getPreferedLocale(ureq);
    }
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }
    Translator translator = Util.createPackageTranslator(CatalogNodeManagerController.class, locale);
    String ownerName = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(lock.getOwner());
    String translation = translator.translate("catalog.locked.by", new String[] { ownerName });
    ErrorVO vo = new ErrorVO("org.olat.catalog.ui", "catalog.locked.by", translation);
    ErrorVO[] voes = new ErrorVO[] { vo };
    return Response.ok(voes).status(Status.UNAUTHORIZED).build();
}
Also used : Locale(java.util.Locale) ErrorVO(org.olat.restapi.support.vo.ErrorVO) Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest)

Example 8 with ErrorVO

use of org.olat.restapi.support.vo.ErrorVO in project OpenOLAT by OpenOLAT.

the class ObjectFactory method get.

public static ErrorVO get(ValidationError error) {
    ErrorVO vo = new ErrorVO();
    vo.setCode("unkown" + ":" + error.getErrorKey());
    vo.setTranslation("Hello");
    return vo;
}
Also used : ErrorVO(org.olat.restapi.support.vo.ErrorVO)

Example 9 with ErrorVO

use of org.olat.restapi.support.vo.ErrorVO in project OpenOLAT by OpenOLAT.

the class ObjectFactory method get.

public static ErrorVO get(String pack, String key, String translation) {
    ErrorVO vo = new ErrorVO();
    vo.setCode(pack + ":" + key);
    vo.setTranslation(translation);
    return vo;
}
Also used : ErrorVO(org.olat.restapi.support.vo.ErrorVO)

Example 10 with ErrorVO

use of org.olat.restapi.support.vo.ErrorVO in project OpenOLAT by OpenOLAT.

the class UserAuthenticationWebService method create.

/**
 * Creates and persists an authentication
 * @response.representation.qname {http://www.example.com}authenticationVO
 * @response.representation.mediaType application/xml, application/json
 * @response.representation.doc An authentication to save
 * @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_AUTHVO}
 * @response.representation.200.qname {http://www.example.com}authenticationVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The saved authentication
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_AUTHVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity not found
 * @response.representation.406.doc Cannot create the authentication for an unkown reason
 * @response.representation.409.doc Cannot create the authentication because the authentication username is already used by someone else within the same provider
 * @param username The username of the user
 * @param authenticationVO The authentication object to persist
 * @param request The HTTP request
 * @return the saved authentication
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response create(@PathParam("username") String username, AuthenticationVO authenticationVO, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isUserManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = BaseSecurityManager.getInstance();
    Identity identity = baseSecurity.loadIdentityByKey(authenticationVO.getIdentityKey(), false);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!identity.getName().equals(username)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    String provider = authenticationVO.getProvider();
    String authUsername = authenticationVO.getAuthUsername();
    String credentials = authenticationVO.getCredential();
    Authentication currentAuthentication = baseSecurity.findAuthenticationByAuthusername(authUsername, provider);
    if (currentAuthentication != null) {
        if (!currentAuthentication.getIdentity().equals(identity)) {
            ErrorVO error = new ErrorVO();
            error.setCode("unkown:409");
            error.setTranslation("Authentication name used by: " + currentAuthentication.getIdentity().getUser().getEmail());
            return Response.serverError().status(Status.CONFLICT).entity(error).build();
        }
    }
    Authentication authentication = baseSecurity.createAndPersistAuthentication(identity, provider, authUsername, credentials, null);
    if (authentication == null) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    log.audit("New authentication created for " + authUsername + " with provider " + provider);
    AuthenticationVO savedAuth = ObjectFactory.get(authentication, true);
    return Response.ok(savedAuth).build();
}
Also used : ErrorVO(org.olat.restapi.support.vo.ErrorVO) Authentication(org.olat.basesecurity.Authentication) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) AuthenticationVO(org.olat.restapi.support.vo.AuthenticationVO) BaseSecurity(org.olat.basesecurity.BaseSecurity) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

ErrorVO (org.olat.restapi.support.vo.ErrorVO)20 Identity (org.olat.core.id.Identity)10 Locale (java.util.Locale)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 Translator (org.olat.core.gui.translator.Translator)6 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)6 URI (java.net.URI)4 PUT (javax.ws.rs.PUT)4 HttpResponse (org.apache.http.HttpResponse)4 HttpPut (org.apache.http.client.methods.HttpPut)4 Test (org.junit.Test)4 Authentication (org.olat.basesecurity.Authentication)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)4 User (org.olat.core.id.User)4 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)4 AuthenticationVO (org.olat.restapi.support.vo.AuthenticationVO)4 UserManager (org.olat.user.UserManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2