单点注销 RC1

This commit is contained in:
Crystal.Sea
2020-10-26 22:31:42 +08:00
parent 68d72e2dd4
commit f635ed358c
14 changed files with 319 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.maxkey.authn.online;
import java.time.Duration;
import org.ehcache.UserManagedCache;
import org.ehcache.config.builders.ExpiryPolicyBuilder;
import org.ehcache.config.builders.UserManagedCacheBuilder;
public class InMemoryOnlineTicketServices implements OnlineTicketServices{
protected final static UserManagedCache<String, OnlineTicket> onlineTicketStore =
UserManagedCacheBuilder.newUserManagedCacheBuilder(String.class, OnlineTicket.class)
.withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(30)))
.build(true);
@Override
public void store(String ticketId, OnlineTicket ticket) {
onlineTicketStore.put(ticketId, ticket);
}
@Override
public OnlineTicket remove(String ticketId) {
OnlineTicket ticket=onlineTicketStore.get(ticketId);
onlineTicketStore.remove(ticketId);
return ticket;
}
@Override
public OnlineTicket get(String ticketId) {
OnlineTicket ticket=onlineTicketStore.get(ticketId);
return ticket;
}
}

View File

@@ -0,0 +1,36 @@
package org.maxkey.authn.online;
import java.io.Serializable;
import org.maxkey.domain.apps.Apps;
public class OnlineTicket implements Serializable{
/**
*
*/
private static final long serialVersionUID = 9008067569150338296L;
public String id;
private Apps authorizeApps;
public OnlineTicket(String id) {
super();
this.id = id;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("OnlineTicket [id=");
builder.append(id);
builder.append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.maxkey.authn.online;
public interface OnlineTicketServices {
public void store(String ticketId, OnlineTicket ticket);
public OnlineTicket remove(String ticket);
public OnlineTicket get(String ticketId);
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.maxkey.authn.online;
import org.maxkey.persistence.redis.RedisConnection;
import org.maxkey.persistence.redis.RedisConnectionFactory;
public class RedisOnlineTicketServices implements OnlineTicketServices {
protected int serviceTicketValiditySeconds = 60 * 30; //default 30 minutes.
RedisConnectionFactory connectionFactory;
public static String PREFIX="REDIS_ONLINE_TICKET_";
/**
* @param connectionFactory
*/
public RedisOnlineTicketServices(RedisConnectionFactory connectionFactory) {
super();
this.connectionFactory = connectionFactory;
}
/**
*
*/
public RedisOnlineTicketServices() {
}
public void setConnectionFactory(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Override
public void store(String ticketId, OnlineTicket ticket) {
RedisConnection conn=connectionFactory.getConnection();
conn.setexObject(PREFIX+ticketId, serviceTicketValiditySeconds, ticket);
conn.close();
}
@Override
public OnlineTicket remove(String ticketId) {
RedisConnection conn=connectionFactory.getConnection();
OnlineTicket ticket = conn.getObject(PREFIX+ticketId);
conn.delete(PREFIX+ticketId);
conn.close();
return ticket;
}
@Override
public OnlineTicket get(String ticketId) {
RedisConnection conn=connectionFactory.getConnection();
OnlineTicket ticket = conn.getObject(PREFIX+ticketId);
conn.close();
return ticket;
}
}

View File

@@ -109,7 +109,10 @@ public class Apps extends JpaBaseDomain implements Serializable {
private String principal;
@Column
private String credentials;
@Column
private String logoutUrl;
@Column
private int logoutType;
/*
* extendAttr
*/
@@ -516,6 +519,23 @@ public class Apps extends JpaBaseDomain implements Serializable {
public void setInducer(String inducer) {
this.inducer = inducer;
}
public String getLogoutUrl() {
return logoutUrl;
}
public void setLogoutUrl(String logoutUrl) {
this.logoutUrl = logoutUrl;
}
public int getLogoutType() {
return logoutType;
}
public void setLogoutType(int logoutType) {
this.logoutType = logoutType;
}
@Override
public String toString() {
@@ -552,6 +572,10 @@ public class Apps extends JpaBaseDomain implements Serializable {
builder.append(principal);
builder.append(", credentials=");
builder.append(credentials);
builder.append(", logoutUrl=");
builder.append(logoutUrl);
builder.append(", logoutType=");
builder.append(logoutType);
builder.append(", isExtendAttr=");
builder.append(isExtendAttr);
builder.append(", extendAttr=");