View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.wss4j.policy.model;
20  
21  import org.apache.neethi.Policy;
22  import org.apache.wss4j.policy.SPConstants;
23  
24  import javax.xml.namespace.QName;
25  import java.util.List;
26  
27  public class SignedParts extends AbstractSecuredParts {
28  
29      private boolean signAllHeaders;
30  
31      public SignedParts(SPConstants.SPVersion version, boolean body, Attachments attachments,
32                         List<Header> headers, boolean signAllHeaders) {
33          super(version, body, attachments, headers);
34  
35          this.signAllHeaders = signAllHeaders;
36      }
37  
38      @Override
39      public QName getName() {
40          return getVersion().getSPConstants().getSignedParts();
41      }
42  
43      @Override
44      public boolean equals(Object object) {
45          if (object == this) {
46              return true;
47          }
48          if (!(object instanceof SignedParts)) {
49              return false;
50          }
51  
52          SignedParts that = (SignedParts)object;
53          if (signAllHeaders != that.signAllHeaders) {
54              return false;
55          }
56  
57          return super.equals(object);
58      }
59  
60      @Override
61      public int hashCode() {
62          int result = 17;
63          result = 31 * result + Boolean.hashCode(signAllHeaders);
64  
65          return 31 * result + super.hashCode();
66      }
67  
68      @Override
69      protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
70          return new SignedParts(getVersion(), isBody(),
71                  getAttachments() == null ? null : (Attachments) getAttachments().clone(nestedPolicy),
72                  getHeaders(), isSignAllHeaders());
73      }
74  
75      public boolean isSignAllHeaders() {
76          return signAllHeaders;
77      }
78  
79      protected void setSignAllHeaders(boolean signAllHeaders) {
80          this.signAllHeaders = signAllHeaders;
81      }
82  }