001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: /*
024: * TimestampValidationCallback.java
025: *
026: * Created on July 12, 2005, 12:54 AM
027: *
028: * This callback is intended for Timestamp validation.
029: * A validator that implements the TimestampValidator interface should
030: * set on the callback by callback handler.
031: */
032:
033: package com.sun.xml.wss.impl.callback;
034:
035: import javax.security.auth.callback.*;
036: import java.util.*;
037:
038: /**
039: *
040: * @author abhijit.das@Sun.COM
041: */
042: public class TimestampValidationCallback extends XWSSCallback implements
043: Callback {
044:
045: private Request request;
046: private TimestampValidator validator;
047:
048: /** Creates a new instance of TimestampValidationCallback */
049: public TimestampValidationCallback(Request request) {
050: this .request = request;
051: }
052:
053: public void getResult() throws TimestampValidationException {
054: validator.validate(request);
055: }
056:
057: /**
058: * The CallbackHandler handling this callbacl should set the validator.
059: *
060: */
061: public void setValidator(TimestampValidator validator) {
062: this .validator = validator;
063: }
064:
065: public static interface Request {
066:
067: }
068:
069: public static class UTCTimestampRequest implements Request {
070: private String created;
071: private String expired;
072: private long maxClockSkew = 0;
073: private long timestampFreshnessLimit = 0;
074:
075: private boolean isUsernameToken = false;
076:
077: /**
078: * Set it to true if the Created Timestamp present inside
079: * UsernameToken needs to be validated.
080: *
081: */
082: public void isUsernameToken(boolean isUsernameToken) {
083: this .isUsernameToken = true;
084: }
085:
086: /**
087: * Check if the Timestamp Created value is coming from UsernameToken
088: * @return true if Created is inside UsernameToken else false
089: */
090: public boolean isUsernameToken() {
091: return isUsernameToken;
092: }
093:
094: /**
095: * Constructor.
096: *
097: * @param created <code>java.lang.String</code> representaion of Creation time.
098: * @param expired <code>java.lang.String</code> representation of Expiration time.
099: * @param maxClockSkew representing the max time difference between sender's
100: * system time and receiver's system time in milliseconds.
101: * @param timestampFreshnessLimit representing the maximum time interval for nonce
102: * cache removal.
103: *
104: */
105: public UTCTimestampRequest(String created, String expired,
106: long maxClockSkew, long timestampFreshnessLimit) {
107: this .created = created;
108: this .expired = expired;
109: this .maxClockSkew = maxClockSkew;
110: this .timestampFreshnessLimit = timestampFreshnessLimit;
111: }
112:
113: public String getCreated() {
114: return created;
115: }
116:
117: public String getExpired() {
118: return expired;
119: }
120:
121: public long getMaxClockSkew() {
122: return maxClockSkew;
123: }
124:
125: public long getTimestampFreshnessLimit() {
126: return timestampFreshnessLimit;
127: }
128: }
129:
130: public static class TimestampValidationException extends Exception {
131:
132: public TimestampValidationException(String message) {
133: super (message);
134: }
135:
136: public TimestampValidationException(String message,
137: Throwable cause) {
138: super (message, cause);
139: }
140:
141: public TimestampValidationException(Throwable cause) {
142: super (cause);
143: }
144: }
145:
146: public static interface TimestampValidator {
147: /**
148: * Timestamp validation method.
149: *
150: * @throws TimestampValidationException if validation does not succeed.
151: */
152: public void validate(Request request)
153: throws TimestampValidationException;
154: }
155: }
|