001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk.ciba;
019
020import net.jcip.annotations.Immutable;
021
022import com.nimbusds.oauth2.sdk.ParseException;
023import com.nimbusds.oauth2.sdk.id.Identifier;
024
025
026/**
027 * CIBA token delivery mode.
028 *
029 * <ul>
030 *      <li>OpenID Connect CIBA Flow - Core 1.0, section 5.
031 * </ul>
032 */
033@Immutable
034public final class BackChannelTokenDeliveryMode extends Identifier {
035        
036        
037        private static final long serialVersionUID = -7661605920720830935L;
038        
039        
040        /**
041         * Push delivery mode. The OP / AS the tokens to a client callback URI.
042         */
043        public static final BackChannelTokenDeliveryMode PUSH = new BackChannelTokenDeliveryMode("push");
044        
045        
046        /**
047         * Poll delivery mode. The client polls the OP / AS token endpoint to
048         * obtain the tokens.
049         */
050        public static final BackChannelTokenDeliveryMode POLL = new BackChannelTokenDeliveryMode("poll");
051
052        
053        /**
054         * Ping delivery mode. The OP / AS sends a notification to a client
055         * endpoint that the tokens are available at the token endpoint.
056         */
057        public static final BackChannelTokenDeliveryMode PING = new BackChannelTokenDeliveryMode("ping");
058
059        
060        /**
061         * Creates a new CIBA token delivery mode with the specified value.
062         *
063         * @param value The CIBA token delivery mode value. Must not be
064         *              {@code null}.
065         */
066        public BackChannelTokenDeliveryMode(final String value) {
067
068                super(value);
069        }
070        
071
072        @Override
073        public boolean equals(final Object object) {
074
075                return object instanceof BackChannelTokenDeliveryMode && this.toString().equals(object.toString());
076        }
077        
078
079        /**
080         * Parses a CIBA token delivery mode from the specified string.
081         * 
082         * @param value The string value.
083         *
084         * @return The CIBA token delivery mode.
085         *
086         * @throws ParseException On a illegal CIBA token delivery mode.
087         */
088        public static BackChannelTokenDeliveryMode parse(final String value)
089                throws ParseException  {
090                
091                if (PING.getValue().equals(value)) {
092                        return PING;
093                } else if (POLL.getValue().equals(value)) {
094                        return POLL;
095                } else if (PUSH.getValue().equals(value)) {
096                        return PUSH;
097                } else {
098                        throw new ParseException("Invalid CIBA token delivery mode: " + value);
099                }
100        }
101}