1package org.apache.archiva.redback.rest.services.interceptors;
2/*3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 */2021import org.apache.archiva.redback.policy.PasswordRuleViolationException;
22import org.apache.archiva.redback.policy.PasswordRuleViolations;
23import org.apache.archiva.redback.rest.api.model.ErrorMessage;
24import org.apache.archiva.redback.rest.api.model.RedbackRestError;
25import org.springframework.stereotype.Service;
2627import javax.ws.rs.core.Response;
28import javax.ws.rs.ext.ExceptionMapper;
29import javax.ws.rs.ext.Provider;
30import java.util.ArrayList;
31import java.util.List;
3233/**34 * @author Olivier Lamy35 * @since 1.436 */37 @Provider
38 @Service( "passwordRuleViolationExceptionMapper" )
39publicclassPasswordRuleViolationExceptionMapper40implements ExceptionMapper<PasswordRuleViolationException>
41 {
42public Response toResponse( PasswordRuleViolationException e )
43 {
44RedbackRestError restError = newRedbackRestError();
4546 List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>( e.getViolations().getViolations().size() );
47for ( PasswordRuleViolations.MessageReference messageReference : e.getViolations().getViolations() )
48 {
49 errorMessages.add( new ErrorMessage( messageReference.getKey(), messageReference.getArgs() ) );
50 }
51 restError.setErrorMessages( errorMessages );
52 Response.ResponseBuilder responseBuilder = Response.status( 500 ).entity( restError );
53return responseBuilder.build();
54 }
55 }