001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.runtime.authentication.standard;
021
022import java.io.IOException;
023import java.util.Arrays;
024import java.util.List;
025
026import org.apache.isis.core.commons.authentication.AuthenticationSessionAbstract;
027import org.apache.isis.core.commons.encoding.DataInputExtended;
028
029public final class SimpleSession extends AuthenticationSessionAbstract {
030
031    private static final long serialVersionUID = 1L;
032
033    // ///////////////////////////////////////////////////////////////
034    // Constructor, encode
035    // ///////////////////////////////////////////////////////////////
036
037    /**
038     * as per {@link #SimpleSession(String, List)}.
039     */
040    public SimpleSession(final String name, final String[] roles) {
041        this(name, Arrays.asList(roles));
042    }
043
044    /**
045     * Defaults {@link #getValidationCode()} to empty string (<tt>""</tt>).
046     */
047    public SimpleSession(final String name, final List<String> roles) {
048        this(name, roles, "");
049    }
050
051    public SimpleSession(final String name, final String[] roles, final String code) {
052        this(name, Arrays.asList(roles), code);
053    }
054
055    public SimpleSession(final String name, final List<String> roles, final String code) {
056        super(name, roles, code);
057    }
058
059    public SimpleSession(final DataInputExtended input) throws IOException {
060        super(input);
061    }
062
063    // ///////////////////////////////////////////////////////////////
064    // equals, hashCode
065    // ///////////////////////////////////////////////////////////////
066
067    @Override
068    public boolean equals(final Object obj) {
069        if (obj == this) {
070            return true;
071        }
072        if (obj == null) {
073            return false;
074        }
075        if (obj.getClass() != getClass()) {
076            return false;
077        }
078        final SimpleSession other = (SimpleSession) obj;
079        return equals(other);
080    }
081
082    public boolean equals(final SimpleSession other) {
083        if (other == this) {
084            return true;
085        }
086        if (other == null) {
087            return false;
088        }
089        return getUserName().equals(other.getUserName());
090    }
091
092    @Override
093    public int hashCode() {
094        return getUserName().hashCode();
095    }
096
097}