
se.kth.iss.ug2.Ug2SessionInformation Maven / Gradle / Ivy
/*
* MIT License
*
* Copyright (c) 2017 Kungliga Tekniska högskolan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package se.kth.iss.ug2;
import java.util.Date;
import java.util.Vector;
public class Ug2SessionInformation {
private final String operator;
private final String facility;
private final Long sessionId;
private final Date lastActiveOperation;
private final Date creationTime;
private final Date lastAccessed;
private final String[] enabledRoles;
public Ug2SessionInformation(String sessionId, String operator, String facility, Date creationTime,
Date lastAccessed, Date lastActiveOperation, String[] roles) {
this(Long.parseLong(sessionId), operator, facility, creationTime, lastAccessed, lastActiveOperation, roles);
}
public Ug2SessionInformation(Long sessionId, String operator, String facility, Date creationTime,
Date lastAccessed, Date lastActiveOperation, String[] roles) {
this.sessionId = sessionId;
this.operator = operator;
this.facility = facility;
this.creationTime = creationTime;
this.lastAccessed = lastAccessed;
this.lastActiveOperation = lastActiveOperation;
this.enabledRoles = roles;
}
public static Ug2ObjectHandle[] fakeApl(String operator, String facility) {
Vector apl = new Vector<>();
if (operator != null)
apl.add(new Ug2ObjectHandle("user", operator));
if (facility != null)
apl.add(new Ug2ObjectHandle("system", facility));
Ug2ObjectHandle[] fakeApl = new Ug2ObjectHandle[apl.size()];
apl.toArray(fakeApl);
return fakeApl;
}
public Ug2ObjectHandle[] apl() {
return fakeApl(operator, facility);
}
public Ug2ObjectHandle[] cpl() {
return new Ug2ObjectHandle[0];
}
public String[] enabledRoles() {
return enabledRoles;
}
public String operator() {
return operator;
}
public String facility() {
return facility;
}
public String[] clientIps() {
return new String[0];
}
public String id() {
return sessionId.toString();
}
public String sessionId() {
return sessionId.toString();
}
public Long getSessionId() {
return sessionId;
}
public long created() {
return creationTime.getTime();
}
public long lastAccessed() {
return lastAccessed.getTime();
}
public long lastActiveOperation() {
return lastActiveOperation.getTime();
}
@Override
public String toString() {
return toString("\n");
}
/**
* Formats a String using the indicated String as the line break delimiter.
* Useful e.g. when printing directly on web pages. Default sequence is '\n'.
*
* @param lineBreakSequence line break string.
* @return string representation.
*/
public String toString(String lineBreakSequence) {
StringBuilder buf = new StringBuilder(256);
if (lineBreakSequence == null)
lineBreakSequence = "\n";
buf.append("SessionId: ").append(sessionId).append(lineBreakSequence);
buf.append("Created: ").append(creationTime.toString()).append(lineBreakSequence);
buf.append("Last accessed: ").append(lastAccessed.toString()).append(lineBreakSequence);
buf.append("Last active: ").append(lastActiveOperation.toString()).append(lineBreakSequence);
buf.append("Operator: ").append((operator == null ? "Not set" : operator)).append(lineBreakSequence);
buf.append("Facility: ").append((facility == null ? "Not set" : facility)).append(lineBreakSequence);
buf.append("Enabled roles: ");
for (String enabledRole : enabledRoles) buf.append(enabledRole).append(" ");
return buf.append(lineBreakSequence).toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy